summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2014-04-21 03:18:06 +1000
committerDamien Zammit <damien@zamaudio.com>2014-04-21 03:18:06 +1000
commit91228734cc4c89795b5df5cc8ecf314275793902 (patch)
tree71be87d5d865b8b7f2d4b74f42751d67d6ec9e21
parent197cd965525b488a019978cb75c8204c7d06675b (diff)
Added mousewheel scrolling on all knobs
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r--libs/dgl/ImageKnob.hpp1
-rw-r--r--libs/dgl/src/ImageKnob.cpp31
2 files changed, 32 insertions, 0 deletions
diff --git a/libs/dgl/ImageKnob.hpp b/libs/dgl/ImageKnob.hpp
index e774a4a..85f626e 100644
--- a/libs/dgl/ImageKnob.hpp
+++ b/libs/dgl/ImageKnob.hpp
@@ -61,6 +61,7 @@ public:
protected:
void onDisplay() override;
bool onMouse(int button, bool press, int x, int y) override;
+ bool onScroll(int x, int y, float dx, float dy) override;
bool onMotion(int x, int y) override;
void onReshape(int width, int height) override;
void onClose() override;
diff --git a/libs/dgl/src/ImageKnob.cpp b/libs/dgl/src/ImageKnob.cpp
index 78eb79e..ee99d09 100644
--- a/libs/dgl/src/ImageKnob.cpp
+++ b/libs/dgl/src/ImageKnob.cpp
@@ -311,6 +311,37 @@ void ImageKnob::onDisplay()
}
}
+bool ImageKnob::onScroll(int x, int y, float, float dy)
+{
+ float d, value;
+
+ if (! getArea().contains(x,y))
+ return false;
+
+ d = (getModifiers() & MODIFIER_CTRL) ? 2000.0f : 200.0f;
+ value = (fValueTmp) + (float(fMaximum - fMinimum) / d * 10.f * dy );
+
+ if (value < fMinimum)
+ {
+ value = fMinimum;
+ fValueTmp = value;
+ }
+ else if (value > fMaximum)
+ {
+ value = fMaximum;
+ fValueTmp = value;
+ }
+ else if (fStep != 0.0f)
+ {
+ fValueTmp = value;
+ const float rest = std::fmod(value, fStep);
+ value = value - rest + (rest > fStep/2.0f ? fStep : 0.0f);
+ }
+
+ setValue(value, true);
+ return true;
+}
+
bool ImageKnob::onMouse(int button, bool press, int x, int y)
{
if (button != 1)