From 3d044ab411eef8b157554aa02e009bc8ecf17480 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 7 Oct 2017 06:29:24 -0400 Subject: [PATCH] Add RoundBlackKnob --- include/components.hpp | 139 +++++++++++++++++----------- include/math.hpp | 6 ++ res/ComponentLibrary/RoundBlack.svg | 123 ++++++++++++++++++++++++ src/app/SVGKnob.cpp | 2 + 4 files changed, 218 insertions(+), 52 deletions(-) create mode 100644 res/ComponentLibrary/RoundBlack.svg diff --git a/include/components.hpp b/include/components.hpp index ffd5a169..ef078c33 100644 --- a/include/components.hpp +++ b/include/components.hpp @@ -25,6 +25,93 @@ namespace rack { // Knobs //////////////////// +struct RoundKnob : SVGKnob { + RoundKnob() { + minAngle = -0.83*M_PI; + maxAngle = 0.83*M_PI; + } +}; + +struct RoundBlackKnob : RoundKnob { + RoundBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/RoundBlack.svg"))); + box.size = Vec(38, 38); + } +}; + +struct RoundSmallBlackKnob : RoundBlackKnob { + RoundSmallBlackKnob() { + box.size = Vec(28, 28); + } +}; + +struct RoundLargeBlackKnob : RoundBlackKnob { + RoundLargeBlackKnob() { + box.size = Vec(46, 46); + } +}; + +struct RoundHugeBlackKnob : RoundBlackKnob { + RoundHugeBlackKnob() { + box.size = Vec(56, 56); + } +}; + +struct RoundSmallBlackSnapKnob : RoundSmallBlackKnob, SnapKnob {}; + + +struct Davies1900hKnob : SVGKnob { + Davies1900hKnob() { + minAngle = -0.83*M_PI; + maxAngle = 0.83*M_PI; + } +}; + +struct Davies1900hWhiteKnob : Davies1900hKnob { + Davies1900hWhiteKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hWhite.svg"))); + } +}; + +struct Davies1900hBlackKnob : Davies1900hKnob { + Davies1900hBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hBlack.svg"))); + } +}; + +struct Davies1900hRedKnob : Davies1900hKnob { + Davies1900hRedKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hRed.svg"))); + } +}; + +struct Davies1900hLargeWhiteKnob : Davies1900hKnob { + Davies1900hLargeWhiteKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeWhite.svg"))); + } +}; + +struct Davies1900hLargeBlackKnob : Davies1900hKnob { + Davies1900hLargeBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeBlack.svg"))); + } +}; + +struct Davies1900hLargeRedKnob : Davies1900hKnob { + Davies1900hLargeRedKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeRed.svg"))); + } +}; + +struct Davies1900hSmallBlackKnob : Davies1900hKnob { + Davies1900hSmallBlackKnob() { + setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hSmallBlack.svg"))); + } +}; + +struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob, SnapKnob {}; + + struct Rogan : SVGKnob { Rogan() { minAngle = -0.83*M_PI; @@ -261,58 +348,6 @@ struct SynthTechAlco : SVGKnob { } }; -struct Davies1900hKnob : SVGKnob { - Davies1900hKnob() { - box.size = Vec(36, 36); - minAngle = -0.83*M_PI; - maxAngle = 0.83*M_PI; - } -}; - -struct Davies1900hWhiteKnob : Davies1900hKnob { - Davies1900hWhiteKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hWhite.svg"))); - } -}; - -struct Davies1900hBlackKnob : Davies1900hKnob { - Davies1900hBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hBlack.svg"))); - } -}; - -struct Davies1900hRedKnob : Davies1900hKnob { - Davies1900hRedKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hRed.svg"))); - } -}; - -struct Davies1900hLargeWhiteKnob : Davies1900hKnob { - Davies1900hLargeWhiteKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeWhite.svg"))); - } -}; - -struct Davies1900hLargeBlackKnob : Davies1900hKnob { - Davies1900hLargeBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeBlack.svg"))); - } -}; - -struct Davies1900hLargeRedKnob : Davies1900hKnob { - Davies1900hLargeRedKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hLargeRed.svg"))); - } -}; - -struct Davies1900hSmallBlackKnob : Davies1900hKnob { - Davies1900hSmallBlackKnob() { - setSVG(SVG::load(assetGlobal("res/ComponentLibrary/Davies1900hSmallBlack.svg"))); - } -}; - -struct Davies1900hSmallBlackSnapKnob : Davies1900hSmallBlackKnob, SnapKnob {}; - struct Trimpot : SVGKnob { Trimpot() { box.size = Vec(17, 17); diff --git a/include/math.hpp b/include/math.hpp index c01135b1..af8b67b4 100644 --- a/include/math.hpp +++ b/include/math.hpp @@ -167,9 +167,15 @@ struct Vec { Vec mult(float s) { return Vec(x * s, y * s); } + Vec mult(Vec b) { + return Vec(x * b.x, y * b.y); + } Vec div(float s) { return Vec(x / s, y / s); } + Vec div(Vec b) { + return Vec(x / b.x, y / b.y); + } float dot(Vec b) { return x * b.x + y * b.y; } diff --git a/res/ComponentLibrary/RoundBlack.svg b/res/ComponentLibrary/RoundBlack.svg new file mode 100644 index 00000000..92969944 --- /dev/null +++ b/res/ComponentLibrary/RoundBlack.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index 181766e4..256e6917 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -24,6 +24,8 @@ void SVGKnob::step() { if (dirty) { float angle = rescalef(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);