Browse Source

Make ThemedSvg* classes fully inline. Refactor app::Svg* classes.

tags/v2.4.0
Andrew Belt 1 year ago
parent
commit
e02ef2932c
8 changed files with 60 additions and 38 deletions
  1. +11
    -3
      include/app/SvgPanel.hpp
  2. +11
    -2
      include/app/SvgScrew.hpp
  3. +3
    -2
      src/app/SvgButton.cpp
  4. +11
    -1
      src/app/SvgKnob.cpp
  5. +3
    -14
      src/app/SvgPanel.cpp
  6. +5
    -1
      src/app/SvgPort.cpp
  7. +1
    -14
      src/app/SvgScrew.cpp
  8. +15
    -1
      src/app/SvgSlider.cpp

+ 11
- 3
include/app/SvgPanel.hpp View File

@@ -3,7 +3,7 @@
#include <widget/TransparentWidget.hpp>
#include <widget/FramebufferWidget.hpp>
#include <widget/SvgWidget.hpp>
#include <context.hpp>
#include <settings.hpp>


namespace rack {
@@ -34,8 +34,16 @@ struct ThemedSvgPanel : SvgPanel {
std::shared_ptr<window::Svg> lightSvg;
std::shared_ptr<window::Svg> darkSvg;

void step() override;
void setBackground(std::shared_ptr<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg);
void setBackground(std::shared_ptr<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg) {
this->lightSvg = lightSvg;
this->darkSvg = darkSvg;
SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg);
}

void step() override {
SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg);
SvgPanel::step();
}
};




+ 11
- 2
include/app/SvgScrew.hpp View File

@@ -3,6 +3,7 @@
#include <widget/Widget.hpp>
#include <widget/FramebufferWidget.hpp>
#include <widget/SvgWidget.hpp>
#include <settings.hpp>


namespace rack {
@@ -26,8 +27,16 @@ struct ThemedSvgScrew : SvgScrew {
std::shared_ptr<window::Svg> lightSvg;
std::shared_ptr<window::Svg> darkSvg;

void step() override;
void setSvg(std::shared_ptr<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg);
void setSvg(std::shared_ptr<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg) {
this->lightSvg = lightSvg;
this->darkSvg = darkSvg;
SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg);
}

void step() override {
SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg);
SvgScrew::step();
}
};




+ 3
- 2
src/app/SvgButton.cpp View File

@@ -39,6 +39,7 @@ void SvgButton::addFrame(std::shared_ptr<window::Svg> 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();
}
}



+ 11
- 1
src/app/SvgKnob.cpp View File

@@ -21,14 +21,24 @@ SvgKnob::SvgKnob() {
}

void SvgKnob::setSvg(std::shared_ptr<window::Svg> 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);
}


+ 3
- 14
src/app/SvgPanel.cpp View File

@@ -1,5 +1,5 @@
#include <app/SvgPanel.hpp>
#include <settings.hpp>
#include <context.hpp>


namespace rack {
@@ -40,31 +40,20 @@ void SvgPanel::step() {
Widget::step();
}


void SvgPanel::setBackground(std::shared_ptr<window::Svg> 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<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg) {
this->lightSvg = lightSvg;
this->darkSvg = darkSvg;
SvgPanel::setBackground(settings::preferDarkPanels ? darkSvg : lightSvg);
fb->setDirty();
}




+ 5
- 1
src/app/SvgPort.cpp View File

@@ -20,14 +20,18 @@ SvgPort::SvgPort() {
}

void SvgPort::setSvg(std::shared_ptr<window::Svg> 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();
}




+ 1
- 14
src/app/SvgScrew.cpp View File

@@ -20,23 +20,10 @@ void SvgScrew::setSvg(std::shared_ptr<window::Svg> 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<window::Svg> lightSvg, std::shared_ptr<window::Svg> darkSvg) {
this->lightSvg = lightSvg;
this->darkSvg = darkSvg;
SvgScrew::setSvg(settings::preferDarkPanels ? darkSvg : lightSvg);
fb->setDirty();
}




+ 15
- 1
src/app/SvgSlider.cpp View File

@@ -20,17 +20,31 @@ SvgSlider::SvgSlider() {


void SvgSlider::setBackgroundSvg(std::shared_ptr<window::Svg> 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<window::Svg> 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);
}


Loading…
Cancel
Save