From ec83a4dacb65850bd1773cf2d5f1ceaaae307821 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 11 Jan 2019 05:20:55 -0500 Subject: [PATCH] Improve behavior for unbounded params --- include/app/ParamQuantity.hpp | 2 ++ src/app/ParamQuantity.cpp | 8 ++++++++ src/app/ParamWidget.cpp | 2 +- src/app/SVGKnob.cpp | 4 ++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/app/ParamQuantity.hpp b/include/app/ParamQuantity.hpp index 218109e3..465ca784 100644 --- a/include/app/ParamQuantity.hpp +++ b/include/app/ParamQuantity.hpp @@ -24,6 +24,8 @@ struct ParamQuantity : Quantity { float getDefaultValue() override; float getDisplayValue() override; void setDisplayValue(float displayValue) override; + std::string getDisplayValueString() override; + void setDisplayValueString(std::string s) override; int getDisplayPrecision() override; std::string getLabel() override; std::string getUnit() override; diff --git a/src/app/ParamQuantity.cpp b/src/app/ParamQuantity.cpp index bdd7a2f1..9caa6d3d 100644 --- a/src/app/ParamQuantity.cpp +++ b/src/app/ParamQuantity.cpp @@ -101,6 +101,14 @@ int ParamQuantity::getDisplayPrecision() { return (int) std::ceil(math::clamp(-log + 3.f, 0.f, 6.f)); } +std::string ParamQuantity::getDisplayValueString() { + return Quantity::getDisplayValueString(); +} + +void ParamQuantity::setDisplayValueString(std::string s) { + Quantity::setDisplayValueString(s); +} + std::string ParamQuantity::getLabel() { if (!module) return Quantity::getLabel(); diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index 8340febb..b6a71eab 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -104,7 +104,7 @@ void ParamWidget::fromJson(json_t *rootJ) { void ParamWidget::onButton(const event::Button &e) { // Right click to reset if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_RIGHT && !(e.mods & WINDOW_MOD) && !(e.mods & GLFW_MOD_SHIFT)) { - if (paramQuantity) { + if (paramQuantity && paramQuantity->isBounded()) { float oldValue = paramQuantity->getValue(); paramQuantity->reset(); float newValue = paramQuantity->getValue(); diff --git a/src/app/SVGKnob.cpp b/src/app/SVGKnob.cpp index 76b88198..99cb98f3 100644 --- a/src/app/SVGKnob.cpp +++ b/src/app/SVGKnob.cpp @@ -36,11 +36,11 @@ void SVGKnob::onChange(const event::Change &e) { float angle; if (paramQuantity->isBounded()) { angle = math::rescale(paramQuantity->getScaledValue(), 0.f, 1.f, minAngle, maxAngle); - angle = std::fmod(angle, 2*M_PI); } else { - angle = math::rescale(paramQuantity->getValue(), 0.f, 1.f, minAngle, maxAngle); + angle = math::rescale(paramQuantity->getValue(), -1.f, 1.f, minAngle, maxAngle); } + angle = std::fmod(angle, 2*M_PI); tw->identity(); // Rotate SVG math::Vec center = sw->box.getCenter();