diff --git a/include/app/SvgPanel.hpp b/include/app/SvgPanel.hpp index 06ccf712..d01c4a76 100644 --- a/include/app/SvgPanel.hpp +++ b/include/app/SvgPanel.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace rack { @@ -34,8 +34,16 @@ struct ThemedSvgPanel : SvgPanel { std::shared_ptr lightSvg; std::shared_ptr darkSvg; - void step() override; - void setBackground(std::shared_ptr lightSvg, std::shared_ptr darkSvg); + void setBackground(std::shared_ptr lightSvg, std::shared_ptr darkSvg) { + this->lightSvg = lightSvg; + this->darkSvg = darkSvg; + SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg); + } + + void step() override { + SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg); + SvgPanel::step(); + } }; diff --git a/include/app/SvgScrew.hpp b/include/app/SvgScrew.hpp index d3cb5d6f..adc33ad6 100644 --- a/include/app/SvgScrew.hpp +++ b/include/app/SvgScrew.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace rack { @@ -26,8 +27,16 @@ struct ThemedSvgScrew : SvgScrew { std::shared_ptr lightSvg; std::shared_ptr darkSvg; - void step() override; - void setSvg(std::shared_ptr lightSvg, std::shared_ptr darkSvg); + void setSvg(std::shared_ptr lightSvg, std::shared_ptr darkSvg) { + this->lightSvg = lightSvg; + this->darkSvg = darkSvg; + SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg); + } + + void step() override { + SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg); + SvgScrew::step(); + } }; diff --git a/src/app/SvgButton.cpp b/src/app/SvgButton.cpp index 07ad2429..ce262f0d 100644 --- a/src/app/SvgButton.cpp +++ b/src/app/SvgButton.cpp @@ -39,6 +39,7 @@ void SvgButton::addFrame(std::shared_ptr svg) { // Move shadow downward by 10% shadow->box.size = sw->box.size; shadow->box.pos = math::Vec(0, sw->box.size.y * 0.10); + fb->setDirty(); } } @@ -49,7 +50,7 @@ void SvgButton::onDragStart(const DragStartEvent& e) { if (frames.size() >= 2) { sw->setSvg(frames[1]); - fb->dirty = true; + fb->setDirty(); } } @@ -57,7 +58,7 @@ void SvgButton::onDragStart(const DragStartEvent& e) { void SvgButton::onDragEnd(const DragEndEvent& e) { if (frames.size() >= 1) { sw->setSvg(frames[0]); - fb->dirty = true; + fb->setDirty(); } } diff --git a/src/app/SvgKnob.cpp b/src/app/SvgKnob.cpp index 5445451e..c72caca5 100644 --- a/src/app/SvgKnob.cpp +++ b/src/app/SvgKnob.cpp @@ -21,14 +21,24 @@ SvgKnob::SvgKnob() { } void SvgKnob::setSvg(std::shared_ptr svg) { + if (svg == sw->svg) + return; + sw->setSvg(svg); tw->box.size = sw->box.size; fb->box.size = sw->box.size; box.size = sw->box.size; + shadow->box.size = sw->box.size; // Move shadow downward by 10% shadow->box.pos = math::Vec(0, sw->box.size.y * 0.10); // shadow->box = shadow->box.grow(math::Vec(2, 2)); + + fb->setDirty(); + + // Dispatch ChangeEvent + ChangeEvent eChange; + onChange(eChange); } void SvgKnob::onChange(const ChangeEvent& e) { @@ -56,7 +66,7 @@ void SvgKnob::onChange(const ChangeEvent& e) { tw->translate(center); tw->rotate(angle); tw->translate(center.neg()); - fb->dirty = true; + fb->setDirty(); } Knob::onChange(e); } diff --git a/src/app/SvgPanel.cpp b/src/app/SvgPanel.cpp index 045ae757..652602ee 100644 --- a/src/app/SvgPanel.cpp +++ b/src/app/SvgPanel.cpp @@ -1,5 +1,5 @@ #include -#include +#include namespace rack { @@ -40,31 +40,20 @@ void SvgPanel::step() { Widget::step(); } + void SvgPanel::setBackground(std::shared_ptr svg) { if (svg == this->svg) return; this->svg = svg; sw->setSvg(svg); - fb->setDirty(); // Round framebuffer size to nearest grid fb->box.size = sw->box.size.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE); panelBorder->box.size = fb->box.size; box.size = fb->box.size; -} - -void ThemedSvgPanel::step() { - SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg); - SvgPanel::step(); -} - - -void ThemedSvgPanel::setBackground(std::shared_ptr lightSvg, std::shared_ptr darkSvg) { - this->lightSvg = lightSvg; - this->darkSvg = darkSvg; - SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg); + fb->setDirty(); } diff --git a/src/app/SvgPort.cpp b/src/app/SvgPort.cpp index 13722351..0fc36a7e 100644 --- a/src/app/SvgPort.cpp +++ b/src/app/SvgPort.cpp @@ -20,14 +20,18 @@ SvgPort::SvgPort() { } void SvgPort::setSvg(std::shared_ptr svg) { + if (svg == sw->svg) + return; + sw->setSvg(svg); fb->box.size = sw->box.size; box.size = sw->box.size; + // Move shadow downward by 10% shadow->box.size = sw->box.size; shadow->box.pos = math::Vec(0, sw->box.size.y * 0.10); - fb->dirty = true; + fb->setDirty(); } diff --git a/src/app/SvgScrew.cpp b/src/app/SvgScrew.cpp index 918c01fb..dd199e28 100644 --- a/src/app/SvgScrew.cpp +++ b/src/app/SvgScrew.cpp @@ -20,23 +20,10 @@ void SvgScrew::setSvg(std::shared_ptr svg) { return; sw->setSvg(svg); - fb->setDirty(); - fb->box.size = sw->box.size; box.size = sw->box.size; -} - -void ThemedSvgScrew::step() { - SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg); - SvgScrew::step(); -} - - -void ThemedSvgScrew::setSvg(std::shared_ptr lightSvg, std::shared_ptr darkSvg) { - this->lightSvg = lightSvg; - this->darkSvg = darkSvg; - SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg); + fb->setDirty(); } diff --git a/src/app/SvgSlider.cpp b/src/app/SvgSlider.cpp index 61268c4d..56073471 100644 --- a/src/app/SvgSlider.cpp +++ b/src/app/SvgSlider.cpp @@ -20,17 +20,31 @@ SvgSlider::SvgSlider() { void SvgSlider::setBackgroundSvg(std::shared_ptr svg) { + if (svg == background->svg) + return; + background->setSvg(svg); box.size = background->box.size; fb->box.size = background->box.size; fb->setDirty(); + + // Dispatch ChangeEvent + ChangeEvent eChange; + onChange(eChange); } void SvgSlider::setHandleSvg(std::shared_ptr svg) { + if (svg == handle->svg) + return; + handle->setSvg(svg); handle->box.pos = minHandlePos; fb->setDirty(); + + // Dispatch ChangeEvent + ChangeEvent eChange; + onChange(eChange); } @@ -38,7 +52,7 @@ void SvgSlider::setHandlePos(math::Vec minHandlePos, math::Vec maxHandlePos) { this->minHandlePos = minHandlePos; this->maxHandlePos = maxHandlePos; - // Dispatch ChangeEvent since the handle position changed + // Dispatch ChangeEvent ChangeEvent eChange; onChange(eChange); }