@@ -145,7 +145,6 @@ struct SVGKnob : Knob, FramebufferWidget { | |||
/** Not owned */ | |||
TransformWidget *tw; | |||
SVGWidget *sw; | |||
CircularShadow *shadow; | |||
SVGKnob(); | |||
void setSVG(std::shared_ptr<SVG> svg); | |||
@@ -5,21 +5,6 @@ | |||
namespace rack { | |||
enum ColorNames { | |||
COLOR_BLACK, | |||
COLOR_WHITE, | |||
COLOR_RED, | |||
COLOR_ORANGE, | |||
COLOR_YELLOW, | |||
COLOR_GREEN, | |||
COLOR_CYAN, | |||
COLOR_BLUE, | |||
COLOR_PURPLE, | |||
NUM_COLORS | |||
}; | |||
extern const NVGcolor colors[NUM_COLORS]; | |||
//////////////////// | |||
// Knobs | |||
//////////////////// | |||
@@ -286,6 +271,24 @@ struct Davies1900hRedKnob : Davies1900hKnob { | |||
} | |||
}; | |||
struct Davies1900hLargeWhiteKnob : Davies1900hKnob { | |||
Davies1900hLargeWhiteKnob() { | |||
setSVG(SVG::load("res/ComponentLibrary/Davies1900hLargeWhite.svg")); | |||
} | |||
}; | |||
struct Davies1900hLargeBlackKnob : Davies1900hKnob { | |||
Davies1900hLargeBlackKnob() { | |||
setSVG(SVG::load("res/ComponentLibrary/Davies1900hLargeBlack.svg")); | |||
} | |||
}; | |||
struct Davies1900hLargeRedKnob : Davies1900hKnob { | |||
Davies1900hLargeRedKnob() { | |||
setSVG(SVG::load("res/ComponentLibrary/Davies1900hLargeRed.svg")); | |||
} | |||
}; | |||
struct Trimpot : SVGKnob { | |||
Trimpot() { | |||
box.size = Vec(17, 17); | |||
@@ -366,30 +369,49 @@ struct ValueLight : Light { | |||
float *value; | |||
}; | |||
template <int COLOR> | |||
struct ColorValueLight : ValueLight { | |||
NVGcolor baseColor; | |||
void step() { | |||
float v = sqrtBipolar(getf(value)); | |||
color = nvgLerpRGBA(colors[COLOR_BLACK], colors[COLOR], v); | |||
color = baseColor; | |||
color.a = clampf(v, 0.0, 1.0); | |||
} | |||
}; | |||
struct RedValueLight : ColorValueLight { | |||
RedValueLight() { | |||
baseColor = nvgRGB(0xed, 0x2c, 0x24); | |||
} | |||
}; | |||
typedef ColorValueLight<COLOR_RED> RedValueLight; | |||
typedef ColorValueLight<COLOR_YELLOW> YellowValueLight; | |||
typedef ColorValueLight<COLOR_GREEN> GreenValueLight; | |||
struct YellowValueLight : ColorValueLight { | |||
YellowValueLight() { | |||
baseColor = nvgRGB(0xf9, 0xdf, 0x1c); | |||
} | |||
}; | |||
struct GreenValueLight : ColorValueLight { | |||
GreenValueLight() { | |||
baseColor = nvgRGB(0x90, 0xc7, 0x3e); | |||
} | |||
}; | |||
template <int COLOR_POS, int COLOR_NEG> | |||
struct PolarityLight : ValueLight { | |||
NVGcolor posColor; | |||
NVGcolor negColor; | |||
void step() { | |||
float v = sqrtBipolar(getf(value)); | |||
if (v >= 0.0) | |||
color = nvgLerpRGBA(colors[COLOR_BLACK], colors[COLOR_POS], v); | |||
else | |||
color = nvgLerpRGBA(colors[COLOR_BLACK], colors[COLOR_NEG], -v); | |||
color = (v >= 0.0) ? posColor : negColor; | |||
color.a = clampf(fabsf(v), 0.0, 1.0); | |||
} | |||
}; | |||
typedef PolarityLight<COLOR_GREEN, COLOR_RED> GreenRedPolarityLight; | |||
struct GreenRedPolarityLight : PolarityLight { | |||
GreenRedPolarityLight() { | |||
posColor = nvgRGB(0x90, 0xc7, 0x3e); | |||
negColor = nvgRGB(0xed, 0x2c, 0x24); | |||
} | |||
}; | |||
template <typename BASE> | |||
struct LargeLight : BASE { | |||
@@ -418,9 +440,9 @@ struct SmallLight : BASE { | |||
struct NKK : SVGSwitch, ToggleSwitch { | |||
NKK() { | |||
addFrame(SVG::load("res/ComponentLibrary/NKK0.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/NKK1.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/NKK2.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/NKK_0.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/NKK_1.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/NKK_2.svg")); | |||
sw->wrap(); | |||
box.size = sw->box.size; | |||
} | |||
@@ -428,8 +450,8 @@ struct NKK : SVGSwitch, ToggleSwitch { | |||
struct CKSS : SVGSwitch, ToggleSwitch { | |||
CKSS() { | |||
addFrame(SVG::load("res/ComponentLibrary/CKSS0.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/CKSS1.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/CKSS_0.svg")); | |||
addFrame(SVG::load("res/ComponentLibrary/CKSS_1.svg")); | |||
sw->wrap(); | |||
box.size = sw->box.size; | |||
} | |||
@@ -5,32 +5,36 @@ namespace rack { | |||
void Light::draw(NVGcontext *vg) { | |||
NVGcolor colorOutline = nvgLerpRGBA(color, nvgRGBf(0.0, 0.0, 0.0), 0.5); | |||
NVGcolor bgColor = nvgRGBf(0.0, 0.0, 0.0); | |||
float radius = box.size.x / 2.0; | |||
float oradius = radius + 30.0; | |||
// Solid | |||
nvgBeginPath(vg); | |||
nvgCircle(vg, radius, radius, radius); | |||
nvgFillColor(vg, color); | |||
nvgFillColor(vg, bgColor); | |||
nvgFill(vg); | |||
// Border | |||
nvgStrokeWidth(vg, 1.0); | |||
nvgStrokeColor(vg, colorOutline); | |||
nvgStrokeColor(vg, nvgTransRGBAf(bgColor, 0.5)); | |||
nvgStroke(vg); | |||
// Glow | |||
// Inner glow | |||
nvgGlobalCompositeOperation(vg, NVG_LIGHTER); | |||
nvgFillColor(vg, color); | |||
nvgFill(vg); | |||
// Outer glow | |||
nvgBeginPath(vg); | |||
nvgRect(vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius); | |||
NVGpaint paint; | |||
NVGcolor icol = color; | |||
icol.a = 0.1; | |||
icol.a *= 0.1; | |||
NVGcolor ocol = color; | |||
ocol.a = 0.0; | |||
float oradius = radius + 30.0; | |||
paint = nvgRadialGradient(vg, radius, radius, radius, oradius, icol, ocol); | |||
nvgFillPaint(vg, paint); | |||
nvgBeginPath(vg); | |||
nvgRect(vg, radius - oradius, radius - oradius, 2*oradius, 2*oradius); | |||
nvgFill(vg); | |||
} | |||
@@ -7,12 +7,6 @@ namespace rack { | |||
SVGKnob::SVGKnob() { | |||
padding = Vec(1, 1); | |||
shadow = new CircularShadow(); | |||
shadow->blur = 5.0; | |||
shadow->box.pos = Vec(0, 1); | |||
// TODO Remove shadow entirely | |||
// addChild(shadow); | |||
tw = new TransformWidget(); | |||
addChild(tw); | |||
@@ -23,31 +17,27 @@ SVGKnob::SVGKnob() { | |||
void SVGKnob::setSVG(std::shared_ptr<SVG> svg) { | |||
sw->svg = svg; | |||
sw->wrap(); | |||
tw->box.size = sw->box.size; | |||
box.size = sw->box.size; | |||
} | |||
void SVGKnob::step() { | |||
// Re-transform TransformWidget if dirty | |||
if (dirty) { | |||
float angle = mapf(value, minValue, maxValue, minAngle, maxAngle); | |||
tw->box.size = box.size; | |||
tw->identity(); | |||
// Resize SVG | |||
Vec scale = Vec(box.size.x / sw->box.size.x, box.size.y / sw->box.size.y); | |||
tw->scale(scale); | |||
// Rotate SVG | |||
Vec center = sw->box.getCenter(); | |||
tw->translate(center); | |||
tw->rotate(angle); | |||
tw->translate(center.neg()); | |||
// Resize shadow | |||
shadow->box.size = box.size; | |||
} | |||
FramebufferWidget::step(); | |||
} | |||
void SVGKnob::onChange() { | |||
dirty = true; | |||
ParamWidget::onChange(); | |||
Knob::onChange(); | |||
} | |||
@@ -28,6 +28,7 @@ void SVGSwitch::onChange() { | |||
if (0 <= index && index < (int)frames.size()) | |||
sw->svg = frames[index]; | |||
dirty = true; | |||
ParamWidget::onChange(); | |||
} | |||
@@ -1,19 +0,0 @@ | |||
#include "components.hpp" | |||
namespace rack { | |||
const NVGcolor colors[NUM_COLORS] = { | |||
nvgRGB(0x00, 0x00, 0x00), | |||
nvgRGB(0xff, 0xff, 0xff), | |||
nvgRGB(0xed, 0x2c, 0x24), | |||
nvgRGB(0xf2, 0xb1, 0x20), | |||
nvgRGB(0xf9, 0xdf, 0x1c), | |||
nvgRGB(0x90, 0xc7, 0x3e), | |||
nvgRGB(0x22, 0xe6, 0xef), | |||
nvgRGB(0x29, 0xb2, 0xef), | |||
nvgRGB(0xd5, 0x2b, 0xed), | |||
}; | |||
} // namespace rack |
@@ -112,7 +112,7 @@ static void drawSVG(NVGcontext *vg, NSVGimage *svg) { | |||
void SVGWidget::wrap() { | |||
if (svg) { | |||
if (svg && svg->handle) { | |||
box.size = Vec(svg->handle->width, svg->handle->height); | |||
} | |||
else { | |||