diff --git a/include/app/ModuleWidget.hpp b/include/app/ModuleWidget.hpp index 94ca4d62..97303d47 100644 --- a/include/app/ModuleWidget.hpp +++ b/include/app/ModuleWidget.hpp @@ -45,7 +45,7 @@ struct ModuleWidget : widget::OpaqueWidget { Transfers ownership */ void setModule(engine::Module *module); - void setPanel(std::shared_ptr svg); + void setPanel(std::shared_ptr svg); /** Convenience functions for adding special widgets (calls addChild()) */ void addParam(ParamWidget *param); diff --git a/include/app/SVGSlider.hpp b/include/app/SVGSlider.hpp deleted file mode 100644 index 823fd744..00000000 --- a/include/app/SVGSlider.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "app/common.hpp" -#include "app/SliderKnob.hpp" -#include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" - - -namespace rack { -namespace app { - - -/** Behaves like a knob but linearly moves an widget::SVGWidget between two points. -Can be used for horizontal or vertical linear faders. -*/ -struct SVGSlider : app::SliderKnob { - widget::FramebufferWidget *fb; - widget::SVGWidget *background; - widget::SVGWidget *handle; - /** Intermediate positions will be interpolated between these positions */ - math::Vec minHandlePos, maxHandlePos; - - SVGSlider(); - void setBackgroundSVG(std::shared_ptr backgroundSVG); - void setHandleSVG(std::shared_ptr handleSVG); - void onChange(const event::Change &e) override; - - DEPRECATED void setSVGs(std::shared_ptr backgroundSVG, std::shared_ptr handleSVG) { - setBackgroundSVG(backgroundSVG); - setHandleSVG(handleSVG); - } -}; - - -} // namespace app -} // namespace rack diff --git a/include/app/SVGButton.hpp b/include/app/SvgButton.hpp similarity index 61% rename from include/app/SVGButton.hpp rename to include/app/SvgButton.hpp index 4cf5e822..d015a67a 100644 --- a/include/app/SVGButton.hpp +++ b/include/app/SvgButton.hpp @@ -2,25 +2,28 @@ #include "app/common.hpp" #include "widget/OpaqueWidget.hpp" #include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" namespace rack { namespace app { -struct SVGButton : widget::OpaqueWidget { +struct SvgButton : widget::OpaqueWidget { widget::FramebufferWidget *fb; - widget::SVGWidget *sw; - std::vector> frames; + widget::SvgWidget *sw; + std::vector> frames; - SVGButton(); - void addFrame(std::shared_ptr svg); + SvgButton(); + void addFrame(std::shared_ptr svg); void onDragStart(const event::DragStart &e) override; void onDragEnd(const event::DragEnd &e) override; void onDragDrop(const event::DragDrop &e) override; }; +DEPRECATED typedef SvgButton SVGButton; + + } // namespace app } // namespace rack diff --git a/include/app/SVGKnob.hpp b/include/app/SvgKnob.hpp similarity index 68% rename from include/app/SVGKnob.hpp rename to include/app/SvgKnob.hpp index f744caa3..17bdf8eb 100644 --- a/include/app/SVGKnob.hpp +++ b/include/app/SvgKnob.hpp @@ -3,7 +3,7 @@ #include "app/Knob.hpp" #include "widget/FramebufferWidget.hpp" #include "widget/TransformWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" #include "app/CircularShadow.hpp" @@ -12,19 +12,23 @@ namespace app { /** A knob which rotates an SVG and caches it in a framebuffer */ -struct SVGKnob : Knob { +struct SvgKnob : Knob { widget::FramebufferWidget *fb; widget::TransformWidget *tw; - widget::SVGWidget *sw; + widget::SvgWidget *sw; CircularShadow *shadow; /** Angles in radians */ float minAngle, maxAngle; - SVGKnob(); - void setSVG(std::shared_ptr svg); + SvgKnob(); + void setSvg(std::shared_ptr svg); + DEPRECATED void setSVG(std::shared_ptr svg) {setSvg(svg);} void onChange(const event::Change &e) override; }; +DEPRECATED typedef SvgKnob SVGKnob; + + } // namespace app } // namespace rack diff --git a/include/app/SVGPanel.hpp b/include/app/SvgPanel.hpp similarity index 68% rename from include/app/SVGPanel.hpp rename to include/app/SvgPanel.hpp index 5fe84a1b..c7d62032 100644 --- a/include/app/SVGPanel.hpp +++ b/include/app/SvgPanel.hpp @@ -2,7 +2,7 @@ #include "app/common.hpp" #include "widget/TransparentWidget.hpp" #include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" #include "app.hpp" @@ -15,12 +15,14 @@ struct PanelBorder : widget::TransparentWidget { }; -struct SVGPanel : widget::FramebufferWidget { +struct SvgPanel : widget::FramebufferWidget { void step() override; - void setBackground(std::shared_ptr svg); + void setBackground(std::shared_ptr svg); }; +DEPRECATED typedef SvgPanel SVGPanel; + } // namespace app } // namespace rack diff --git a/include/app/SVGPort.hpp b/include/app/SvgPort.hpp similarity index 53% rename from include/app/SVGPort.hpp rename to include/app/SvgPort.hpp index 86f4e804..b86b33eb 100644 --- a/include/app/SVGPort.hpp +++ b/include/app/SvgPort.hpp @@ -2,7 +2,7 @@ #include "app/common.hpp" #include "app/PortWidget.hpp" #include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" #include "app/CircularShadow.hpp" @@ -10,15 +10,19 @@ namespace rack { namespace app { -struct SVGPort : PortWidget { +struct SvgPort : PortWidget { widget::FramebufferWidget *fb; - widget::SVGWidget *sw; + widget::SvgWidget *sw; CircularShadow *shadow; - SVGPort(); - void setSVG(std::shared_ptr svg); + SvgPort(); + void setSvg(std::shared_ptr svg); + DEPRECATED void setSVG(std::shared_ptr svg) {setSvg(svg);} }; +DEPRECATED typedef SvgPort SVGPort; + + } // namespace app } // namespace rack diff --git a/include/app/SVGScrew.hpp b/include/app/SvgScrew.hpp similarity index 61% rename from include/app/SVGScrew.hpp rename to include/app/SvgScrew.hpp index f6d27853..a0810129 100644 --- a/include/app/SVGScrew.hpp +++ b/include/app/SvgScrew.hpp @@ -1,7 +1,7 @@ #pragma once #include "common.hpp" #include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" namespace rack { @@ -9,12 +9,15 @@ namespace app { /** If you don't add these to your ModuleWidget, they will fall out of the rack... */ -struct SVGScrew : widget::FramebufferWidget { - widget::SVGWidget *sw; +struct SvgScrew : widget::FramebufferWidget { + widget::SvgWidget *sw; - SVGScrew(); + SvgScrew(); }; +DEPRECATED typedef SvgScrew SVGScrew; + + } // namespace app } // namespace rack diff --git a/include/app/SvgSlider.hpp b/include/app/SvgSlider.hpp new file mode 100644 index 00000000..44e03614 --- /dev/null +++ b/include/app/SvgSlider.hpp @@ -0,0 +1,40 @@ +#pragma once +#include "app/common.hpp" +#include "app/SliderKnob.hpp" +#include "widget/FramebufferWidget.hpp" +#include "widget/SvgWidget.hpp" + + +namespace rack { +namespace app { + + +/** Behaves like a knob but linearly moves an widget::SvgWidget between two points. +Can be used for horizontal or vertical linear faders. +*/ +struct SvgSlider : app::SliderKnob { + widget::FramebufferWidget *fb; + widget::SvgWidget *background; + widget::SvgWidget *handle; + /** Intermediate positions will be interpolated between these positions */ + math::Vec minHandlePos, maxHandlePos; + + SvgSlider(); + void setBackgroundSvg(std::shared_ptr svg); + void setHandleSvg(std::shared_ptr svg); + void onChange(const event::Change &e) override; + + DEPRECATED void setBackgroundSVG(std::shared_ptr svg) {setBackgroundSvg(svg);} + DEPRECATED void setHandleSVG(std::shared_ptr svg) {setBackgroundSvg(svg);} + DEPRECATED void setSVGs(std::shared_ptr backgroundSvg, std::shared_ptr handleSvg) { + setBackgroundSvg(backgroundSvg); + setHandleSvg(handleSvg); + } +}; + + +DEPRECATED typedef SvgSlider SVGSlider; + + +} // namespace app +} // namespace rack diff --git a/include/app/SVGSwitch.hpp b/include/app/SvgSwitch.hpp similarity index 64% rename from include/app/SVGSwitch.hpp rename to include/app/SvgSwitch.hpp index 39869759..a7eecfb6 100644 --- a/include/app/SVGSwitch.hpp +++ b/include/app/SvgSwitch.hpp @@ -1,7 +1,7 @@ #pragma once #include "app/common.hpp" #include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" #include "app/Switch.hpp" @@ -10,17 +10,20 @@ namespace app { /** A ParamWidget with multiple frames corresponding to its value */ -struct SVGSwitch : Switch { +struct SvgSwitch : Switch { widget::FramebufferWidget *fb; - widget::SVGWidget *sw; - std::vector> frames; + widget::SvgWidget *sw; + std::vector> frames; - SVGSwitch(); + SvgSwitch(); /** Adds an SVG file to represent the next switch position */ - void addFrame(std::shared_ptr svg); + void addFrame(std::shared_ptr svg); void onChange(const event::Change &e) override; }; +DEPRECATED typedef SvgSwitch SVGSwitch; + + } // namespace app } // namespace rack diff --git a/include/component.hpp b/include/component.hpp index 2ff8aeed..b79795b0 100644 --- a/include/component.hpp +++ b/include/component.hpp @@ -27,7 +27,7 @@ static const NVGcolor DARK_GRAY = nvgRGB(0x17, 0x17, 0x17); // Knobs //////////////////// -struct RoundKnob : app::SVGKnob { +struct RoundKnob : app::SvgKnob { RoundKnob() { minAngle = -0.83*M_PI; maxAngle = 0.83*M_PI; @@ -36,25 +36,25 @@ struct RoundKnob : app::SVGKnob { struct RoundBlackKnob : RoundKnob { RoundBlackKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/RoundBlackKnob.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundBlackKnob.svg"))); } }; struct RoundSmallBlackKnob : RoundKnob { RoundSmallBlackKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/RoundSmallBlackKnob.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundSmallBlackKnob.svg"))); } }; struct RoundLargeBlackKnob : RoundKnob { RoundLargeBlackKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/RoundLargeBlackKnob.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundLargeBlackKnob.svg"))); } }; struct RoundHugeBlackKnob : RoundKnob { RoundHugeBlackKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/RoundHugeBlackKnob.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/RoundHugeBlackKnob.svg"))); } }; @@ -65,7 +65,7 @@ struct RoundBlackSnapKnob : RoundBlackKnob { }; -struct Davies1900hKnob : app::SVGKnob { +struct Davies1900hKnob : app::SvgKnob { Davies1900hKnob() { minAngle = -0.83*M_PI; maxAngle = 0.83*M_PI; @@ -74,42 +74,42 @@ struct Davies1900hKnob : app::SVGKnob { struct Davies1900hWhiteKnob : Davies1900hKnob { Davies1900hWhiteKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Davies1900hWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hWhite.svg"))); } }; struct Davies1900hBlackKnob : Davies1900hKnob { Davies1900hBlackKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Davies1900hBlack.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hBlack.svg"))); } }; struct Davies1900hRedKnob : Davies1900hKnob { Davies1900hRedKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Davies1900hRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hRed.svg"))); } }; struct Davies1900hLargeWhiteKnob : Davies1900hKnob { Davies1900hLargeWhiteKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Davies1900hLargeWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hLargeWhite.svg"))); } }; struct Davies1900hLargeBlackKnob : Davies1900hKnob { Davies1900hLargeBlackKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Davies1900hLargeBlack.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hLargeBlack.svg"))); } }; struct Davies1900hLargeRedKnob : Davies1900hKnob { Davies1900hLargeRedKnob() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Davies1900hLargeRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Davies1900hLargeRed.svg"))); } }; -struct Rogan : app::SVGKnob { +struct Rogan : app::SvgKnob { Rogan() { minAngle = -0.83*M_PI; maxAngle = 0.83*M_PI; @@ -118,191 +118,191 @@ struct Rogan : app::SVGKnob { struct Rogan6PSWhite : Rogan { Rogan6PSWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan6PSWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan6PSWhite.svg"))); } }; struct Rogan5PSGray : Rogan { Rogan5PSGray() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan5PSGray.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan5PSGray.svg"))); } }; struct Rogan3PSBlue : Rogan { Rogan3PSBlue() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PSBlue.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSBlue.svg"))); } }; struct Rogan3PSRed : Rogan { Rogan3PSRed() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PSRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSRed.svg"))); } }; struct Rogan3PSGreen : Rogan { Rogan3PSGreen() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PSGreen.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSGreen.svg"))); } }; struct Rogan3PSWhite : Rogan { Rogan3PSWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PSWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PSWhite.svg"))); } }; struct Rogan3PBlue : Rogan { Rogan3PBlue() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PBlue.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PBlue.svg"))); } }; struct Rogan3PRed : Rogan { Rogan3PRed() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PRed.svg"))); } }; struct Rogan3PGreen : Rogan { Rogan3PGreen() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PGreen.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PGreen.svg"))); } }; struct Rogan3PWhite : Rogan { Rogan3PWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan3PWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan3PWhite.svg"))); } }; struct Rogan2SGray : Rogan { Rogan2SGray() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2SGray.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2SGray.svg"))); } }; struct Rogan2PSBlue : Rogan { Rogan2PSBlue() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PSBlue.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSBlue.svg"))); } }; struct Rogan2PSRed : Rogan { Rogan2PSRed() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PSRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSRed.svg"))); } }; struct Rogan2PSGreen : Rogan { Rogan2PSGreen() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PSGreen.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSGreen.svg"))); } }; struct Rogan2PSWhite : Rogan { Rogan2PSWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PSWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PSWhite.svg"))); } }; struct Rogan2PBlue : Rogan { Rogan2PBlue() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PBlue.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PBlue.svg"))); } }; struct Rogan2PRed : Rogan { Rogan2PRed() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PRed.svg"))); } }; struct Rogan2PGreen : Rogan { Rogan2PGreen() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PGreen.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PGreen.svg"))); } }; struct Rogan2PWhite : Rogan { Rogan2PWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan2PWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan2PWhite.svg"))); } }; struct Rogan1PSBlue : Rogan { Rogan1PSBlue() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PSBlue.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSBlue.svg"))); } }; struct Rogan1PSRed : Rogan { Rogan1PSRed() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PSRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSRed.svg"))); } }; struct Rogan1PSGreen : Rogan { Rogan1PSGreen() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PSGreen.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSGreen.svg"))); } }; struct Rogan1PSWhite : Rogan { Rogan1PSWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PSWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PSWhite.svg"))); } }; struct Rogan1PBlue : Rogan { Rogan1PBlue() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PBlue.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PBlue.svg"))); } }; struct Rogan1PRed : Rogan { Rogan1PRed() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PRed.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PRed.svg"))); } }; struct Rogan1PGreen : Rogan { Rogan1PGreen() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PGreen.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PGreen.svg"))); } }; struct Rogan1PWhite : Rogan { Rogan1PWhite() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/Rogan1PWhite.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Rogan1PWhite.svg"))); } }; -struct SynthTechAlco : app::SVGKnob { +struct SynthTechAlco : app::SvgKnob { SynthTechAlco() { minAngle = -0.82*M_PI; maxAngle = 0.82*M_PI; - setSVG(SVG::load(asset::system("res/ComponentLibrary/SynthTechAlco.svg"))); - SVGWidget *cap = new SVGWidget; - cap->setSVG(SVG::load(asset::system("res/ComponentLibrary/SynthTechAlco_cap.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/SynthTechAlco.svg"))); + SvgWidget *cap = new SvgWidget; + cap->setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/SynthTechAlco_cap.svg"))); addChild(cap); } }; -struct Trimpot : app::SVGKnob { +struct Trimpot : app::SvgKnob { Trimpot() { minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; - setSVG(SVG::load(asset::system("res/ComponentLibrary/Trimpot.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/Trimpot.svg"))); } }; -struct BefacoBigKnob : app::SVGKnob { +struct BefacoBigKnob : app::SvgKnob { BefacoBigKnob() { minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; - setSVG(SVG::load(asset::system("res/ComponentLibrary/BefacoBigKnob.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoBigKnob.svg"))); } }; @@ -312,62 +312,62 @@ struct BefacoBigSnapKnob : BefacoBigKnob { } }; -struct BefacoTinyKnob : app::SVGKnob { +struct BefacoTinyKnob : app::SvgKnob { BefacoTinyKnob() { minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; - setSVG(SVG::load(asset::system("res/ComponentLibrary/BefacoTinyKnob.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoTinyKnob.svg"))); } }; -struct BefacoSlidePot : app::SVGSlider { +struct BefacoSlidePot : app::SvgSlider { BefacoSlidePot() { math::Vec margin = math::Vec(3.5, 3.5); maxHandlePos = math::Vec(-1, -2).plus(margin); minHandlePos = math::Vec(-1, 87).plus(margin); - setBackgroundSVG(SVG::load(asset::system("res/ComponentLibrary/BefacoSlidePot.svg"))); - setHandleSVG(SVG::load(asset::system("res/ComponentLibrary/BefacoSlidePotHandle.svg"))); + setBackgroundSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSlidePot.svg"))); + setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSlidePotHandle.svg"))); background->box.pos = margin; box.size = background->box.size.plus(margin.mult(2)); } }; -struct LEDSlider : app::SVGSlider { +struct LEDSlider : app::SvgSlider { LEDSlider() { maxHandlePos = mm2px(math::Vec(0.738, 0.738).plus(math::Vec(2, 0))); minHandlePos = mm2px(math::Vec(0.738, 22.078).plus(math::Vec(2, 0))); - setBackgroundSVG(SVG::load(asset::system("res/ComponentLibrary/LEDSlider.svg"))); + setBackgroundSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSlider.svg"))); } }; /** API is unstable for LEDSlider. Will add a LightWidget later. */ struct LEDSliderGreen : LEDSlider { LEDSliderGreen() { - setHandleSVG(SVG::load(asset::system("res/ComponentLibrary/LEDSliderGreenHandle.svg"))); + setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderGreenHandle.svg"))); } }; struct LEDSliderRed : LEDSlider { LEDSliderRed() { - setHandleSVG(SVG::load(asset::system("res/ComponentLibrary/LEDSliderRedHandle.svg"))); + setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderRedHandle.svg"))); } }; struct LEDSliderYellow : LEDSlider { LEDSliderYellow() { - setHandleSVG(SVG::load(asset::system("res/ComponentLibrary/LEDSliderYellowHandle.svg"))); + setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderYellowHandle.svg"))); } }; struct LEDSliderBlue : LEDSlider { LEDSliderBlue() { - setHandleSVG(SVG::load(asset::system("res/ComponentLibrary/LEDSliderBlueHandle.svg"))); + setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderBlueHandle.svg"))); } }; struct LEDSliderWhite : LEDSlider { LEDSliderWhite() { - setHandleSVG(SVG::load(asset::system("res/ComponentLibrary/LEDSliderWhiteHandle.svg"))); + setHandleSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDSliderWhiteHandle.svg"))); } }; @@ -375,21 +375,21 @@ struct LEDSliderWhite : LEDSlider { // Ports //////////////////// -struct PJ301MPort : app::SVGPort { +struct PJ301MPort : app::SvgPort { PJ301MPort() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/PJ301M.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/PJ301M.svg"))); } }; -struct PJ3410Port : app::SVGPort { +struct PJ3410Port : app::SvgPort { PJ3410Port() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/PJ3410.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/PJ3410.svg"))); } }; -struct CL1362Port : app::SVGPort { +struct CL1362Port : app::SvgPort { CL1362Port() { - setSVG(SVG::load(asset::system("res/ComponentLibrary/CL1362.svg"))); + setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/CL1362.svg"))); } }; @@ -510,79 +510,79 @@ struct PB61303Light : BASE { // Switches //////////////////// -struct NKK : app::SVGSwitch { +struct NKK : app::SvgSwitch { NKK() { - addFrame(SVG::load(asset::system("res/ComponentLibrary/NKK_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/NKK_1.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/NKK_2.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_2.svg"))); } }; -struct CKSS : app::SVGSwitch { +struct CKSS : app::SvgSwitch { CKSS() { - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSS_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSS_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSS_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSS_1.svg"))); } }; -struct CKSSThree : app::SVGSwitch { +struct CKSSThree : app::SvgSwitch { CKSSThree() { - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSSThree_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSSThree_1.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKSSThree_2.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKSSThree_2.svg"))); } }; -struct CKD6 : app::SVGSwitch { +struct CKD6 : app::SvgSwitch { CKD6() { momentary = true; - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKD6_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKD6_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_1.svg"))); } }; -struct TL1105 : app::SVGSwitch { +struct TL1105 : app::SvgSwitch { TL1105() { momentary = true; - addFrame(SVG::load(asset::system("res/ComponentLibrary/TL1105_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/TL1105_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/TL1105_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/TL1105_1.svg"))); } }; -struct LEDButton : app::SVGSwitch { +struct LEDButton : app::SvgSwitch { LEDButton() { momentary = true; - addFrame(SVG::load(asset::system("res/ComponentLibrary/LEDButton.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDButton.svg"))); } }; -struct BefacoSwitch : app::SVGSwitch { +struct BefacoSwitch : app::SvgSwitch { BefacoSwitch() { - addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoSwitch_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoSwitch_1.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoSwitch_2.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoSwitch_2.svg"))); } }; -struct BefacoPush : app::SVGSwitch { +struct BefacoPush : app::SvgSwitch { BefacoPush() { momentary = true; - addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoPush_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/BefacoPush_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoPush_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/BefacoPush_1.svg"))); } }; -struct LEDBezel : app::SVGSwitch { +struct LEDBezel : app::SvgSwitch { LEDBezel() { momentary = true; - addFrame(SVG::load(asset::system("res/ComponentLibrary/LEDBezel.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/LEDBezel.svg"))); } }; -struct PB61303 : app::SVGSwitch { +struct PB61303 : app::SvgSwitch { PB61303() { momentary = true; - addFrame(SVG::load(asset::system("res/ComponentLibrary/PB61303.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/PB61303.svg"))); } }; @@ -590,16 +590,16 @@ struct PB61303 : app::SVGSwitch { // Misc //////////////////// -struct ScrewSilver : app::SVGScrew { +struct ScrewSilver : app::SvgScrew { ScrewSilver() { - sw->setSVG(SVG::load(asset::system("res/ComponentLibrary/ScrewSilver.svg"))); + sw->setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/ScrewSilver.svg"))); box.size = sw->box.size; } }; -struct ScrewBlack : app::SVGScrew { +struct ScrewBlack : app::SvgScrew { ScrewBlack() { - sw->setSVG(SVG::load(asset::system("res/ComponentLibrary/ScrewBlack.svg"))); + sw->setSvg(APP->window->loadSvg(asset::system("res/ComponentLibrary/ScrewBlack.svg"))); box.size = sw->box.size; } }; diff --git a/include/dsp/vumeter.hpp b/include/dsp/vumeter.hpp index 20af3614..098a4592 100644 --- a/include/dsp/vumeter.hpp +++ b/include/dsp/vumeter.hpp @@ -6,7 +6,7 @@ namespace rack { namespace dsp { -/** Deprecated. */ +/** Deprecated. Use VUMeter2. */ struct VUMeter { /** Decibel level difference between adjacent meter lights */ float dBInterval = 3.0; @@ -15,7 +15,7 @@ struct VUMeter { void setValue(float v) { dBScaled = std::log10(std::abs(v)) * 20.0 / dBInterval; } - /** Returns the brightness of the light indexed by i + /** Returns the brightness of the light indexed by i. Light 0 is a clip light (red) which is either on or off. All others are smooth lights which are fully bright at -dBInterval*i and higher, and fully off at -dBInterval*(i-1). */ @@ -61,6 +61,7 @@ struct VUMeter2 { } /** Returns the LED brightness measuring tick marks between dbMin and dbMax. + For example, `getBrightness(-6.f, 0.f)` will be at minimum brightness at -6dB and maximum brightness at 0dB. Set dbMin == dbMax == 0.f for a clip indicator. Expensive, so call this infrequently. */ diff --git a/include/rack.hpp b/include/rack.hpp index f0f2d63f..c0d388da 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -17,9 +17,9 @@ #include "widget/OpaqueWidget.hpp" #include "widget/TransformWidget.hpp" #include "widget/ZoomWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" #include "widget/FramebufferWidget.hpp" -#include "widget/GLWidget.hpp" +#include "widget/OpenGlWidget.hpp" #include "ui/SequentialLayout.hpp" #include "ui/Label.hpp" @@ -56,13 +56,13 @@ #include "app/Scene.hpp" #include "app/RackScrollWidget.hpp" #include "app/RackWidget.hpp" -#include "app/SVGButton.hpp" -#include "app/SVGKnob.hpp" -#include "app/SVGPanel.hpp" -#include "app/SVGPort.hpp" -#include "app/SVGScrew.hpp" -#include "app/SVGSlider.hpp" -#include "app/SVGSwitch.hpp" +#include "app/SvgButton.hpp" +#include "app/SvgKnob.hpp" +#include "app/SvgPanel.hpp" +#include "app/SvgPort.hpp" +#include "app/SvgScrew.hpp" +#include "app/SvgSlider.hpp" +#include "app/SvgSwitch.hpp" #include "app/Toolbar.hpp" #include "app/CableWidget.hpp" diff --git a/include/ui/IconButton.hpp b/include/ui/IconButton.hpp index c36858cc..b38e4451 100644 --- a/include/ui/IconButton.hpp +++ b/include/ui/IconButton.hpp @@ -1,6 +1,6 @@ #pragma once #include "widget/FramebufferWidget.hpp" -#include "widget/SVGWidget.hpp" +#include "widget/SvgWidget.hpp" #include "ui/common.hpp" #include "ui/Button.hpp" @@ -11,10 +11,11 @@ namespace ui { struct IconButton : Button { widget::FramebufferWidget *fw; - widget::SVGWidget *sw; + widget::SvgWidget *sw; IconButton(); - void setSVG(std::shared_ptr svg); + void setSvg(std::shared_ptr svg); + DEPRECATED void setSVG(std::shared_ptr svg) {setSvg(svg);} }; diff --git a/include/widget/GLWidget.hpp b/include/widget/OpenGlWidget.hpp similarity index 87% rename from include/widget/GLWidget.hpp rename to include/widget/OpenGlWidget.hpp index 90482128..1562ae99 100644 --- a/include/widget/GLWidget.hpp +++ b/include/widget/OpenGlWidget.hpp @@ -6,7 +6,7 @@ namespace rack { namespace widget { -struct GLWidget : FramebufferWidget { +struct OpenGlWidget : FramebufferWidget { /** Draws every frame by default Override this to restore the default behavior of FramebufferWidget. */ diff --git a/include/widget/SVGWidget.hpp b/include/widget/SVGWidget.hpp deleted file mode 100644 index 019ab675..00000000 --- a/include/widget/SVGWidget.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include "widget/Widget.hpp" -#include "svg.hpp" - - -namespace rack { -namespace widget { - - -/** Draws an SVG */ -struct SVGWidget : Widget { - std::shared_ptr svg; - - /** Sets the box size to the svg image size */ - void wrap() { - if (svg && svg->handle) { - box.size = math::Vec(svg->handle->width, svg->handle->height); - } - else { - box.size = math::Vec(); - } - } - - /** Sets and wraps the SVG */ - void setSVG(std::shared_ptr svg) { - this->svg = svg; - wrap(); - } - - void draw(const DrawContext &ctx) override { - if (svg && svg->handle) { - svgDraw(ctx.vg, svg->handle); - } - } -}; - - -} // namespace widget -} // namespace rack diff --git a/include/widget/SvgWidget.hpp b/include/widget/SvgWidget.hpp new file mode 100644 index 00000000..12a4f9ec --- /dev/null +++ b/include/widget/SvgWidget.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "widget/Widget.hpp" +#include "svg.hpp" + + +namespace rack { +namespace widget { + + +/** Draws an SVG */ +struct SvgWidget : Widget { + std::shared_ptr svg; + + /** Sets the box size to the svg image size */ + void wrap(); + + /** Sets and wraps the SVG */ + void setSvg(std::shared_ptr svg); + DEPRECATED void setSVG(std::shared_ptr svg) {setSvg(svg);} + + void draw(const DrawContext &ctx) override; +}; + + +DEPRECATED typedef SvgWidget SVGWidget; + + +} // namespace widget +} // namespace rack diff --git a/include/window.hpp b/include/window.hpp index 139661c8..9133b027 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -40,26 +40,34 @@ namespace rack { // Constructing these directly will load from the disk each time. Use the load() functions to load from disk and cache them as long as the shared_ptr is held. struct Font { + NVGcontext *vg; int handle; - Font(const std::string &filename); + Font(NVGcontext *vg, const std::string &filename); ~Font(); - static std::shared_ptr load(const std::string &filename); + /** Use `APP->window->loadFont()` instead. */ + DEPRECATED static std::shared_ptr load(const std::string &filename); }; struct Image { + NVGcontext *vg; int handle; - Image(const std::string &filename); + Image(NVGcontext *vg, const std::string &filename); ~Image(); - static std::shared_ptr load(const std::string &filename); + /** Use `APP->window->loadImage()` instead. */ + DEPRECATED static std::shared_ptr load(const std::string &filename); }; -struct SVG { +struct Svg { NSVGimage *handle; - SVG(const std::string &filename); - ~SVG(); - static std::shared_ptr load(const std::string &filename); + Svg(const std::string &filename); + ~Svg(); + /** Use `APP->window->loadSvg()` instead. */ + DEPRECATED static std::shared_ptr load(const std::string &filename); }; +DEPRECATED typedef Svg SVG; + + struct Window { GLFWwindow *win = NULL; NVGcontext *vg = NULL; @@ -91,6 +99,10 @@ struct Window { int getMods(); void setFullScreen(bool fullScreen); bool isFullScreen(); + + std::shared_ptr loadFont(const std::string &filename); + std::shared_ptr loadImage(const std::string &filename); + std::shared_ptr loadSvg(const std::string &filename); }; diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index 74e2543f..27f78f96 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -236,7 +236,7 @@ struct AudioInterface : Module { struct AudioInterfaceWidget : ModuleWidget { AudioInterfaceWidget(AudioInterface *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/AudioInterface.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/AudioInterface.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/CV_CC.cpp b/src/Core/CV_CC.cpp index 043fc3be..ef85470c 100644 --- a/src/Core/CV_CC.cpp +++ b/src/Core/CV_CC.cpp @@ -112,7 +112,7 @@ struct CV_CC : Module { struct CV_CCWidget : ModuleWidget { CV_CCWidget(CV_CC *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/CV-CC.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/CV-CC.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/CV_Gate.cpp b/src/Core/CV_Gate.cpp index c66b3d77..0f802d39 100644 --- a/src/Core/CV_Gate.cpp +++ b/src/Core/CV_Gate.cpp @@ -146,7 +146,7 @@ struct CV_Gate : Module { struct CV_GateWidget : ModuleWidget { CV_GateWidget(CV_Gate *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/CV-Gate.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/CV-Gate.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/CV_MIDI.cpp b/src/Core/CV_MIDI.cpp index 8fdaaf23..fdccd618 100644 --- a/src/Core/CV_MIDI.cpp +++ b/src/Core/CV_MIDI.cpp @@ -316,7 +316,7 @@ struct CV_MIDI : Module { struct CV_MIDIWidget : ModuleWidget { CV_MIDIWidget(CV_MIDI *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/CV-MIDI.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/CV-MIDI.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDI_CC.cpp b/src/Core/MIDI_CC.cpp index 0d08ea58..184c9032 100644 --- a/src/Core/MIDI_CC.cpp +++ b/src/Core/MIDI_CC.cpp @@ -137,7 +137,7 @@ struct MIDI_CC : Module { struct MIDI_CCWidget : ModuleWidget { MIDI_CCWidget(MIDI_CC *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/MIDI-CC.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/MIDI-CC.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDI_CV.cpp b/src/Core/MIDI_CV.cpp index b6675716..f3ff420b 100644 --- a/src/Core/MIDI_CV.cpp +++ b/src/Core/MIDI_CV.cpp @@ -260,7 +260,7 @@ struct MIDI_CV : Module { struct MIDI_CVWidget : ModuleWidget { MIDI_CVWidget(MIDI_CV *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/MIDI-CV.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/MIDI-CV.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDI_Gate.cpp b/src/Core/MIDI_Gate.cpp index fbceb0b1..6b52d667 100644 --- a/src/Core/MIDI_Gate.cpp +++ b/src/Core/MIDI_Gate.cpp @@ -147,7 +147,7 @@ struct MIDI_Gate : Module { struct MIDI_GateWidget : ModuleWidget { MIDI_GateWidget(MIDI_Gate *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/MIDI-Gate.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/MIDI-Gate.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/MIDI_Map.cpp b/src/Core/MIDI_Map.cpp index c4c71caa..c4233ea9 100644 --- a/src/Core/MIDI_Map.cpp +++ b/src/Core/MIDI_Map.cpp @@ -46,13 +46,13 @@ struct MIDI_Map : Module { }; -struct CKD6Button : SVGButton { +struct CKD6Button : SvgButton { MIDI_Map *module; int id; CKD6Button() { - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKD6_0.svg"))); - addFrame(SVG::load(asset::system("res/ComponentLibrary/CKD6_1.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_0.svg"))); + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/CKD6_1.svg"))); } void onAction(const event::Action &e) override { @@ -73,7 +73,7 @@ TWidget *createMapButtonCentered(math::Vec pos, MIDI_Map *module, int id) { struct MIDI_MapWidget : ModuleWidget { MIDI_MapWidget(MIDI_Map *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/MIDI-Map.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/MIDI-Map.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/Core/Notes.cpp b/src/Core/Notes.cpp index a4d2d1bb..4f16b58c 100644 --- a/src/Core/Notes.cpp +++ b/src/Core/Notes.cpp @@ -9,7 +9,7 @@ struct NotesWidget : ModuleWidget { NotesWidget(Module *module) { setModule(module); - setPanel(SVG::load(asset::system("res/Core/Notes.svg"))); + setPanel(APP->window->loadSvg(asset::system("res/Core/Notes.svg"))); addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); diff --git a/src/app/LedDisplay.cpp b/src/app/LedDisplay.cpp index d0bbf2b4..4160409a 100644 --- a/src/app/LedDisplay.cpp +++ b/src/app/LedDisplay.cpp @@ -35,7 +35,7 @@ void LedDisplaySeparator::draw(const widget::DrawContext &ctx) { LedDisplayChoice::LedDisplayChoice() { box.size = mm2px(math::Vec(0, 28.0 / 3)); - font = Font::load(asset::system("res/fonts/ShareTechMono-Regular.ttf")); + font = APP->window->loadFont(asset::system("res/fonts/ShareTechMono-Regular.ttf")); color = nvgRGB(0xff, 0xd7, 0x14); textOffset = math::Vec(10, 18); } @@ -65,7 +65,7 @@ void LedDisplayChoice::onButton(const event::Button &e) { LedDisplayTextField::LedDisplayTextField() { - font = Font::load(asset::system("res/fonts/ShareTechMono-Regular.ttf")); + font = APP->window->loadFont(asset::system("res/fonts/ShareTechMono-Regular.ttf")); color = nvgRGB(0xff, 0xd7, 0x14); textOffset = math::Vec(5, 5); } diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index a3e0af85..fc9d4829 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -3,7 +3,7 @@ #include "system.hpp" #include "asset.hpp" #include "app/Scene.hpp" -#include "app/SVGPanel.hpp" +#include "app/SvgPanel.hpp" #include "helpers.hpp" #include "app.hpp" #include "settings.hpp" @@ -299,7 +299,7 @@ void ModuleWidget::setModule(engine::Module *module) { this->module = module; } -void ModuleWidget::setPanel(std::shared_ptr svg) { +void ModuleWidget::setPanel(std::shared_ptr svg) { // Remove old panel if (panel) { removeChild(panel); @@ -308,7 +308,7 @@ void ModuleWidget::setPanel(std::shared_ptr svg) { } { - SVGPanel *panel = new SVGPanel; + SvgPanel *panel = new SvgPanel; panel->setBackground(svg); addChild(panel); box.size = panel->box.size; diff --git a/src/app/SVGButton.cpp b/src/app/SvgButton.cpp similarity index 58% rename from src/app/SVGButton.cpp rename to src/app/SvgButton.cpp index 5e912de8..f1e53e63 100644 --- a/src/app/SVGButton.cpp +++ b/src/app/SvgButton.cpp @@ -1,44 +1,44 @@ -#include "app/SVGButton.hpp" +#include "app/SvgButton.hpp" namespace rack { namespace app { -SVGButton::SVGButton() { +SvgButton::SvgButton() { fb = new widget::FramebufferWidget; addChild(fb); - sw = new widget::SVGWidget; + sw = new widget::SvgWidget; fb->addChild(sw); } -void SVGButton::addFrame(std::shared_ptr svg) { +void SvgButton::addFrame(std::shared_ptr svg) { frames.push_back(svg); // If this is our first frame, automatically set SVG and size if (!sw->svg) { - sw->setSVG(svg); + sw->setSvg(svg); box.size = sw->box.size; fb->box.size = sw->box.size; } } -void SVGButton::onDragStart(const event::DragStart &e) { +void SvgButton::onDragStart(const event::DragStart &e) { if (frames.size() >= 2) { - sw->setSVG(frames[1]); + sw->setSvg(frames[1]); fb->dirty = true; } e.consume(this); } -void SVGButton::onDragEnd(const event::DragEnd &e) { +void SvgButton::onDragEnd(const event::DragEnd &e) { if (frames.size() >= 1) { - sw->setSVG(frames[0]); + sw->setSvg(frames[0]); fb->dirty = true; } } -void SVGButton::onDragDrop(const event::DragDrop &e) { +void SvgButton::onDragDrop(const event::DragDrop &e) { if (e.origin == this) { event::Action eAction; onAction(eAction); diff --git a/src/app/SVGKnob.cpp b/src/app/SvgKnob.cpp similarity index 85% rename from src/app/SVGKnob.cpp rename to src/app/SvgKnob.cpp index 4e671057..1a098dfb 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SvgKnob.cpp @@ -1,11 +1,11 @@ -#include "app/SVGKnob.hpp" +#include "app/SvgKnob.hpp" namespace rack { namespace app { -SVGKnob::SVGKnob() { +SvgKnob::SvgKnob() { fb = new widget::FramebufferWidget; addChild(fb); @@ -16,12 +16,12 @@ SVGKnob::SVGKnob() { tw = new widget::TransformWidget; fb->addChild(tw); - sw = new widget::SVGWidget; + sw = new widget::SvgWidget; tw->addChild(sw); } -void SVGKnob::setSVG(std::shared_ptr svg) { - sw->setSVG(svg); +void SvgKnob::setSvg(std::shared_ptr svg) { + sw->setSvg(svg); tw->box.size = sw->box.size; fb->box.size = sw->box.size; box.size = sw->box.size; @@ -31,7 +31,7 @@ void SVGKnob::setSVG(std::shared_ptr svg) { // shadow->box = shadow->box.grow(math::Vec(2, 2)); } -void SVGKnob::onChange(const event::Change &e) { +void SvgKnob::onChange(const event::Change &e) { // Re-transform the widget::TransformWidget if (paramQuantity) { float angle; diff --git a/src/app/SVGPanel.cpp b/src/app/SvgPanel.cpp similarity index 81% rename from src/app/SVGPanel.cpp rename to src/app/SvgPanel.cpp index 488bc358..bf977dff 100644 --- a/src/app/SVGPanel.cpp +++ b/src/app/SvgPanel.cpp @@ -1,4 +1,4 @@ -#include "app/SVGPanel.hpp" +#include "app/SvgPanel.hpp" namespace rack { @@ -15,7 +15,7 @@ void PanelBorder::draw(const widget::DrawContext &ctx) { } -void SVGPanel::step() { +void SvgPanel::step() { if (math::isNear(APP->window->pixelRatio, 1.0)) { // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer oversample = 2.0; @@ -23,9 +23,9 @@ void SVGPanel::step() { widget::FramebufferWidget::step(); } -void SVGPanel::setBackground(std::shared_ptr svg) { - widget::SVGWidget *sw = new widget::SVGWidget; - sw->setSVG(svg); +void SvgPanel::setBackground(std::shared_ptr svg) { + widget::SvgWidget *sw = new widget::SvgWidget; + sw->setSvg(svg); addChild(sw); // Set size diff --git a/src/app/SVGPort.cpp b/src/app/SvgPort.cpp similarity index 73% rename from src/app/SVGPort.cpp rename to src/app/SvgPort.cpp index 400b56d2..ac6f7b71 100644 --- a/src/app/SVGPort.cpp +++ b/src/app/SvgPort.cpp @@ -1,26 +1,26 @@ -#include "app/SVGPort.hpp" +#include "app/SvgPort.hpp" namespace rack { namespace app { -SVGPort::SVGPort() { +SvgPort::SvgPort() { fb = new widget::FramebufferWidget; addChild(fb); shadow = new CircularShadow; fb->addChild(shadow); - // Avoid breakage if plugins fail to call setSVG() + // Avoid breakage if plugins fail to call setSvg() // In that case, just disable the shadow. shadow->box.size = math::Vec(); - sw = new widget::SVGWidget; + sw = new widget::SvgWidget; fb->addChild(sw); } -void SVGPort::setSVG(std::shared_ptr svg) { - sw->setSVG(svg); +void SvgPort::setSvg(std::shared_ptr svg) { + sw->setSvg(svg); fb->box.size = sw->box.size; box.size = sw->box.size; shadow->box.size = sw->box.size; diff --git a/src/app/SVGScrew.cpp b/src/app/SvgScrew.cpp similarity index 54% rename from src/app/SVGScrew.cpp rename to src/app/SvgScrew.cpp index bbdfa68e..5b8bb335 100644 --- a/src/app/SVGScrew.cpp +++ b/src/app/SvgScrew.cpp @@ -1,12 +1,12 @@ -#include "app/SVGScrew.hpp" +#include "app/SvgScrew.hpp" namespace rack { namespace app { -SVGScrew::SVGScrew() { - sw = new widget::SVGWidget; +SvgScrew::SvgScrew() { + sw = new widget::SvgWidget; addChild(sw); } diff --git a/src/app/SVGSlider.cpp b/src/app/SvgSlider.cpp similarity index 63% rename from src/app/SVGSlider.cpp rename to src/app/SvgSlider.cpp index ae671835..f494ced3 100644 --- a/src/app/SVGSlider.cpp +++ b/src/app/SvgSlider.cpp @@ -1,36 +1,36 @@ -#include "app/SVGSlider.hpp" +#include "app/SvgSlider.hpp" namespace rack { namespace app { -SVGSlider::SVGSlider() { +SvgSlider::SvgSlider() { fb = new widget::FramebufferWidget; addChild(fb); - background = new widget::SVGWidget; + background = new widget::SvgWidget; fb->addChild(background); - handle = new widget::SVGWidget; + handle = new widget::SvgWidget; fb->addChild(handle); speed = 2.0; } -void SVGSlider::setBackgroundSVG(std::shared_ptr backgroundSVG) { - background->setSVG(backgroundSVG); +void SvgSlider::setBackgroundSvg(std::shared_ptr svg) { + background->setSvg(svg); fb->box.size = background->box.size; box.size = background->box.size; } -void SVGSlider::setHandleSVG(std::shared_ptr handleSVG) { - handle->setSVG(handleSVG); +void SvgSlider::setHandleSvg(std::shared_ptr svg) { + handle->setSvg(svg); handle->box.pos = maxHandlePos; fb->dirty = true; } -void SVGSlider::onChange(const event::Change &e) { +void SvgSlider::onChange(const event::Change &e) { if (paramQuantity) { // Interpolate handle position float v = paramQuantity->getScaledValue(); diff --git a/src/app/SVGSwitch.cpp b/src/app/SvgSwitch.cpp similarity index 69% rename from src/app/SVGSwitch.cpp rename to src/app/SvgSwitch.cpp index f3b8ceb5..42970ada 100644 --- a/src/app/SVGSwitch.cpp +++ b/src/app/SvgSwitch.cpp @@ -1,33 +1,33 @@ -#include "app/SVGSwitch.hpp" +#include "app/SvgSwitch.hpp" namespace rack { namespace app { -SVGSwitch::SVGSwitch() { +SvgSwitch::SvgSwitch() { fb = new widget::FramebufferWidget; addChild(fb); - sw = new widget::SVGWidget; + sw = new widget::SvgWidget; fb->addChild(sw); } -void SVGSwitch::addFrame(std::shared_ptr svg) { +void SvgSwitch::addFrame(std::shared_ptr svg) { frames.push_back(svg); // If this is our first frame, automatically set SVG and size if (!sw->svg) { - sw->setSVG(svg); + sw->setSvg(svg); box.size = sw->box.size; fb->box.size = sw->box.size; } } -void SVGSwitch::onChange(const event::Change &e) { +void SvgSwitch::onChange(const event::Change &e) { if (!frames.empty() && paramQuantity) { int index = (int) std::round(paramQuantity->getValue()); index = math::clamp(index, 0, (int) frames.size() - 1); - sw->setSVG(frames[index]); + sw->setSvg(frames[index]); fb->dirty = true; } ParamWidget::onChange(e); diff --git a/src/ui/IconButton.cpp b/src/ui/IconButton.cpp index 136906e8..e2566662 100644 --- a/src/ui/IconButton.cpp +++ b/src/ui/IconButton.cpp @@ -12,13 +12,13 @@ IconButton::IconButton() { fw->oversample = 2; addChild(fw); - sw = new widget::SVGWidget; + sw = new widget::SvgWidget; sw->box.pos = math::Vec(2, 2); fw->addChild(sw); } -void IconButton::setSVG(std::shared_ptr svg) { - sw->setSVG(svg); +void IconButton::setSvg(std::shared_ptr svg) { + sw->setSvg(svg); fw->dirty = true; } diff --git a/src/widget/GLWidget.cpp b/src/widget/OpenGlWidget.cpp similarity index 85% rename from src/widget/GLWidget.cpp rename to src/widget/OpenGlWidget.cpp index 49a1fe55..6c799c2c 100644 --- a/src/widget/GLWidget.cpp +++ b/src/widget/OpenGlWidget.cpp @@ -1,4 +1,4 @@ -#include "widget/GLWidget.hpp" +#include "widget/OpenGlWidget.hpp" #include "app.hpp" @@ -6,13 +6,13 @@ namespace rack { namespace widget { -void GLWidget::step() { +void OpenGlWidget::step() { // Render every frame dirty = true; } -void GLWidget::drawFramebuffer() { +void OpenGlWidget::drawFramebuffer() { glViewport(0.0, 0.0, fbSize.x, fbSize.y); glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); diff --git a/src/widget/SvgWidget.cpp b/src/widget/SvgWidget.cpp new file mode 100644 index 00000000..f40f0032 --- /dev/null +++ b/src/widget/SvgWidget.cpp @@ -0,0 +1,31 @@ +#include "widget/SvgWidget.hpp" +#include "app.hpp" + + +namespace rack { +namespace widget { + + +void SvgWidget::wrap() { + if (svg && svg->handle) { + box.size = math::Vec(svg->handle->width, svg->handle->height); + } + else { + box.size = math::Vec(); + } +} + +void SvgWidget::setSvg(std::shared_ptr svg) { + this->svg = svg; + wrap(); +} + +void SvgWidget::draw(const DrawContext &ctx) { + if (svg && svg->handle) { + svgDraw(ctx.vg, svg->handle); + } +} + + +} // namespace widget +} // namespace rack diff --git a/src/window.cpp b/src/window.cpp index 5e147dee..908e9f2d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -23,13 +23,8 @@ namespace rack { -static std::map> fontCache; -static std::map> imageCache; -static std::map> svgCache; - - -Font::Font(const std::string &filename) { - handle = nvgCreateFont(APP->window->vg, filename.c_str(), filename.c_str()); +Font::Font(NVGcontext *vg, const std::string &filename) { + handle = nvgCreateFont(vg, filename.c_str(), filename.c_str()); if (handle >= 0) { INFO("Loaded font %s", filename.c_str()); } @@ -43,14 +38,11 @@ Font::~Font() { } std::shared_ptr Font::load(const std::string &filename) { - auto sp = fontCache[filename].lock(); - if (!sp) - fontCache[filename] = sp = std::make_shared(filename); - return sp; + return APP->window->loadFont(filename); } -Image::Image(const std::string &filename) { - handle = nvgCreateImage(APP->window->vg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); +Image::Image(NVGcontext *vg, const std::string &filename) { + handle = nvgCreateImage(vg, filename.c_str(), NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY); if (handle > 0) { INFO("Loaded image %s", filename.c_str()); } @@ -61,17 +53,14 @@ Image::Image(const std::string &filename) { Image::~Image() { // TODO What if handle is invalid? - nvgDeleteImage(APP->window->vg, handle); + nvgDeleteImage(vg, handle); } std::shared_ptr Image::load(const std::string &filename) { - auto sp = imageCache[filename].lock(); - if (!sp) - imageCache[filename] = sp = std::make_shared(filename); - return sp; + return APP->window->loadImage(filename); } -SVG::SVG(const std::string &filename) { +Svg::Svg(const std::string &filename) { handle = nsvgParseFromFile(filename.c_str(), "px", app::SVG_DPI); if (handle) { INFO("Loaded SVG %s", filename.c_str()); @@ -81,15 +70,12 @@ SVG::SVG(const std::string &filename) { } } -SVG::~SVG() { +Svg::~Svg() { nsvgDelete(handle); } -std::shared_ptr SVG::load(const std::string &filename) { - auto sp = svgCache[filename].lock(); - if (!sp) - svgCache[filename] = sp = std::make_shared(filename); - return sp; +std::shared_ptr Svg::load(const std::string &filename) { + return APP->window->loadSvg(filename); } @@ -100,6 +86,10 @@ struct Window::Internal { int lastWindowY = 0; int lastWindowWidth = 0; int lastWindowHeight = 0; + + std::map> fontCache; + std::map> imageCache; + std::map> svgCache; }; @@ -316,7 +306,7 @@ Window::~Window() { } void Window::run() { - uiFont = Font::load(asset::system("res/fonts/DejaVuSans.ttf")); + uiFont = APP->window->loadFont(asset::system("res/fonts/DejaVuSans.ttf")); frame = 0; while(!glfwWindowShouldClose(win)) { @@ -460,6 +450,29 @@ bool Window::isFullScreen() { return monitor != NULL; } +std::shared_ptr Window::loadFont(const std::string &filename) { + auto sp = internal->fontCache[filename].lock(); + if (!sp) + internal->fontCache[filename] = sp = std::make_shared(vg, filename); + return sp; +} + +std::shared_ptr Window::loadImage(const std::string &filename) { + auto sp = internal->imageCache[filename].lock(); + if (!sp) + internal->imageCache[filename] = sp = std::make_shared(vg, filename); + return sp; +} + +std::shared_ptr Window::loadSvg(const std::string &filename) { + auto sp = internal->svgCache[filename].lock(); + if (!sp) + internal->svgCache[filename] = sp = std::make_shared(filename); + return sp; +} + + + void windowInit() { int err;