| @@ -10,6 +10,7 @@ namespace rack { | |||||
| struct Switch : ParamWidget { | struct Switch : ParamWidget { | ||||
| /** Return to original position when released */ | /** Return to original position when released */ | ||||
| bool momentary = false; | bool momentary = false; | ||||
| void onDragStart(const event::DragStart &e) override; | void onDragStart(const event::DragStart &e) override; | ||||
| void onDragEnd(const event::DragEnd &e) override; | void onDragEnd(const event::DragEnd &e) override; | ||||
| }; | }; | ||||
| @@ -39,10 +39,9 @@ struct Quantity { | |||||
| /** Inversely transforms the display value and sets the value */ | /** Inversely transforms the display value and sets the value */ | ||||
| virtual void setDisplayValue(float displayValue) {setValue(displayValue);} | 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 */ | /** Returns a string representation of the display value */ | ||||
| virtual std::string getDisplayValueString(); | virtual std::string getDisplayValueString(); | ||||
| @@ -4,7 +4,7 @@ | |||||
| using namespace rack; | using namespace rack; | ||||
| struct BlankPanel : virtual Widget { | |||||
| struct BlankPanel : Widget { | |||||
| Widget *panelBorder; | Widget *panelBorder; | ||||
| BlankPanel() { | BlankPanel() { | ||||
| @@ -26,7 +26,7 @@ struct BlankPanel : virtual Widget { | |||||
| }; | }; | ||||
| struct ModuleResizeHandle : virtual Widget { | |||||
| struct ModuleResizeHandle : Widget { | |||||
| bool right = false; | bool right = false; | ||||
| float dragX; | float dragX; | ||||
| Rect originalBox; | Rect originalBox; | ||||
| @@ -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 (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()) { | if (!app()->window->isModPressed() && !app()->window->isShiftPressed()) { | ||||
| ModuleWidget_removeAction(this); | ModuleWidget_removeAction(this); | ||||
| e.consume(NULL); | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| @@ -90,9 +90,7 @@ void ParamQuantity::setDisplayValue(float displayValue) { | |||||
| } | } | ||||
| int ParamQuantity::getDisplayPrecision() { | int ParamQuantity::getDisplayPrecision() { | ||||
| if (!module) | |||||
| return Quantity::getDisplayPrecision(); | |||||
| return 5; | |||||
| return Quantity::getDisplayPrecision(); | |||||
| } | } | ||||
| std::string ParamQuantity::getDisplayValueString() { | std::string ParamQuantity::getDisplayValueString() { | ||||
| @@ -8,15 +8,15 @@ namespace rack { | |||||
| void Switch::onDragStart(const event::DragStart &e) { | 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 | // Set to maximum value | ||||
| paramQuantity->setMax(); | paramQuantity->setMax(); | ||||
| } | } | ||||
| else { | |||||
| } | |||||
| else { | |||||
| if (paramQuantity) { | |||||
| float oldValue = paramQuantity->getValue(); | |||||
| // Increment value by 1, or reset back to minimum | // Increment value by 1, or reset back to minimum | ||||
| if (paramQuantity->isMax()) { | if (paramQuantity->isMax()) { | ||||
| paramQuantity->setMin(); | paramQuantity->setMin(); | ||||
| @@ -24,24 +24,24 @@ void Switch::onDragStart(const event::DragStart &e) { | |||||
| else { | else { | ||||
| paramQuantity->setValue(std::floor(paramQuantity->getValue() + 1)); | 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) { | void Switch::onDragEnd(const event::DragEnd &e) { | ||||
| if (paramQuantity) { | |||||
| if (momentary) { | |||||
| if (momentary) { | |||||
| if (paramQuantity) { | |||||
| // Set to minimum value | // Set to minimum value | ||||
| paramQuantity->setMin(); | paramQuantity->setMin(); | ||||
| } | } | ||||
| @@ -5,6 +5,10 @@ | |||||
| namespace rack { | namespace rack { | ||||
| int Quantity::getDisplayPrecision() { | |||||
| return 5; | |||||
| } | |||||
| std::string Quantity::getDisplayValueString() { | std::string Quantity::getDisplayValueString() { | ||||
| return string::f("%.*g", getDisplayPrecision(), math::normalizeZero(getDisplayValue())); | return string::f("%.*g", getDisplayPrecision(), math::normalizeZero(getDisplayValue())); | ||||
| } | } | ||||