Browse Source

Add appliesToEventInput arg to Button and Knob setEnabled

Signed-off-by: falkTX <falktx@falktx.com>
pull/491/head
falkTX 3 months ago
parent
commit
53454d71ba
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 25 additions and 13 deletions
  1. +2
    -2
      dgl/EventHandlers.hpp
  2. +23
    -11
      dgl/src/EventHandlers.cpp

+ 2
- 2
dgl/EventHandlers.hpp View File

@@ -64,7 +64,7 @@ public:
void setCheckable(bool checkable) noexcept; void setCheckable(bool checkable) noexcept;


bool isEnabled() const noexcept; bool isEnabled() const noexcept;
void setEnabled(bool enabled) noexcept;
void setEnabled(bool enabled, bool appliesToEventInput = true) noexcept;


Point<double> getLastClickPosition() const noexcept; Point<double> getLastClickPosition() const noexcept;
Point<double> getLastMotionPosition() const noexcept; Point<double> getLastMotionPosition() const noexcept;
@@ -125,7 +125,7 @@ public:
virtual ~KnobEventHandler(); virtual ~KnobEventHandler();


bool isEnabled() const noexcept; bool isEnabled() const noexcept;
void setEnabled(bool enabled) noexcept;
void setEnabled(bool enabled, bool appliesToEventInput = true) noexcept;


// if setStep(1) has been called before, this returns true // if setStep(1) has been called before, this returns true
bool isInteger() const noexcept; bool isInteger() const noexcept;


+ 23
- 11
dgl/src/EventHandlers.cpp View File

@@ -32,6 +32,7 @@ struct ButtonEventHandler::PrivateData {
bool checkable; bool checkable;
bool checked; bool checked;
bool enabled; bool enabled;
bool enabledInput;


Point<double> lastClickPos; Point<double> lastClickPos;
Point<double> lastMotionPos; Point<double> lastMotionPos;
@@ -46,12 +47,13 @@ struct ButtonEventHandler::PrivateData {
checkable(false), checkable(false),
checked(false), checked(false),
enabled(true), enabled(true),
enabledInput(true),
lastClickPos(0, 0), lastClickPos(0, 0),
lastMotionPos(0, 0) {} lastMotionPos(0, 0) {}


bool mouseEvent(const Widget::MouseEvent& ev) bool mouseEvent(const Widget::MouseEvent& ev)
{ {
if (! enabled)
if (! enabledInput)
return false; return false;


lastClickPos = ev.pos; lastClickPos = ev.pos;
@@ -103,7 +105,7 @@ struct ButtonEventHandler::PrivateData {


bool motionEvent(const Widget::MotionEvent& ev) bool motionEvent(const Widget::MotionEvent& ev)
{ {
if (! enabled)
if (! enabledInput)
return false; return false;


// keep pressed // keep pressed
@@ -179,8 +181,11 @@ struct ButtonEventHandler::PrivateData {
} }
} }


void setEnabled(const bool enabled2) noexcept
void setEnabled(const bool enabled2, const bool appliesToEventInput) noexcept
{ {
if (appliesToEventInput)
enabledInput = enabled2;

if (enabled == enabled2) if (enabled == enabled2)
return; return;


@@ -248,9 +253,9 @@ bool ButtonEventHandler::isEnabled() const noexcept
return pData->enabled; return pData->enabled;
} }


void ButtonEventHandler::setEnabled(const bool enabled) noexcept
void ButtonEventHandler::setEnabled(const bool enabled, const bool appliesToEventInput) noexcept
{ {
pData->setEnabled(enabled);
pData->setEnabled(enabled, appliesToEventInput);
} }


Point<double> ButtonEventHandler::getLastClickPosition() const noexcept Point<double> ButtonEventHandler::getLastClickPosition() const noexcept
@@ -318,6 +323,7 @@ struct KnobEventHandler::PrivateData {
float valueDef; float valueDef;
float valueTmp; float valueTmp;
bool enabled; bool enabled;
bool enabledInput;
bool usingDefault; bool usingDefault;
bool usingLog; bool usingLog;
Orientation orientation; Orientation orientation;
@@ -339,6 +345,7 @@ struct KnobEventHandler::PrivateData {
valueDef(value), valueDef(value),
valueTmp(value), valueTmp(value),
enabled(true), enabled(true),
enabledInput(true),
usingDefault(false), usingDefault(false),
usingLog(false), usingLog(false),
orientation(Vertical), orientation(Vertical),
@@ -359,6 +366,7 @@ struct KnobEventHandler::PrivateData {
valueDef(other->valueDef), valueDef(other->valueDef),
valueTmp(value), valueTmp(value),
enabled(other->enabled), enabled(other->enabled),
enabledInput(other->enabledInput),
usingDefault(other->usingDefault), usingDefault(other->usingDefault),
usingLog(other->usingLog), usingLog(other->usingLog),
orientation(other->orientation), orientation(other->orientation),
@@ -378,6 +386,7 @@ struct KnobEventHandler::PrivateData {
valueDef = other->valueDef; valueDef = other->valueDef;
valueTmp = value; valueTmp = value;
enabled = other->enabled; enabled = other->enabled;
enabledInput = other->enabledInput;
usingDefault = other->usingDefault; usingDefault = other->usingDefault;
usingLog = other->usingLog; usingLog = other->usingLog;
orientation = other->orientation; orientation = other->orientation;
@@ -403,7 +412,7 @@ struct KnobEventHandler::PrivateData {


bool mouseEvent(const Widget::MouseEvent& ev, const double scaleFactor) bool mouseEvent(const Widget::MouseEvent& ev, const double scaleFactor)
{ {
if (! enabled)
if (! enabledInput)
return false; return false;


if (ev.button != 1) if (ev.button != 1)
@@ -459,7 +468,7 @@ struct KnobEventHandler::PrivateData {


bool motionEvent(const Widget::MotionEvent& ev, const double scaleFactor) bool motionEvent(const Widget::MotionEvent& ev, const double scaleFactor)
{ {
if (! enabled)
if (! enabledInput)
return false; return false;


if ((state & kKnobStateDragging) == 0x0) if ((state & kKnobStateDragging) == 0x0)
@@ -547,7 +556,7 @@ struct KnobEventHandler::PrivateData {


bool scrollEvent(const Widget::ScrollEvent& ev) bool scrollEvent(const Widget::ScrollEvent& ev)
{ {
if (! enabled)
if (! enabledInput)
return false; return false;


if (! widget->contains(ev.pos)) if (! widget->contains(ev.pos))
@@ -590,8 +599,11 @@ struct KnobEventHandler::PrivateData {
return ((usingLog ? invlogscale(value) : value) - minimum) / diff; return ((usingLog ? invlogscale(value) : value) - minimum) / diff;
} }


void setEnabled(const bool enabled2) noexcept
void setEnabled(const bool enabled2, const bool appliesToEventInput) noexcept
{ {
if (appliesToEventInput)
enabledInput = enabled2;

if (enabled == enabled2) if (enabled == enabled2)
return; return;


@@ -671,9 +683,9 @@ bool KnobEventHandler::isEnabled() const noexcept
return pData->enabled; return pData->enabled;
} }


void KnobEventHandler::setEnabled(const bool enabled) noexcept
void KnobEventHandler::setEnabled(const bool enabled, const bool appliesToEventInput) noexcept
{ {
pData->setEnabled(enabled);
pData->setEnabled(enabled, appliesToEventInput);
} }


bool KnobEventHandler::isInteger() const noexcept bool KnobEventHandler::isInteger() const noexcept


Loading…
Cancel
Save