diff --git a/include/app.hpp b/include/app.hpp index 60e527b9..968036dd 100644 --- a/include/app.hpp +++ b/include/app.hpp @@ -217,7 +217,9 @@ struct Component : OpaqueWidget { }; struct CircularShadow : TransparentWidget { - float blur = 0.0; + float blurRadius; + float opacity; + CircularShadow(); void draw(NVGcontext *vg) override; }; @@ -276,6 +278,7 @@ struct SVGKnob : Knob, FramebufferWidget { float minAngle, maxAngle; TransformWidget *tw; SVGWidget *sw; + CircularShadow *shadow; SVGKnob(); void setSVG(std::shared_ptr svg); diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index 85bbb3fd..a2b60456 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -36,31 +36,30 @@ struct RoundKnob : SVGKnob { struct RoundBlackKnob : RoundKnob { RoundBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundBlack.svg"))); - box.size = Vec(38, 38); + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundBlackKnob.svg"))); } }; -struct RoundSmallBlackKnob : RoundBlackKnob { +struct RoundSmallBlackKnob : RoundKnob { RoundSmallBlackKnob() { - box.size = Vec(28, 28); + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundSmallBlackKnob.svg"))); } }; -struct RoundLargeBlackKnob : RoundBlackKnob { +struct RoundLargeBlackKnob : RoundKnob { RoundLargeBlackKnob() { - box.size = Vec(46, 46); + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundLargeBlackKnob.svg"))); } }; -struct RoundHugeBlackKnob : RoundBlackKnob { +struct RoundHugeBlackKnob : RoundKnob { RoundHugeBlackKnob() { - box.size = Vec(56, 56); + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundHugeBlackKnob.svg"))); } }; -struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob { - RoundSmallBlackSnapKnob() { +struct RoundBlackSnapKnob : RoundBlackKnob { + RoundBlackSnapKnob() { snap = true; smooth = false; } @@ -294,7 +293,6 @@ struct SynthTechAlco : SVGKnob { struct Trimpot : SVGKnob { Trimpot() { - box.size = Vec(17, 17); minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Trimpot.svg"))); @@ -303,7 +301,6 @@ struct Trimpot : SVGKnob { struct BefacoBigKnob : SVGKnob { BefacoBigKnob() { - box.size = Vec(75, 75); minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; setSVG(SVG::load(assetGlobal("res/ComponentLibrary/BefacoBigKnob.svg"))); @@ -319,7 +316,6 @@ struct BefacoBigSnapKnob : BefacoBigKnob { struct BefacoTinyKnob : SVGKnob { BefacoTinyKnob() { - box.size = Vec(26, 26); minAngle = -0.75*M_PI; maxAngle = 0.75*M_PI; setSVG(SVG::load(assetGlobal("res/ComponentLibrary/BefacoTinyKnob.svg"))); diff --git a/include/util/math.hpp b/include/util/math.hpp index 9eb2e441..2742c1cd 100644 --- a/include/util/math.hpp +++ b/include/util/math.hpp @@ -257,6 +257,12 @@ struct Rect { r.size = size; return r; } + Rect grow(Vec delta) { + Rect r; + r.pos = pos.minus(delta); + r.size = size.plus(delta.mult(2.f)); + return r; + } }; diff --git a/res/ComponentLibrary/BefacoBigKnob.svg b/res/ComponentLibrary/BefacoBigKnob.svg index e4967eb0..912ba00b 100644 --- a/res/ComponentLibrary/BefacoBigKnob.svg +++ b/res/ComponentLibrary/BefacoBigKnob.svg @@ -9,376 +9,15 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="25.664583mm" - height="25.66571mm" - viewBox="0 0 25.664584 25.665714" + width="26.000004mm" + height="26.001146mm" + viewBox="0 0 26.000004 26.001146" version="1.1" - id="svg15246" - sodipodi:docname="BefacoBigKnob.svg" - inkscape:version="0.92.2 5c3e80d, 2017-08-06"> + id="svg113936" + inkscape:version="0.92.2 5c3e80d, 2017-08-06" + sodipodi:docname="BefacoBigKnob.svg"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + id="defs113930" /> + fit-margin-bottom="0" + inkscape:window-width="2560" + inkscape:window-height="1422" + inkscape:window-x="0" + inkscape:window-y="18" + inkscape:window-maximized="0" /> + id="metadata113933"> @@ -418,26 +56,26 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-35.482976,-90.654687)"> + transform="translate(-80.833177,-85.089003)"> + style="fill:#d4d4d4;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.2879144" + d="m 106.83318,98.089007 c 0,7.179863 -5.82014,13.001143 -13.000007,13.001143 -7.179864,0 -12.999996,-5.82128 -12.999996,-13.001143 0,-7.178735 5.820132,-13.000004 12.999996,-13.000004 7.179867,0 13.000007,5.821269 13.000007,13.000004" + id="path109718" /> + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.2879144" + d="m 103.36809,92.943667 c -0.6377,-1.189896 -1.49355,-2.244833 -2.51139,-3.115323 -1.962536,0.275543 -3.99481,-0.701791 -5.009247,-2.403411 -0.652299,-0.123713 -1.32599,-0.190069 -2.01428,-0.190069 -0.688287,0 -1.360855,0.06636 -2.014277,0.190069 -1.014438,1.70162 -3.045587,2.678954 -5.00925,2.403411 -1.017835,0.87049 -1.873689,1.925427 -2.51139,3.115323 0.726523,1.878194 0.208076,4.120774 -1.270883,5.489499 0.04838,1.363087 0.345295,2.662074 0.851391,3.850844 1.968154,0.59045 3.433609,2.43604 3.561817,4.48854 1.042568,0.76591 2.227968,1.34736 3.507834,1.7005 1.694867,-1.19327 4.074651,-1.19327 5.769516,0 1.279864,-0.35314 2.465268,-0.93459 3.508959,-1.7005 0.12709,-2.0525 1.59254,-3.89809 3.56182,-4.48854 0.50609,-1.18877 0.80302,-2.487757 0.85024,-3.850844 -1.47894,-1.368725 -1.99626,-3.611305 -1.27086,-5.489499" + id="path109720" /> + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.2879144" + d="m 94.2909,86.161932 c 0,0.253052 -0.205801,0.456617 -0.457727,0.456617 -0.251924,0 -0.456603,-0.203565 -0.456603,-0.456617 0,-0.253046 0.204679,-0.456614 0.456603,-0.456614 0.251926,0 0.457727,0.203568 0.457727,0.456614" + id="path109722" /> + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.2879144" + d="m 94.2909,98.090134 h -0.91433 v -9.861065 h 0.91433 z m 0,0" + id="path109724" /> diff --git a/res/ComponentLibrary/BefacoTinyKnob.svg b/res/ComponentLibrary/BefacoTinyKnob.svg index 3d38e4c8..b3db71a3 100644 --- a/res/ComponentLibrary/BefacoTinyKnob.svg +++ b/res/ComponentLibrary/BefacoTinyKnob.svg @@ -9,376 +9,15 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8.6999998mm" - height="8.7000618mm" - viewBox="0 0 8.7000002 8.7000631" + width="9.0000019mm" + height="9.0000801mm" + viewBox="0 0 9.0000016 9.00008" version="1.1" - id="svg15246" - sodipodi:docname="BefacoTinyKnob.svg" - inkscape:version="0.92.2 5c3e80d, 2017-08-06"> + id="svg113936" + inkscape:version="0.92.2 5c3e80d, 2017-08-06" + sodipodi:docname="BefacoTinyKnob.svg"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + id="defs113930" /> + inkscape:window-maximized="0" /> + id="metadata113933"> @@ -418,26 +56,31 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-44.329061,-94.497224)"> + transform="translate(-111.86932,-85.795053)"> + + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.28209424" + d="m 120.02026,91.143448 c -0.46281,2.022043 -2.47716,3.285957 -4.49919,2.823148 -2.02205,-0.462813 -3.28598,-2.47714 -2.82314,-4.499182 0.46281,-2.020944 2.47713,-3.285958 4.49918,-2.82315 2.02093,0.462812 3.28594,2.477141 2.82315,4.499184" + id="path109732" /> + style="fill:none;stroke:#7f7878;stroke-width:0.11481237;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" + d="m 120.02026,91.143463 c -0.46281,2.022042 -2.47715,3.285956 -4.49919,2.823145 -2.02204,-0.462811 -3.28595,-2.47714 -2.82314,-4.499183 0.46281,-2.020941 2.47714,-3.285957 4.49918,-2.823145 2.02094,0.46281 3.28596,2.47714 2.82315,4.499183 z m 0,0" + id="path109734" /> + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.28209424" + d="m 116.20648,88.009558 c -0.11239,-0.07603 -0.14328,-0.229201 -0.0672,-0.342701 0.0761,-0.113495 0.23029,-0.143251 0.34379,-0.06722 0.11356,0.07603 0.14325,0.229201 0.0672,0.342701 -0.076,0.113495 -0.23031,0.14325 -0.34379,0.06722" + id="path109736" /> + style="fill:none;stroke:#000000;stroke-width:0.46912277;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1" + d="m 116.20647,88.009571 c -0.11239,-0.07603 -0.14326,-0.229202 -0.0672,-0.3427 0.076,-0.113495 0.23032,-0.14325 0.34381,-0.06722 0.11356,0.07602 0.14325,0.229201 0.0672,0.3427 -0.076,0.113495 -0.2303,0.143251 -0.3438,0.06722 z m 0,0" + id="path109738" /> diff --git a/res/ComponentLibrary/RoundBlack.svg b/res/ComponentLibrary/RoundBlack.svg deleted file mode 100644 index 92969944..00000000 --- a/res/ComponentLibrary/RoundBlack.svg +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - diff --git a/res/ComponentLibrary/RoundBlackKnob.svg b/res/ComponentLibrary/RoundBlackKnob.svg new file mode 100644 index 00000000..0fa91ad9 --- /dev/null +++ b/res/ComponentLibrary/RoundBlackKnob.svg @@ -0,0 +1,71 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/res/ComponentLibrary/RoundHugeBlackKnob.svg b/res/ComponentLibrary/RoundHugeBlackKnob.svg new file mode 100644 index 00000000..cc3c2a7f --- /dev/null +++ b/res/ComponentLibrary/RoundHugeBlackKnob.svg @@ -0,0 +1,71 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/res/ComponentLibrary/RoundLargeBlackKnob.svg b/res/ComponentLibrary/RoundLargeBlackKnob.svg new file mode 100644 index 00000000..82e4ae7a --- /dev/null +++ b/res/ComponentLibrary/RoundLargeBlackKnob.svg @@ -0,0 +1,71 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/res/ComponentLibrary/RoundSmallBlackKnob.svg b/res/ComponentLibrary/RoundSmallBlackKnob.svg new file mode 100644 index 00000000..609d3a87 --- /dev/null +++ b/res/ComponentLibrary/RoundSmallBlackKnob.svg @@ -0,0 +1,71 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/res/ComponentLibrary/Trimpot.svg b/res/ComponentLibrary/Trimpot.svg index 6191a6d0..f8ff0922 100644 --- a/res/ComponentLibrary/Trimpot.svg +++ b/res/ComponentLibrary/Trimpot.svg @@ -9,376 +9,15 @@ xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="6.2990241mm" - height="6.3003879mm" - viewBox="0 0 6.2990242 6.3003887" + width="6.2990298mm" + height="6.3003922mm" + viewBox="0 0 6.2990294 6.3003921" version="1.1" - id="svg15246" - sodipodi:docname="Trimpot.svg" - inkscape:version="0.92.2 5c3e80d, 2017-08-06"> + id="svg111794" + inkscape:version="0.92.2 5c3e80d, 2017-08-06" + sodipodi:docname="Trimpot.svg"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + id="defs111788" /> + fit-margin-bottom="0" + inkscape:window-width="2560" + inkscape:window-height="1422" + inkscape:window-x="0" + inkscape:window-y="18" + inkscape:window-maximized="0" /> + id="metadata111791"> @@ -418,16 +56,16 @@ inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" - transform="translate(-46.318588,-97.647662)"> + transform="translate(-183.93691,-77.348595)"> + style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277775" + d="m 183.93691,80.498791 c 0,1.740461 1.40974,3.150196 3.1502,3.150196 1.73909,0 3.14883,-1.409735 3.14883,-3.150196 0,-1.739085 -1.40974,-3.150196 -3.14883,-3.150196 -1.74046,0 -3.1502,1.411111 -3.1502,3.150196" + id="path108214" /> + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.35277775" + d="m 187.29109,77.359619 c -0.0675,-0.0055 -0.13508,-0.01101 -0.20398,-0.01101 -0.0689,0 -0.13779,0.0055 -0.20531,0.01101 v 3.139172 h 0.40929 z m 0,0" + id="path108216" /> diff --git a/src/app/CircularShadow.cpp b/src/app/CircularShadow.cpp index 3d3ec3fe..2e00f08d 100644 --- a/src/app/CircularShadow.cpp +++ b/src/app/CircularShadow.cpp @@ -4,15 +4,24 @@ namespace rack { +CircularShadow::CircularShadow() { + blurRadius = 0; + opacity = 0.15; + // blurRadius = 0; + // opacity = 0.15; +} + void CircularShadow::draw(NVGcontext *vg) { + if (opacity < 0.0) + return; + nvgBeginPath(vg); - nvgRect(vg, -blur, -blur, box.size.x + 2*blur, box.size.y + 2*blur); - nvgFillColor(vg, nvgRGBAf(0.0, 0.0, 0.0, 0.25)); - Vec c = box.size.div(2.0); - float radius = c.x; - NVGcolor icol = nvgRGBAf(0.0, 0.0, 0.0, 0.25); + nvgRect(vg, -blurRadius, -blurRadius, box.size.x + 2*blurRadius, box.size.y + 2*blurRadius); + Vec center = box.size.div(2.0); + float radius = center.x; + NVGcolor icol = nvgRGBAf(0.0, 0.0, 0.0, opacity); NVGcolor ocol = nvgRGBAf(0.0, 0.0, 0.0, 0.0); - NVGpaint paint = nvgRadialGradient(vg, c.x, c.y, radius - blur/2, radius + blur/2, icol, ocol); + NVGpaint paint = nvgRadialGradient(vg, center.x, center.y, radius - blurRadius, radius, icol, ocol); nvgFillPaint(vg, paint); nvgFill(vg); } diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index 0d0f56f9..5a53b943 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -5,6 +5,9 @@ namespace rack { SVGKnob::SVGKnob() { + shadow = new CircularShadow(); + addChild(shadow); + tw = new TransformWidget(); addChild(tw); @@ -13,22 +16,21 @@ SVGKnob::SVGKnob() { } void SVGKnob::setSVG(std::shared_ptr svg) { - sw->svg = svg; - sw->wrap(); + sw->setSVG(svg); tw->box.size = sw->box.size; box.size = sw->box.size; + shadow->box.size = sw->box.size; + shadow->box.pos = Vec(0, 4); + // shadow->box = shadow->box.grow(Vec(2, 2)); } void SVGKnob::step() { // Re-transform TransformWidget if dirty if (dirty) { - tw->box.size = box.size; float angle = 0.0; if (isfinite(minValue) && isfinite(maxValue)) angle = rescale(value, minValue, maxValue, minAngle, maxAngle); tw->identity(); - // Scale SVG to box - tw->scale(box.size.div(sw->box.size)); // Rotate SVG Vec center = sw->box.getCenter(); tw->translate(center); @@ -44,5 +46,4 @@ void SVGKnob::onChange(EventChange &e) { } - } // namespace rack