-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add enabled state control to button and knob handlers
Signed-off-by: falkTX <[email protected]>
- Loading branch information
Showing
2 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* DISTRHO Plugin Framework (DPF) | ||
* Copyright (C) 2012-2024 Filipe Coelho <[email protected]> | ||
* Copyright (C) 2012-2025 Filipe Coelho <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | ||
* or without fee is hereby granted, provided that the above copyright notice and this | ||
|
@@ -63,6 +63,9 @@ class ButtonEventHandler | |
bool isCheckable() const noexcept; | ||
void setCheckable(bool checkable) noexcept; | ||
|
||
bool isEnabled() const noexcept; | ||
void setEnabled(bool enabled) noexcept; | ||
|
||
Point<double> getLastClickPosition() const noexcept; | ||
Point<double> getLastMotionPosition() const noexcept; | ||
|
||
|
@@ -121,6 +124,9 @@ class KnobEventHandler | |
KnobEventHandler& operator=(const KnobEventHandler& other); | ||
virtual ~KnobEventHandler(); | ||
|
||
bool isEnabled() const noexcept; | ||
void setEnabled(bool enabled) noexcept; | ||
|
||
// if setStep(1) has been called before, this returns true | ||
bool isInteger() const noexcept; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* DISTRHO Plugin Framework (DPF) | ||
* Copyright (C) 2012-2024 Filipe Coelho <[email protected]> | ||
* Copyright (C) 2012-2025 Filipe Coelho <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose with | ||
* or without fee is hereby granted, provided that the above copyright notice and this | ||
|
@@ -31,6 +31,7 @@ struct ButtonEventHandler::PrivateData { | |
int state; | ||
bool checkable; | ||
bool checked; | ||
bool enabled; | ||
|
||
Point<double> lastClickPos; | ||
Point<double> lastMotionPos; | ||
|
@@ -44,11 +45,15 @@ struct ButtonEventHandler::PrivateData { | |
state(kButtonStateDefault), | ||
checkable(false), | ||
checked(false), | ||
enabled(true), | ||
lastClickPos(0, 0), | ||
lastMotionPos(0, 0) {} | ||
|
||
bool mouseEvent(const Widget::MouseEvent& ev) | ||
{ | ||
if (! enabled) | ||
return false; | ||
|
||
lastClickPos = ev.pos; | ||
|
||
// button was released, handle it now | ||
|
@@ -98,6 +103,9 @@ struct ButtonEventHandler::PrivateData { | |
|
||
bool motionEvent(const Widget::MotionEvent& ev) | ||
{ | ||
if (! enabled) | ||
return false; | ||
|
||
// keep pressed | ||
if (button != -1) | ||
{ | ||
|
@@ -171,6 +179,24 @@ struct ButtonEventHandler::PrivateData { | |
} | ||
} | ||
|
||
void setEnabled(const bool enabled2) noexcept | ||
{ | ||
if (enabled == enabled2) | ||
return; | ||
|
||
// reset temp vars if disabling | ||
if (! enabled2) | ||
{ | ||
button = -1; | ||
state = kButtonStateDefault; | ||
lastClickPos = Point<double>(); | ||
lastMotionPos = Point<double>(); | ||
} | ||
|
||
enabled = enabled2; | ||
widget->repaint(); | ||
} | ||
|
||
DISTRHO_DECLARE_NON_COPYABLE(PrivateData) | ||
}; | ||
|
||
|
@@ -217,6 +243,16 @@ void ButtonEventHandler::setCheckable(const bool checkable) noexcept | |
pData->checkable = checkable; | ||
} | ||
|
||
bool ButtonEventHandler::isEnabled() const noexcept | ||
{ | ||
return pData->enabled; | ||
} | ||
|
||
void ButtonEventHandler::setEnabled(const bool enabled) noexcept | ||
{ | ||
pData->setEnabled(enabled); | ||
} | ||
|
||
Point<double> ButtonEventHandler::getLastClickPosition() const noexcept | ||
{ | ||
return pData->lastClickPos; | ||
|
@@ -281,6 +317,7 @@ struct KnobEventHandler::PrivateData { | |
float value; | ||
float valueDef; | ||
float valueTmp; | ||
bool enabled; | ||
bool usingDefault; | ||
bool usingLog; | ||
Orientation orientation; | ||
|
@@ -301,6 +338,7 @@ struct KnobEventHandler::PrivateData { | |
value(0.5f), | ||
valueDef(value), | ||
valueTmp(value), | ||
enabled(true), | ||
usingDefault(false), | ||
usingLog(false), | ||
orientation(Vertical), | ||
|
@@ -320,6 +358,7 @@ struct KnobEventHandler::PrivateData { | |
value(other->value), | ||
valueDef(other->valueDef), | ||
valueTmp(value), | ||
enabled(other->enabled), | ||
usingDefault(other->usingDefault), | ||
usingLog(other->usingLog), | ||
orientation(other->orientation), | ||
|
@@ -338,6 +377,7 @@ struct KnobEventHandler::PrivateData { | |
value = other->value; | ||
valueDef = other->valueDef; | ||
valueTmp = value; | ||
enabled = other->enabled; | ||
usingDefault = other->usingDefault; | ||
usingLog = other->usingLog; | ||
orientation = other->orientation; | ||
|
@@ -363,6 +403,9 @@ struct KnobEventHandler::PrivateData { | |
|
||
bool mouseEvent(const Widget::MouseEvent& ev, const double scaleFactor) | ||
{ | ||
if (! enabled) | ||
return false; | ||
|
||
if (ev.button != 1) | ||
return false; | ||
|
||
|
@@ -416,6 +459,9 @@ struct KnobEventHandler::PrivateData { | |
|
||
bool motionEvent(const Widget::MotionEvent& ev, const double scaleFactor) | ||
{ | ||
if (! enabled) | ||
return false; | ||
|
||
if ((state & kKnobStateDragging) == 0x0) | ||
return false; | ||
|
||
|
@@ -501,6 +547,9 @@ struct KnobEventHandler::PrivateData { | |
|
||
bool scrollEvent(const Widget::ScrollEvent& ev) | ||
{ | ||
if (! enabled) | ||
return false; | ||
|
||
if (! widget->contains(ev.pos)) | ||
return false; | ||
|
||
|
@@ -541,6 +590,25 @@ struct KnobEventHandler::PrivateData { | |
return ((usingLog ? invlogscale(value) : value) - minimum) / diff; | ||
} | ||
|
||
void setEnabled(const bool enabled2) noexcept | ||
{ | ||
if (enabled == enabled2) | ||
return; | ||
|
||
// reset temp vars if disabling | ||
if (! enabled2) | ||
{ | ||
state = kKnobStateDefault; | ||
lastX = 0.0; | ||
lastY = 0.0; | ||
lastClickTime = 0; | ||
valueTmp = value; | ||
} | ||
|
||
enabled = enabled2; | ||
widget->repaint(); | ||
} | ||
|
||
void setRange(const float min, const float max) noexcept | ||
{ | ||
DISTRHO_SAFE_ASSERT_RETURN(max > min,); | ||
|
@@ -598,6 +666,16 @@ KnobEventHandler::~KnobEventHandler() | |
delete pData; | ||
} | ||
|
||
bool KnobEventHandler::isEnabled() const noexcept | ||
{ | ||
return pData->enabled; | ||
} | ||
|
||
void KnobEventHandler::setEnabled(const bool enabled) noexcept | ||
{ | ||
pData->setEnabled(enabled); | ||
} | ||
|
||
bool KnobEventHandler::isInteger() const noexcept | ||
{ | ||
return d_isEqual(pData->step, 1.f); | ||
|