From 45e7c5f0b0c95312e3194fd8d068ca71d9a9dd6c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 2 Oct 2017 01:29:49 -0400 Subject: [PATCH] Added plug lights (but commented out) --- include/app.hpp | 7 +++++-- include/components.hpp | 19 ++++++++++++------- src/app/WireWidget.cpp | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/include/app.hpp b/include/app.hpp index 08c1b4f0..845cd51a 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -66,11 +66,14 @@ struct ModuleWidget : OpaqueWidget { void onMouseDownOpaque(int button); }; +struct ValueLight; struct WireWidget : OpaqueWidget { - Port *inputPort = NULL; Port *outputPort = NULL; - Port *hoveredInputPort = NULL; + Port *inputPort = NULL; Port *hoveredOutputPort = NULL; + Port *hoveredInputPort = NULL; + ValueLight *inputLight; + ValueLight *outputLight; Wire *wire = NULL; NVGcolor color; diff --git a/include/components.hpp b/include/components.hpp index adb7bbf1..571d56dc 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -389,13 +389,18 @@ struct CL1362Port : SVGPort { //////////////////// struct ValueLight : Light { - float *value; + float *value = NULL; + virtual void setValue(float v) {} + void step() { + if (value) + setValue(*value); + } }; struct ColorValueLight : ValueLight { NVGcolor baseColor; - void step() { - float v = sqrtBipolar(getf(value)); + void setValue(float v) { + v = sqrtBipolar(v); color = baseColor; color.a = clampf(v, 0.0, 1.0); } @@ -422,8 +427,8 @@ struct GreenValueLight : ColorValueLight { struct PolarityLight : ValueLight { NVGcolor posColor; NVGcolor negColor; - void step() { - float v = sqrtBipolar(getf(value)); + void setValue(float v) { + v = sqrtBipolar(v); color = (v >= 0.0) ? posColor : negColor; color.a = clampf(fabsf(v), 0.0, 1.0); } @@ -438,8 +443,8 @@ struct GreenRedPolarityLight : PolarityLight { struct ModeValueLight : ValueLight { std::vector colors; - void step() { - int mode = clampi((int)roundf(getf(value)), 0, colors.size()); + void setValue(float v) { + int mode = clampi((int)roundf(v), 0, colors.size()); color = colors[mode]; } void addColor(NVGcolor color) { diff --git a/src/app/WireWidget.cpp b/src/app/WireWidget.cpp index eba4fac1..86508434 100644 --- a/src/app/WireWidget.cpp +++ b/src/app/WireWidget.cpp @@ -1,5 +1,6 @@ #include "app.hpp" #include "engine.hpp" +#include "components.hpp" namespace rack { @@ -84,6 +85,17 @@ static int lastWireColorId = -1; WireWidget::WireWidget() { lastWireColorId = (lastWireColorId + 1) % 6; color = wireColors[lastWireColorId]; + + PolarityLight *inputPolarityLight = new MediumLight(); + PolarityLight *outputPolarityLight = new MediumLight(); + outputPolarityLight->posColor = inputPolarityLight->posColor = COLOR_GREEN; + outputPolarityLight->negColor = inputPolarityLight->negColor = COLOR_RED; + + inputLight = inputPolarityLight; + outputLight = outputPolarityLight; + addChild(inputLight); + addChild(outputLight); + } WireWidget::~WireWidget() { @@ -157,8 +169,27 @@ void WireWidget::draw(NVGcontext *vg) { void WireWidget::drawPlugs(NVGcontext *vg) { // TODO Figure out a way to draw plugs first and wires last, and cut the plug portion of the wire off. - drawPlug(vg, getOutputPos(), color); + Vec outputPos = getOutputPos(); + Vec inputPos = getInputPos(); + drawPlug(vg, outputPos, color); drawPlug(vg, getInputPos(), color); + + // Draw plug light + /* + if (wire) { + Output &output = wire->outputModule->outputs[wire->outputId]; + float value = output.value / 10.0; + outputLight->box.pos = outputPos.minus(Vec(6, 6)); + inputLight->box.pos = inputPos.minus(Vec(6, 6)); + outputLight->setValue(value); + inputLight->setValue(value); + } + else { + outputLight->setValue(0.0); + inputLight->setValue(0.0); + } + Widget::draw(vg); + */ }