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