@@ -2873,6 +2873,11 @@ Toggle::Toggle(double cx, double cy, double w, double h)
28732873void Toggle::setChecked (bool c) {
28742874 checked = c;
28752875 knobTarget = c ? 1.0 : 0.0 ;
2876+ if (this ->parent != nullptr ) {
2877+ if (Panel* p = dynamic_cast <Panel*>(this ->parent )) {
2878+ p->setDirty ();
2879+ }
2880+ }
28762881}
28772882
28782883void Toggle::toggle () {
@@ -2920,7 +2925,15 @@ bool Toggle::handleEvent(const mouse_msg& msg) {
29202925 int dx = msg.x - cx;
29212926 int dy = msg.y - cy;
29222927
2928+ bool hoverChanged = false ;
2929+ bool prevHovered = hovered;
29232930 hovered = (std::abs (dx) <= w / 2 && std::abs (dy) <= h / 2 );
2931+ hoverChanged = (prevHovered != hovered);
2932+ if (hoverChanged && this ->parent != nullptr ) {
2933+ if (Panel* p = dynamic_cast <Panel*>(this ->parent )) {
2934+ p->setDirty ();
2935+ }
2936+ }
29242937
29252938 if (disabled) return false ;
29262939
@@ -2977,6 +2990,24 @@ void Toggle::draw(PIMAGE dst, double x, double y) {
29772990 else
29782991 knobOffset = knobTarget;
29792992
2993+ bool isAnimating = std::abs (knobOffset - knobTarget) > 1e-3 ;
2994+ if (this ->parent != nullptr ) {
2995+ if (Panel* p = dynamic_cast <Panel*>(this ->parent )) {
2996+ if (isAnimating) {
2997+ if (!m_animatingDirty) {
2998+ p->setAlwaysDirty (true );
2999+ this ->setDrawing (true );
3000+ m_animatingDirty = true ;
3001+ }
3002+ p->setDirty ();
3003+ } else if (m_animatingDirty) {
3004+ p->setAlwaysDirty (false );
3005+ this ->setDrawing (false );
3006+ m_animatingDirty = false ;
3007+ }
3008+ }
3009+ }
3010+
29803011 if (BackendFlag) {
29813012 return ;
29823013 }
0 commit comments