diff --git a/dgl/EventHandlers.hpp b/dgl/EventHandlers.hpp index 443fa8d2..1609dc24 100644 --- a/dgl/EventHandlers.hpp +++ b/dgl/EventHandlers.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2024 Filipe Coelho + * Copyright (C) 2012-2025 Filipe Coelho * * 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 @@ public: bool isCheckable() const noexcept; void setCheckable(bool checkable) noexcept; + bool isEnabled() const noexcept; + void setEnabled(bool enabled) noexcept; + Point getLastClickPosition() const noexcept; Point getLastMotionPosition() const noexcept; @@ -121,6 +124,9 @@ public: 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; diff --git a/dgl/src/EventHandlers.cpp b/dgl/src/EventHandlers.cpp index a2721d2c..11e9055e 100644 --- a/dgl/src/EventHandlers.cpp +++ b/dgl/src/EventHandlers.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2024 Filipe Coelho + * Copyright (C) 2012-2025 Filipe Coelho * * 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 lastClickPos; Point 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(); + lastMotionPos = Point(); + } + + 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 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);