commit 3857d83acd411ffee53d31537bfad45eed652c72
parent 94dbe91e4ff7353e0f81ed25819b3214d1b116d1
Author: falkTX <falktx@falktx.com>
Date: Wed, 24 Aug 2022 04:45:36 +0100
Allow KnobEventHandler orientation to be both (horiz and vertical)
Diffstat:
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/dgl/EventHandlers.hpp b/dgl/EventHandlers.hpp
@@ -94,7 +94,8 @@ class KnobEventHandler
public:
enum Orientation {
Horizontal,
- Vertical
+ Vertical,
+ Both
};
// NOTE hover not implemented yet
@@ -139,7 +140,7 @@ public:
void setUsingLogScale(bool yesNo) noexcept;
Orientation getOrientation() const noexcept;
- void setOrientation(const Orientation orientation) noexcept;
+ void setOrientation(Orientation orientation) noexcept;
void setCallback(Callback* callback) noexcept;
diff --git a/dgl/src/EventHandlers.cpp b/dgl/src/EventHandlers.cpp
@@ -402,23 +402,35 @@ struct KnobEventHandler::PrivateData {
bool doVal = false;
float d, value2 = 0.0f;
- if (orientation == Horizontal)
+ switch (orientation)
{
+ case Horizontal:
if (const double movX = ev.pos.getX() - lastX)
{
d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f;
value2 = (usingLog ? invlogscale(valueTmp) : valueTmp) + (float(maximum - minimum) / d * float(movX));
doVal = true;
}
- }
- else if (orientation == Vertical)
- {
+ break;
+ case Vertical:
if (const double movY = lastY - ev.pos.getY())
{
d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f;
value2 = (usingLog ? invlogscale(valueTmp) : valueTmp) + (float(maximum - minimum) / d * float(movY));
doVal = true;
}
+ break;
+ case Both:
+ const double movX = ev.pos.getX() - lastX;
+ const double movY = lastY - ev.pos.getY();
+
+ if (const double mov = movX + movY)
+ {
+ d = (ev.mod & kModifierControl) ? 2000.0f : 200.0f;
+ value2 = (usingLog ? invlogscale(valueTmp) : valueTmp) + (float(maximum - minimum) / d * float(mov));
+ doVal = true;
+ }
+ break;
}
if (! doVal)
@@ -596,9 +608,6 @@ KnobEventHandler::Orientation KnobEventHandler::getOrientation() const noexcept
void KnobEventHandler::setOrientation(const Orientation orientation) noexcept
{
- if (pData->orientation == orientation)
- return;
-
pData->orientation = orientation;
}