diff --git a/include/app.hpp b/include/app.hpp index 88d74b86..9cea300e 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -74,14 +74,11 @@ struct ModuleWidget : OpaqueWidget { void onDragMove(EventDragMove &e) override; }; -struct ValueLight; struct WireWidget : OpaqueWidget { Port *outputPort = NULL; Port *inputPort = NULL; Port *hoveredOutputPort = NULL; Port *hoveredInputPort = NULL; - ValueLight *inputLight; - ValueLight *outputLight; Wire *wire = NULL; NVGcolor color; @@ -227,14 +224,14 @@ struct SVGKnob : virtual Knob, FramebufferWidget { void onChange(EventChange &e) override; }; -struct SVGSlider : Knob, FramebufferWidget { +struct SVGFader : Knob, FramebufferWidget { /** Intermediate positions will be interpolated between these positions */ Vec minHandlePos, maxHandlePos; /** Not owned */ SVGWidget *background; SVGWidget *handle; - SVGSlider(); + SVGFader(); void step() override; void onChange(EventChange &e) override; }; @@ -271,6 +268,8 @@ struct MomentarySwitch : virtual Switch { void randomize() override {} void onDragStart(EventDragStart &e) override { setValue(maxValue); + EventAction eAction; + onAction(eAction); } void onDragEnd(EventDragEnd &e) override { setValue(minValue); @@ -285,6 +284,8 @@ struct LightWidget : TransparentWidget { NVGcolor bgColor = nvgRGBf(0, 0, 0); NVGcolor color = nvgRGBf(1, 1, 1); void draw(NVGcontext *vg) override; + virtual void drawLight(NVGcontext *vg); + virtual void drawHalo(NVGcontext *vg); }; /** Mixes a list of colors based on a list of brightness values */ diff --git a/include/components.hpp b/include/components.hpp index c300e44b..03854062 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -322,7 +322,7 @@ struct BefacoTinyKnob : SVGKnob { } }; -struct BefacoSlidePot : SVGSlider { +struct BefacoSlidePot : SVGFader { BefacoSlidePot() { Vec margin = Vec(3.5, 3.5); maxHandlePos = Vec(-1, -2).plus(margin); diff --git a/src/app/LightWidget.cpp b/src/app/LightWidget.cpp index a75bf23c..70f3a00d 100644 --- a/src/app/LightWidget.cpp +++ b/src/app/LightWidget.cpp @@ -5,35 +5,46 @@ namespace rack { void LightWidget::draw(NVGcontext *vg) { - float radius = box.size.x / 2.0; - float oradius = radius + 15.0; - color.r = clampf(color.r, 0.0, 1.0); color.g = clampf(color.g, 0.0, 1.0); color.b = clampf(color.b, 0.0, 1.0); color.a = clampf(color.a, 0.0, 1.0); - // Solid + drawLight(vg); + drawHalo(vg); +} + + +void LightWidget::drawLight(NVGcontext *vg) { + float radius = box.size.x / 2.0; + nvgBeginPath(vg); nvgCircle(vg, radius, radius, radius); + + // Background nvgFillColor(vg, bgColor); nvgFill(vg); - // Border - nvgStrokeWidth(vg, 1.0); - NVGcolor borderColor = bgColor; - borderColor.a *= 0.5; - nvgStrokeColor(vg, borderColor); - nvgStroke(vg); + // // Border + // nvgStrokeWidth(vg, 1.0); + // NVGcolor borderColor = bgColor; + // borderColor.a *= 0.5; + // nvgStrokeColor(vg, borderColor); + // nvgStroke(vg); // Inner glow - nvgGlobalCompositeOperation(vg, NVG_LIGHTER); nvgFillColor(vg, color); nvgFill(vg); +} + + +void LightWidget::drawHalo(NVGcontext *vg) { + float radius = box.size.x / 2.0; + float oradius = radius + 15.0; - // Outer glow nvgBeginPath(vg); nvgRect(vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius); + NVGpaint paint; NVGcolor icol = color; icol.a *= 0.10; @@ -41,8 +52,11 @@ void LightWidget::draw(NVGcontext *vg) { ocol.a = 0.0; paint = nvgRadialGradient(vg, radius, radius, radius, oradius, icol, ocol); nvgFillPaint(vg, paint); + nvgGlobalCompositeOperation(vg, NVG_LIGHTER); nvgFill(vg); } + + } // namespace rack diff --git a/src/app/SVGSlider.cpp b/src/app/SVGFader.cpp similarity index 83% rename from src/app/SVGSlider.cpp rename to src/app/SVGFader.cpp index b65bcd30..ee170ea1 100644 --- a/src/app/SVGSlider.cpp +++ b/src/app/SVGFader.cpp @@ -4,7 +4,7 @@ namespace rack { -SVGSlider::SVGSlider() { +SVGFader::SVGFader() { background = new SVGWidget(); addChild(background); @@ -12,7 +12,7 @@ SVGSlider::SVGSlider() { addChild(handle); } -void SVGSlider::step() { +void SVGFader::step() { if (dirty) { // Update handle position Vec handlePos = Vec(rescalef(value, minValue, maxValue, minHandlePos.x, maxHandlePos.x), rescalef(value, minValue, maxValue, minHandlePos.y, maxHandlePos.y)); @@ -21,7 +21,7 @@ void SVGSlider::step() { FramebufferWidget::step(); } -void SVGSlider::onChange(EventChange &e) { +void SVGFader::onChange(EventChange &e) { dirty = true; Knob::onChange(e); } diff --git a/src/app/WireWidget.cpp b/src/app/WireWidget.cpp index 07d16226..75b73516 100644 --- a/src/app/WireWidget.cpp +++ b/src/app/WireWidget.cpp @@ -86,11 +86,6 @@ static int lastWireColorId = -1; WireWidget::WireWidget() { lastWireColorId = (lastWireColorId + 1) % LENGTHOF(wireColors); color = wireColors[lastWireColorId]; - - // inputLight = construct(&PolarityLight::posColor, COLOR_GREEN, &PolarityLight::negColor, COLOR_RED); - // outputLight = construct(&PolarityLight::posColor, COLOR_GREEN, &PolarityLight::negColor, COLOR_RED); - // addChild(inputLight); - // addChild(outputLight); } WireWidget::~WireWidget() {