Add button callbacks
This commit is contained in:
parent
5846220601
commit
25d54ad976
|
@ -1,4 +1,6 @@
|
|||
out
|
||||
.vs
|
||||
doc
|
||||
releases
|
||||
out/
|
||||
.vs/
|
||||
doc/
|
||||
build/
|
||||
releases/
|
||||
lib/DPF/khronos/
|
|
@ -1,12 +1,15 @@
|
|||
#include "DistrhoUI.hpp"
|
||||
#include "tablet.h"
|
||||
#ifdef DEBUG
|
||||
#include <format>
|
||||
#include <optional>
|
||||
#endif
|
||||
|
||||
START_NAMESPACE_DISTRHO
|
||||
|
||||
//UI element for mapping the currently pressed pen button combination to a parameter.
|
||||
class ButtonMappingWidget : public NanoSubWidget
|
||||
class ButtonMappingWidget : public NanoSubWidget,
|
||||
public ButtonEventHandler
|
||||
{
|
||||
public:
|
||||
ButtonMappingWidget(
|
||||
|
@ -14,7 +17,8 @@ public:
|
|||
float initialSize,
|
||||
float initialX,
|
||||
float initialY,
|
||||
Parameters associatedParameter) :
|
||||
Parameters associatedParameter,
|
||||
ButtonEventHandler::Callback* const callback) :
|
||||
x(initialX),
|
||||
y(initialY),
|
||||
size(initialSize),
|
||||
|
@ -22,41 +26,33 @@ public:
|
|||
isClicked(false),
|
||||
isPenPressed(false),
|
||||
mask(0),
|
||||
NanoSubWidget(parent)
|
||||
NanoSubWidget(parent),
|
||||
ButtonEventHandler(this)
|
||||
{
|
||||
setNeedsFullViewportDrawing(true);
|
||||
setSize(Size<uint>(static_cast<uint>(size), static_cast<uint>(size)));
|
||||
setAbsolutePos((int)x, (int)y);
|
||||
ButtonEventHandler::setCallback(callback);
|
||||
}
|
||||
|
||||
void onNanoDisplay() override
|
||||
{
|
||||
beginPath();
|
||||
strokeColor(200, 200, 200);
|
||||
//if (isClicked)
|
||||
fillColor(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
//roundedRect(x, y, size, size, 0.f);
|
||||
circle(0.5 * getWidth(), 0.5 * getHeight(), 10.f);
|
||||
fillColor(0.5f, 0.5f, 0.5f, 0.5f * (isClicked + isPenPressed));
|
||||
roundedRect(0.f, 0.f, size, size, 0.5f * size);
|
||||
stroke();
|
||||
fill();
|
||||
closePath();
|
||||
}
|
||||
|
||||
bool onMouse(const MouseEvent& ev) override
|
||||
{
|
||||
isClicked = ev.press && contains(ev.pos);
|
||||
repaint();
|
||||
return false;
|
||||
isClicked = ev.press;
|
||||
return ButtonEventHandler::mouseEvent(ev);
|
||||
}
|
||||
|
||||
void setMask(const ButtonMask m)
|
||||
{
|
||||
mask = m;
|
||||
}
|
||||
|
||||
bool matchesMask(const ButtonMask m)
|
||||
{
|
||||
isPenPressed = (m && mask == m);
|
||||
return isPenPressed;
|
||||
}
|
||||
void setMask(const ButtonMask m) { mask = m; }
|
||||
bool matchesMask(const ButtonMask m) { return isPenPressed = (m && mask == m); }
|
||||
|
||||
bool isClicked;
|
||||
bool isPenPressed;
|
||||
|
@ -71,7 +67,8 @@ private:
|
|||
};
|
||||
|
||||
|
||||
class TabUI : public UI
|
||||
class TabUI : public UI,
|
||||
public ButtonEventHandler::Callback
|
||||
{
|
||||
static const uint kInitialWidth = 800;
|
||||
static const uint kInitialHeight = 600;
|
||||
|
@ -80,8 +77,8 @@ public:
|
|||
TabUI()
|
||||
: UI(kInitialWidth, kInitialHeight),
|
||||
tab(getWindow().getNativeWindowHandle()),
|
||||
AButtonWidget(this, 5.f, 0.f, 0.f, kParameterButtonA),
|
||||
BButtonWidget(this, 50.f, 0.f, 0.f, kParameterButtonB)
|
||||
AButtonWidget(this, 75.f, 700.f, 500.f, kParameterButtonA, this),
|
||||
BButtonWidget(this, 75.f, 700.f, 400.f, kParameterButtonB, this)
|
||||
{
|
||||
|
||||
#ifdef DGL_NO_SHARED_RESOURCES
|
||||
|
@ -118,8 +115,12 @@ protected:
|
|||
setParameterValue(kParameterButtonB, 1.f);
|
||||
else setParameterValue(kParameterButtonB, 0.f);
|
||||
|
||||
if (AButtonWidget.isClicked) AButtonWidget.setMask(buttonMask);
|
||||
if (BButtonWidget.isClicked) BButtonWidget.setMask(buttonMask);
|
||||
}
|
||||
|
||||
void buttonClicked(SubWidget* const widget, int ) override
|
||||
{
|
||||
if (widget == &AButtonWidget) AButtonWidget.setMask(pkt.buttons);
|
||||
if (widget == &BButtonWidget) BButtonWidget.setMask(pkt.buttons);
|
||||
}
|
||||
|
||||
void parameterChanged(uint32_t index, float value) override
|
||||
|
|
Loading…
Reference in New Issue