From c5549682eba13cfb6a68513a719197a8c5880611 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 28 May 2021 14:14:33 -0400 Subject: [PATCH] Add new Light graphics. Add TSvgLight class to handle SVG files above light. --- include/componentlibrary.hpp | 107 ++++++++++++++++----------- res/ComponentLibrary/LargeLight.svg | 98 ++++++++++++++++++++++++ res/ComponentLibrary/MediumLight.svg | 98 ++++++++++++++++++++++++ res/ComponentLibrary/SmallLight.svg | 98 ++++++++++++++++++++++++ res/ComponentLibrary/TinyLight.svg | 98 ++++++++++++++++++++++++ src/app/LightWidget.cpp | 1 + src/app/ModuleLightWidget.cpp | 2 + 7 files changed, 460 insertions(+), 42 deletions(-) create mode 100644 res/ComponentLibrary/LargeLight.svg create mode 100644 res/ComponentLibrary/MediumLight.svg create mode 100644 res/ComponentLibrary/SmallLight.svg create mode 100644 res/ComponentLibrary/TinyLight.svg diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index a8911d6a..0c8de42f 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -1,4 +1,6 @@ #pragma once +#include +#include #include #include #include @@ -51,7 +53,7 @@ Many of these classes use CRTP (https://en.wikipedia.org/wiki/Curiously_recurrin To use a red light with its default base class for example, use `RedLight` or `TRedLight<>`. (They are synonymous.) -Use the `TBase` template argument if you want a different base class. +Use the `Base` template argument if you want a different base class. E.g. `RectangleLight` Although this paradigm might seem confusing at first, it ends up being extremely simple in your plugin code and perfect for "decorating" your classes with appearance traits and behavioral properties. @@ -60,49 +62,70 @@ For example, need a slider with a green LED? Just use createLightParamCentered>(...) */ -template -struct TGrayModuleLightWidget : TBase { +template +struct TSvgLight : Base { + widget::FramebufferWidget* fb; + widget::SvgWidget* sw; + + TSvgLight() { + fb = new widget::FramebufferWidget; + this->addChild(fb); + + sw = new widget::SvgWidget; + fb->addChild(sw); + } + + void setSvg(std::shared_ptr svg) { + sw->setSvg(svg); + fb->box.size = sw->box.size; + this->box.size = sw->box.size; + } +}; +typedef TSvgLight<> SvgLight; + +template +struct TGrayModuleLightWidget : Base { TGrayModuleLightWidget() { - this->bgColor = nvgRGB(0x5a, 0x5a, 0x5a); - this->borderColor = nvgRGBA(0, 0, 0, 0x60); + this->bgColor = nvgRGBA(0xaf, 0xaf, 0xaf, 0xff); + this->borderColor = nvgRGBA(0, 0, 0, 53); } }; typedef TGrayModuleLightWidget<> GrayModuleLightWidget; -template -struct TRedLight : TBase { +template +struct TRedLight : Base { TRedLight() { this->addBaseColor(SCHEME_RED); } }; typedef TRedLight<> RedLight; -template -struct TGreenLight : TBase { +template +struct TGreenLight : Base { TGreenLight() { this->addBaseColor(SCHEME_GREEN); } }; typedef TGreenLight<> GreenLight; -template -struct TYellowLight : TBase { +template +struct TYellowLight : Base { TYellowLight() { this->addBaseColor(SCHEME_YELLOW); } }; typedef TYellowLight<> YellowLight; -template -struct TBlueLight : TBase { +template +struct TBlueLight : Base { TBlueLight() { this->addBaseColor(SCHEME_BLUE); } }; typedef TBlueLight<> BlueLight; -template -struct TWhiteLight : TBase { +template +struct TWhiteLight : Base { TWhiteLight() { this->addBaseColor(SCHEME_WHITE); } @@ -110,8 +133,8 @@ struct TWhiteLight : TBase { typedef TWhiteLight<> WhiteLight; /** Reads two adjacent lightIds, so `lightId` and `lightId + 1` must be defined */ -template -struct TGreenRedLight : TBase { +template +struct TGreenRedLight : Base { TGreenRedLight() { this->addBaseColor(SCHEME_GREEN); this->addBaseColor(SCHEME_RED); @@ -119,8 +142,8 @@ struct TGreenRedLight : TBase { }; typedef TGreenRedLight<> GreenRedLight; -template -struct TRedGreenBlueLight : TBase { +template +struct TRedGreenBlueLight : Base { TRedGreenBlueLight() { this->addBaseColor(SCHEME_RED); this->addBaseColor(SCHEME_GREEN); @@ -130,39 +153,39 @@ struct TRedGreenBlueLight : TBase { typedef TRedGreenBlueLight<> RedGreenBlueLight; /** Based on the size of 5mm LEDs */ -template -struct LargeLight : TBase { +template +struct LargeLight : TSvgLight { LargeLight() { - this->box.size = mm2px(math::Vec(5.179, 5.179)); + this->setSvg(Svg::load(asset::system("res/ComponentLibrary/LargeLight.svg"))); } }; /** Based on the size of 3mm LEDs */ -template -struct MediumLight : TBase { +template +struct MediumLight : TSvgLight { MediumLight() { - this->box.size = mm2px(math::Vec(3.176, 3.176)); + this->setSvg(Svg::load(asset::system("res/ComponentLibrary/MediumLight.svg"))); } }; /** Based on the size of 2mm LEDs */ -template -struct SmallLight : TBase { +template +struct SmallLight : TSvgLight { SmallLight() { - this->box.size = mm2px(math::Vec(2.176, 2.176)); + this->setSvg(Svg::load(asset::system("res/ComponentLibrary/SmallLight.svg"))); } }; /** Based on the size of 1mm LEDs */ -template -struct TinyLight : TBase { +template +struct TinyLight : TSvgLight { TinyLight() { - this->box.size = mm2px(math::Vec(1.088, 1.088)); + this->setSvg(Svg::load(asset::system("res/ComponentLibrary/TinyLight.svg"))); } }; -template -struct RectangleLight : TBase { +template +struct RectangleLight : Base { void drawLight(const widget::Widget::DrawArgs& args) override { nvgBeginPath(args.vg); nvgRect(args.vg, 0, 0, this->box.size.x, this->box.size.y); @@ -189,8 +212,8 @@ struct RectangleLight : TBase { }; /** A light for displaying on top of PB61303. Must add a color by subclassing or templating. */ -template -struct LEDBezelLight : TBase { +template +struct LEDBezelLight : Base { LEDBezelLight() { this->bgColor = color::BLACK_TRANSPARENT; this->box.size = mm2px(math::Vec(6.0, 6.0)); @@ -200,8 +223,8 @@ struct LEDBezelLight : TBase { /** A light to displayed over PB61303. Must add a color by subclassing or templating. Don't add this as a child of the PB61303 itself. Instead, just place it over it as a sibling in the scene graph, offset by mm2px(math::Vec(0.5, 0.5)). */ -template -struct PB61303Light : TBase { +template +struct PB61303Light : Base { PB61303Light() { this->bgColor = color::BLACK_TRANSPARENT; this->box.size = mm2px(math::Vec(9.0, 9.0)); @@ -638,8 +661,8 @@ struct LEDSliderHorizontal : app::SvgSlider { } }; -template -struct LightSlider : TBase { +template +struct LightSlider : Base { app::ModuleLightWidget* light; LightSlider() { @@ -653,11 +676,11 @@ struct LightSlider : TBase { } void step() override { - TBase::step(); + Base::step(); // Move center of light to center of handle light->box.pos = this->handle->box.pos - .plus(this->handle->box.size.div(2)) - .minus(light->box.size.div(2)); + .plus(this->handle->box.size.div(2)) + .minus(light->box.size.div(2)); } }; diff --git a/res/ComponentLibrary/LargeLight.svg b/res/ComponentLibrary/LargeLight.svg new file mode 100644 index 00000000..6c9b7759 --- /dev/null +++ b/res/ComponentLibrary/LargeLight.svg @@ -0,0 +1,98 @@ + +image/svg+xml + + + + + + + + + + + + + + diff --git a/res/ComponentLibrary/MediumLight.svg b/res/ComponentLibrary/MediumLight.svg new file mode 100644 index 00000000..520716cd --- /dev/null +++ b/res/ComponentLibrary/MediumLight.svg @@ -0,0 +1,98 @@ + +image/svg+xml + + + + + + + + + + + + + + diff --git a/res/ComponentLibrary/SmallLight.svg b/res/ComponentLibrary/SmallLight.svg new file mode 100644 index 00000000..ac3d6f39 --- /dev/null +++ b/res/ComponentLibrary/SmallLight.svg @@ -0,0 +1,98 @@ + +image/svg+xml + + + + + + + + + + + + + + diff --git a/res/ComponentLibrary/TinyLight.svg b/res/ComponentLibrary/TinyLight.svg new file mode 100644 index 00000000..24a8cfe2 --- /dev/null +++ b/res/ComponentLibrary/TinyLight.svg @@ -0,0 +1,98 @@ + +image/svg+xml + + + + + + + + + + + + + + diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index 518b78c8..5bd3ab17 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -9,6 +9,7 @@ namespace app { void LightWidget::draw(const DrawArgs& args) { drawLight(args); drawHalo(args); + TransparentWidget::draw(args); } void LightWidget::drawLight(const DrawArgs& args) { diff --git a/src/app/ModuleLightWidget.cpp b/src/app/ModuleLightWidget.cpp index ed460f91..48652f69 100644 --- a/src/app/ModuleLightWidget.cpp +++ b/src/app/ModuleLightWidget.cpp @@ -115,6 +115,8 @@ void ModuleLightWidget::step() { } setBrightnesses(brightnesses); + + MultiLightWidget::step(); }