From 9085727425bd7f403abc7bbebd5f91dc482bd748 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 26 Dec 2017 17:33:00 -0500 Subject: [PATCH] Added support for continuous encoders, aka Knob widgets with infinite min/max values --- src/app/Knob.cpp | 6 +++++- src/app/SVGKnob.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index fbb5ee37..f47f3349 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -18,7 +18,11 @@ void Knob::onDragStart(EventDragStart &e) { void Knob::onDragMove(EventDragMove &e) { // Drag slower if Mod - float delta = KNOB_SENSITIVITY * (maxValue - minValue) * -e.mouseRel.y * speed; + float range = maxValue - minValue; + float delta = KNOB_SENSITIVITY * -e.mouseRel.y * speed; + if (std::isfinite(range)) + delta *= range; + if (guiIsModPressed()) delta /= 16.0; dragValue += delta; diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index ae25ddb3..fc96b131 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -23,7 +23,9 @@ void SVGKnob::step() { // Re-transform TransformWidget if dirty if (dirty) { tw->box.size = box.size; - float angle = rescalef(value, minValue, maxValue, minAngle, maxAngle); + float angle = 0.0; + if (std::isfinite(minValue) && std::isfinite(maxValue)) + angle = rescalef(value, minValue, maxValue, minAngle, maxAngle); tw->identity(); // Scale SVG to box tw->scale(box.size.div(sw->box.size));