Browse Source

Add enabled state control to button and knob handlers

Signed-off-by: falkTX <falktx@falktx.com>
pull/491/head
falkTX 3 months ago
parent
commit
6b3d1da7c3
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 86 additions and 2 deletions
  1. +7
    -1
      dgl/EventHandlers.hpp
  2. +79
    -1
      dgl/src/EventHandlers.cpp

+ 7
- 1
dgl/EventHandlers.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
*
* 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<double> getLastClickPosition() const noexcept;
Point<double> 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;



+ 79
- 1
dgl/src/EventHandlers.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2024 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
*
* 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);


Loading…
Cancel
Save