Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix BlendishToolButton callback
  • Loading branch information
falkTX committed Nov 20, 2022
1 parent c0ebd2c commit ea4b4f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
23 changes: 19 additions & 4 deletions opengl/Blendish.cpp
Expand Up @@ -543,18 +543,27 @@ void BlendishLabel::onBlendishDisplay()

BlendishToolButton::BlendishToolButton(BlendishSubWidgetSharedContext* const parent)
: BlendishSubWidget(parent),
ButtonEventHandler(this)
ButtonEventHandler(this),
callback(nullptr)
{
ButtonEventHandler::setCallback(this);
setSize(BND_TOOL_WIDTH*bData->scaleFactor, BND_WIDGET_HEIGHT*bData->scaleFactor);
}

BlendishToolButton::BlendishToolButton(SubWidget* const parent)
: BlendishSubWidget(parent),
ButtonEventHandler(this)
ButtonEventHandler(this),
callback(nullptr)
{
ButtonEventHandler::setCallback(this);
setSize(BND_TOOL_WIDTH*bData->scaleFactor, BND_WIDGET_HEIGHT*bData->scaleFactor);
}

void BlendishToolButton::setCallback(Callback* const cb)
{
callback = cb;
}

uint BlendishToolButton::getMinimumWidth() const noexcept
{
return BND_TOOL_WIDTH;
Expand Down Expand Up @@ -587,6 +596,12 @@ bool BlendishToolButton::onMotion(const MotionEvent& ev)
return motionEvent(ev);
}

void BlendishToolButton::buttonClicked(SubWidget* const, const int button)
{
if (callback != nullptr)
callback->blendishToolButtonClicked(this, button);
}

// --------------------------------------------------------------------------------------------------------------------

BlendishCheckBox::BlendishCheckBox(BlendishSubWidgetSharedContext* const parent)
Expand Down Expand Up @@ -688,9 +703,9 @@ void BlendishButtonGroup::setActiveButton(const uint id, const bool sendCallback
callback->blendishButtonGroupClicked(this, id);
}

void BlendishButtonGroup::setCallback(Callback* const callback2)
void BlendishButtonGroup::setCallback(Callback* const cb)
{
callback = callback2;
callback = cb;
}

uint BlendishButtonGroup::getMinimumWidth() const noexcept
Expand Down
13 changes: 10 additions & 3 deletions opengl/Blendish.hpp
Expand Up @@ -249,7 +249,8 @@ class BlendishLabel : public BlendishSubWidget
Will trigger Callback::blendishButtonClicked.
*/
class BlendishToolButton : public BlendishSubWidget,
public ButtonEventHandler
public ButtonEventHandler,
public ButtonEventHandler::Callback
{
public:
struct Callback {
Expand All @@ -260,12 +261,19 @@ class BlendishToolButton : public BlendishSubWidget,
explicit BlendishToolButton(BlendishSubWidgetSharedContext* parent);
explicit BlendishToolButton(SubWidget* parent);

void setCallback(Callback* callback);

protected:
uint getMinimumWidth() const noexcept override;
void onBlendishDisplay() override;
bool onMouse(const MouseEvent& ev) override;
bool onMotion(const MotionEvent& ev) override;

private:
Callback* callback;

void buttonClicked(SubWidget* widget, int button) override;

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BlendishToolButton)
};

Expand All @@ -277,8 +285,7 @@ class BlendishToolButton : public BlendishSubWidget,
This widget is a simple checkbox.
Uses the label methods from BlendishSubWidget to set its contents.
Provides its own methods for setting the checked state.
Will trigger Callback::blendishButtonClicked.
Uses the methods from ButtonEventHandler to set checked state.
*/
class BlendishCheckBox : public BlendishSubWidget,
public ButtonEventHandler
Expand Down

0 comments on commit ea4b4f3

Please sign in to comment.