diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index c5071dae..888fa3fd 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -635,6 +635,20 @@ struct CL1362Port : app::SvgPort { // Switches //////////////////// +template +struct LatchingSwitch : TSwitch { + LatchingSwitch() { + this->momentary = false; + } +}; + +template +struct MomentarySwitch : TSwitch { + MomentarySwitch() { + this->momentary = true; + } +}; + struct NKK : app::SvgSwitch { NKK() { addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/NKK_0.svg"))); @@ -745,6 +759,46 @@ struct ScrewBlack : app::SvgScrew { } }; +struct SegmentDisplay : widget::Widget { + int lightsLen = 0; + bool vertical = false; + float margin = app::mm2px(0.5); + + void draw(const DrawArgs& args) override { + // Background + nvgBeginPath(args.vg); + nvgRect(args.vg, 0, 0, box.size.x, box.size.y); + nvgFillColor(args.vg, color::BLACK); + nvgFill(args.vg); + Widget::draw(args); + } + + template + void setLights(engine::Module* module, int firstLightId, int lightsLen) { + clearChildren(); + this->lightsLen = lightsLen; + float r = (vertical ? box.size.y : box.size.x) - margin; + for (int i = 0; i < lightsLen; i++) { + float p = float(i) / lightsLen; + app::ModuleLightWidget* light = new RectangleLight; + if (vertical) { + light->box.pos.y = p * r + margin; + light->box.size.y = r / lightsLen - margin; + light->box.size.x = box.size.x; + } + else { + light->box.pos.x = p * r + margin; + light->box.size.x = r / lightsLen - margin; + light->box.size.y = box.size.y; + } + light->module = module; + light->firstLightId = firstLightId; + firstLightId += light->baseColors.size(); + addChild(light); + } + } +}; + } // namespace componentlibrary } // namespace rack diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index 2cf46933..3df6dce8 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -12,7 +12,7 @@ void LightWidget::draw(const DrawArgs& args) { } void LightWidget::drawLight(const DrawArgs& args) { - float radius = box.size.x / 2.0; + float radius = std::min(box.size.x, box.size.y) / 2.0; nvgBeginPath(args.vg); nvgCircle(args.vg, radius, radius, radius); @@ -38,7 +38,7 @@ void LightWidget::drawLight(const DrawArgs& args) { } void LightWidget::drawHalo(const DrawArgs& args) { - float radius = box.size.x / 2.0; + float radius = std::min(box.size.x, box.size.y) / 2.0; float oradius = 4.0 * radius; nvgBeginPath(args.vg);