Browse Source

Fix history for momentary Switches, remove `virtual` from Core structs

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
445e5e6d6b
7 changed files with 29 additions and 26 deletions
  1. +1
    -0
      include/app/Switch.hpp
  2. +2
    -3
      include/ui/Quantity.hpp
  3. +2
    -2
      src/Core/Blank.cpp
  4. +1
    -0
      src/app/ModuleWidget.cpp
  5. +1
    -3
      src/app/ParamQuantity.cpp
  6. +18
    -18
      src/app/Switch.cpp
  7. +4
    -0
      src/ui/Quantity.cpp

+ 1
- 0
include/app/Switch.hpp View File

@@ -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;
};


+ 2
- 3
include/ui/Quantity.hpp View File

@@ -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();


+ 2
- 2
src/Core/Blank.cpp View File

@@ -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;


+ 1
- 0
src/app/ModuleWidget.cpp View File

@@ -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;
}
}


+ 1
- 3
src/app/ParamQuantity.cpp View File

@@ -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() {


+ 18
- 18
src/app/Switch.cpp View File

@@ -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();
}


+ 4
- 0
src/ui/Quantity.cpp View File

@@ -5,6 +5,10 @@
namespace rack {


int Quantity::getDisplayPrecision() {
return 5;
}

std::string Quantity::getDisplayValueString() {
return string::f("%.*g", getDisplayPrecision(), math::normalizeZero(getDisplayValue()));
}


Loading…
Cancel
Save