From e1fbf120ddc719347f277870a451e49a35c337d2 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 26 Jun 2024 16:32:53 -0400 Subject: [PATCH] Add setValueFromGUIQuantized and use it in the ContEditor (#94) So we can do quantized drags via the interface --- include/sst/jucegui/data/Continuous.h | 1 + src/sst/jucegui/components/ContinuousParamEditor.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/sst/jucegui/data/Continuous.h b/include/sst/jucegui/data/Continuous.h index 8fc1471..ac05eca 100644 --- a/include/sst/jucegui/data/Continuous.h +++ b/include/sst/jucegui/data/Continuous.h @@ -64,6 +64,7 @@ struct Continuous : public Labeled virtual float getValue() const = 0; virtual void setValueFromGUI(const float &f) = 0; + virtual void setValueFromGUIQuantized(const float &f) { setValueFromGUI(f); } virtual void setValueFromModel(const float &f) = 0; virtual float getDefaultValue() const = 0; virtual float getValue01() { return (getValue() - getMin()) / (getMax() - getMin()); } diff --git a/src/sst/jucegui/components/ContinuousParamEditor.cpp b/src/sst/jucegui/components/ContinuousParamEditor.cpp index 42310bb..02868b0 100644 --- a/src/sst/jucegui/components/ContinuousParamEditor.cpp +++ b/src/sst/jucegui/components/ContinuousParamEditor.cpp @@ -126,7 +126,14 @@ void ContinuousParamEditor::mouseDrag(const juce::MouseEvent &e) else { auto vn = std::clamp(mouseDownV0 + d, continuous()->getMin(), continuous()->getMax()); - continuous()->setValueFromGUI(vn); + if (e.mods.isCommandDown()) + { + continuous()->setValueFromGUIQuantized(vn); + } + else + { + continuous()->setValueFromGUI(vn); + } notifyAccessibleChange(); mouseDownV0 = vn; }