From 445e5e6d6baa74c4d5c96a15b87ff505a41dd888 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 12 Jan 2019 23:32:56 -0500 Subject: [PATCH] Fix history for momentary Switches, remove `virtual` from Core structs --- include/app/Switch.hpp | 1 + include/ui/Quantity.hpp | 5 ++--- src/Core/Blank.cpp | 4 ++-- src/app/ModuleWidget.cpp | 1 + src/app/ParamQuantity.cpp | 4 +--- src/app/Switch.cpp | 36 ++++++++++++++++++------------------ src/ui/Quantity.cpp | 4 ++++ 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/app/Switch.hpp b/include/app/Switch.hpp index 5d45a4c5..9085adf3 100644 --- a/include/app/Switch.hpp +++ b/include/app/Switch.hpp @@ -10,6 +10,7 @@ namespace rack { struct Switch : ParamWidget { /** Return to original position when released */ bool momentary = false; + void onDragStart(const event::DragStart &e) override; void onDragEnd(const event::DragEnd &e) override; }; diff --git a/include/ui/Quantity.hpp b/include/ui/Quantity.hpp index 182a05e2..7aa8d43c 100644 --- a/include/ui/Quantity.hpp +++ b/include/ui/Quantity.hpp @@ -39,10 +39,9 @@ struct Quantity { /** Inversely transforms the display value and sets the value */ virtual void setDisplayValue(float displayValue) {setValue(displayValue);} - /** The number of decimal places for displaying - A precision of 2 will display as "1.00" for example. + /** The number of total decimal places for generating the display value string */ - virtual int getDisplayPrecision() {return 2;} + virtual int getDisplayPrecision(); /** Returns a string representation of the display value */ virtual std::string getDisplayValueString(); diff --git a/src/Core/Blank.cpp b/src/Core/Blank.cpp index e9b288f6..fc0a1353 100644 --- a/src/Core/Blank.cpp +++ b/src/Core/Blank.cpp @@ -4,7 +4,7 @@ using namespace rack; -struct BlankPanel : virtual Widget { +struct BlankPanel : Widget { Widget *panelBorder; BlankPanel() { @@ -26,7 +26,7 @@ struct BlankPanel : virtual Widget { }; -struct ModuleResizeHandle : virtual Widget { +struct ModuleResizeHandle : Widget { bool right = false; float dragX; Rect originalBox; diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 6465a4bb..8c2aa9d1 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -340,6 +340,7 @@ void ModuleWidget::onHover(const event::Hover &e) { if (glfwGetKey(app()->window->win, GLFW_KEY_DELETE) == GLFW_PRESS || glfwGetKey(app()->window->win, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { if (!app()->window->isModPressed() && !app()->window->isShiftPressed()) { ModuleWidget_removeAction(this); + e.consume(NULL); return; } } diff --git a/src/app/ParamQuantity.cpp b/src/app/ParamQuantity.cpp index 21ebcc1e..8e49b159 100644 --- a/src/app/ParamQuantity.cpp +++ b/src/app/ParamQuantity.cpp @@ -90,9 +90,7 @@ void ParamQuantity::setDisplayValue(float displayValue) { } int ParamQuantity::getDisplayPrecision() { - if (!module) - return Quantity::getDisplayPrecision(); - return 5; + return Quantity::getDisplayPrecision(); } std::string ParamQuantity::getDisplayValueString() { diff --git a/src/app/Switch.cpp b/src/app/Switch.cpp index 33683803..b1bdc89e 100644 --- a/src/app/Switch.cpp +++ b/src/app/Switch.cpp @@ -8,15 +8,15 @@ namespace rack { void Switch::onDragStart(const event::DragStart &e) { - // Cycle through values - // e.g. a range of [0.0, 3.0] would have modes 0, 1, 2, and 3. - if (paramQuantity) { - float oldValue = paramQuantity->getValue(); - if (momentary) { + if (momentary) { + if (paramQuantity) { // Set to maximum value paramQuantity->setMax(); } - else { + } + else { + if (paramQuantity) { + float oldValue = paramQuantity->getValue(); // Increment value by 1, or reset back to minimum if (paramQuantity->isMax()) { paramQuantity->setMin(); @@ -24,24 +24,24 @@ void Switch::onDragStart(const event::DragStart &e) { else { paramQuantity->setValue(std::floor(paramQuantity->getValue() + 1)); } - } - float newValue = paramQuantity->getValue(); - if (oldValue != newValue) { - // Push ParamChange history action - history::ParamChange *h = new history::ParamChange; - h->moduleId = paramQuantity->module->id; - h->paramId = paramQuantity->paramId; - h->oldValue = oldValue; - h->newValue = newValue; - app()->history->push(h); + float newValue = paramQuantity->getValue(); + if (oldValue != newValue) { + // Push ParamChange history action + history::ParamChange *h = new history::ParamChange; + h->moduleId = paramQuantity->module->id; + h->paramId = paramQuantity->paramId; + h->oldValue = oldValue; + h->newValue = newValue; + app()->history->push(h); + } } } } void Switch::onDragEnd(const event::DragEnd &e) { - if (paramQuantity) { - if (momentary) { + if (momentary) { + if (paramQuantity) { // Set to minimum value paramQuantity->setMin(); } diff --git a/src/ui/Quantity.cpp b/src/ui/Quantity.cpp index dbdab9b2..b74ade6e 100644 --- a/src/ui/Quantity.cpp +++ b/src/ui/Quantity.cpp @@ -5,6 +5,10 @@ namespace rack { +int Quantity::getDisplayPrecision() { + return 5; +} + std::string Quantity::getDisplayValueString() { return string::f("%.*g", getDisplayPrecision(), math::normalizeZero(getDisplayValue())); }