From 25d54ad9761af37554fe4b1f14dd23a58dfe8061 Mon Sep 17 00:00:00 2001 From: yaw-man Date: Thu, 18 Aug 2022 11:21:03 -0300 Subject: [PATCH] Add button callbacks --- .gitignore | 10 +++++---- src/yaw-tab/ui.cpp | 53 +++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index b018e83..93bcd24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -out -.vs -doc -releases \ No newline at end of file +out/ +.vs/ +doc/ +build/ +releases/ +lib/DPF/khronos/ \ No newline at end of file diff --git a/src/yaw-tab/ui.cpp b/src/yaw-tab/ui.cpp index 286896a..346ba05 100644 --- a/src/yaw-tab/ui.cpp +++ b/src/yaw-tab/ui.cpp @@ -1,12 +1,15 @@ #include "DistrhoUI.hpp" #include "tablet.h" +#ifdef DEBUG #include #include +#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(static_cast(size), static_cast(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