Browse Source

Rename SVGSlider to SVGFader, refactor LightWidget

tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
199f99b0bf
5 changed files with 36 additions and 26 deletions
  1. +6
    -5
      include/app.hpp
  2. +1
    -1
      include/components.hpp
  3. +26
    -12
      src/app/LightWidget.cpp
  4. +3
    -3
      src/app/SVGFader.cpp
  5. +0
    -5
      src/app/WireWidget.cpp

+ 6
- 5
include/app.hpp View File

@@ -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 */


+ 1
- 1
include/components.hpp View File

@@ -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);


+ 26
- 12
src/app/LightWidget.cpp View File

@@ -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

src/app/SVGSlider.cpp → src/app/SVGFader.cpp View File

@@ -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);
}

+ 0
- 5
src/app/WireWidget.cpp View File

@@ -86,11 +86,6 @@ static int lastWireColorId = -1;
WireWidget::WireWidget() {
lastWireColorId = (lastWireColorId + 1) % LENGTHOF(wireColors);
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() {


Loading…
Cancel
Save