| @@ -66,11 +66,14 @@ struct ModuleWidget : OpaqueWidget { | |||||
| void onMouseDownOpaque(int button); | void onMouseDownOpaque(int button); | ||||
| }; | }; | ||||
| struct ValueLight; | |||||
| struct WireWidget : OpaqueWidget { | struct WireWidget : OpaqueWidget { | ||||
| Port *inputPort = NULL; | |||||
| Port *outputPort = NULL; | Port *outputPort = NULL; | ||||
| Port *hoveredInputPort = NULL; | |||||
| Port *inputPort = NULL; | |||||
| Port *hoveredOutputPort = NULL; | Port *hoveredOutputPort = NULL; | ||||
| Port *hoveredInputPort = NULL; | |||||
| ValueLight *inputLight; | |||||
| ValueLight *outputLight; | |||||
| Wire *wire = NULL; | Wire *wire = NULL; | ||||
| NVGcolor color; | NVGcolor color; | ||||
| @@ -389,13 +389,18 @@ struct CL1362Port : SVGPort { | |||||
| //////////////////// | //////////////////// | ||||
| struct ValueLight : Light { | struct ValueLight : Light { | ||||
| float *value; | |||||
| float *value = NULL; | |||||
| virtual void setValue(float v) {} | |||||
| void step() { | |||||
| if (value) | |||||
| setValue(*value); | |||||
| } | |||||
| }; | }; | ||||
| struct ColorValueLight : ValueLight { | struct ColorValueLight : ValueLight { | ||||
| NVGcolor baseColor; | NVGcolor baseColor; | ||||
| void step() { | |||||
| float v = sqrtBipolar(getf(value)); | |||||
| void setValue(float v) { | |||||
| v = sqrtBipolar(v); | |||||
| color = baseColor; | color = baseColor; | ||||
| color.a = clampf(v, 0.0, 1.0); | color.a = clampf(v, 0.0, 1.0); | ||||
| } | } | ||||
| @@ -422,8 +427,8 @@ struct GreenValueLight : ColorValueLight { | |||||
| struct PolarityLight : ValueLight { | struct PolarityLight : ValueLight { | ||||
| NVGcolor posColor; | NVGcolor posColor; | ||||
| NVGcolor negColor; | NVGcolor negColor; | ||||
| void step() { | |||||
| float v = sqrtBipolar(getf(value)); | |||||
| void setValue(float v) { | |||||
| v = sqrtBipolar(v); | |||||
| color = (v >= 0.0) ? posColor : negColor; | color = (v >= 0.0) ? posColor : negColor; | ||||
| color.a = clampf(fabsf(v), 0.0, 1.0); | color.a = clampf(fabsf(v), 0.0, 1.0); | ||||
| } | } | ||||
| @@ -438,8 +443,8 @@ struct GreenRedPolarityLight : PolarityLight { | |||||
| struct ModeValueLight : ValueLight { | struct ModeValueLight : ValueLight { | ||||
| std::vector<NVGcolor> colors; | std::vector<NVGcolor> 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]; | color = colors[mode]; | ||||
| } | } | ||||
| void addColor(NVGcolor color) { | void addColor(NVGcolor color) { | ||||
| @@ -1,5 +1,6 @@ | |||||
| #include "app.hpp" | #include "app.hpp" | ||||
| #include "engine.hpp" | #include "engine.hpp" | ||||
| #include "components.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -84,6 +85,17 @@ static int lastWireColorId = -1; | |||||
| WireWidget::WireWidget() { | WireWidget::WireWidget() { | ||||
| lastWireColorId = (lastWireColorId + 1) % 6; | lastWireColorId = (lastWireColorId + 1) % 6; | ||||
| color = wireColors[lastWireColorId]; | color = wireColors[lastWireColorId]; | ||||
| PolarityLight *inputPolarityLight = new MediumLight<PolarityLight>(); | |||||
| PolarityLight *outputPolarityLight = new MediumLight<PolarityLight>(); | |||||
| outputPolarityLight->posColor = inputPolarityLight->posColor = COLOR_GREEN; | |||||
| outputPolarityLight->negColor = inputPolarityLight->negColor = COLOR_RED; | |||||
| inputLight = inputPolarityLight; | |||||
| outputLight = outputPolarityLight; | |||||
| addChild(inputLight); | |||||
| addChild(outputLight); | |||||
| } | } | ||||
| WireWidget::~WireWidget() { | WireWidget::~WireWidget() { | ||||
| @@ -157,8 +169,27 @@ void WireWidget::draw(NVGcontext *vg) { | |||||
| void WireWidget::drawPlugs(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. | // 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); | 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); | |||||
| */ | |||||
| } | } | ||||