Build release version, separate UI into header file
This commit is contained in:
parent
d4644df706
commit
4c8cd87421
|
@ -1,5 +1,4 @@
|
||||||
#include "DistrhoUI.hpp"
|
#include "ui.h"
|
||||||
#include "tablet.h"
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -7,19 +6,13 @@
|
||||||
|
|
||||||
START_NAMESPACE_DISTRHO
|
START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
//UI element for mapping the currently pressed pen button combination to a parameter.
|
ButtonMappingWidget::ButtonMappingWidget(
|
||||||
class ButtonMappingWidget : public NanoSubWidget,
|
|
||||||
public ButtonEventHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ButtonMappingWidget(
|
|
||||||
Widget *parent,
|
Widget *parent,
|
||||||
float initialSize,
|
float initialSize,
|
||||||
float initialX,
|
float initialX,
|
||||||
float initialY,
|
float initialY,
|
||||||
Parameters associatedParameter,
|
Parameters associatedParameter,
|
||||||
ButtonEventHandler::Callback* const callback) :
|
ButtonEventHandler::Callback *const callback) : x(initialX),
|
||||||
x(initialX),
|
|
||||||
y(initialY),
|
y(initialY),
|
||||||
size(initialSize),
|
size(initialSize),
|
||||||
param(associatedParameter),
|
param(associatedParameter),
|
||||||
|
@ -34,7 +27,7 @@ public:
|
||||||
ButtonEventHandler::setCallback(callback);
|
ButtonEventHandler::setCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onNanoDisplay() override
|
void ButtonMappingWidget::onNanoDisplay()
|
||||||
{
|
{
|
||||||
beginPath();
|
beginPath();
|
||||||
strokeColor(200, 200, 200);
|
strokeColor(200, 200, 200);
|
||||||
|
@ -45,36 +38,16 @@ public:
|
||||||
closePath();
|
closePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onMouse(const MouseEvent& ev) override
|
bool ButtonMappingWidget::onMouse(const MouseEvent &ev)
|
||||||
{
|
{
|
||||||
isClicked = ev.press;
|
isClicked = ev.press;
|
||||||
return ButtonEventHandler::mouseEvent(ev);
|
return ButtonEventHandler::mouseEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMask(const ButtonMask m) { mask = m; }
|
static constexpr uint kInitialWidth = 800;
|
||||||
bool matchesMask(const ButtonMask m) { return isPenPressed = (m && mask == m); }
|
static constexpr uint kInitialHeight = 600;
|
||||||
|
|
||||||
bool isClicked;
|
TabUI::TabUI()
|
||||||
bool isPenPressed;
|
|
||||||
|
|
||||||
private:
|
|
||||||
float x = 0;
|
|
||||||
float y = 0;
|
|
||||||
float size = 0;
|
|
||||||
const Parameters param;
|
|
||||||
ButtonMask mask;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class TabUI : public UI,
|
|
||||||
public ButtonEventHandler::Callback
|
|
||||||
{
|
|
||||||
static const uint kInitialWidth = 800;
|
|
||||||
static const uint kInitialHeight = 600;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TabUI()
|
|
||||||
: UI(kInitialWidth, kInitialHeight),
|
: UI(kInitialWidth, kInitialHeight),
|
||||||
tab(getWindow().getNativeWindowHandle()),
|
tab(getWindow().getNativeWindowHandle()),
|
||||||
AButtonWidget(this, 75.f, 700.f, 500.f, kParameterButtonA, this),
|
AButtonWidget(this, 75.f, 700.f, 500.f, kParameterButtonA, this),
|
||||||
|
@ -87,52 +60,66 @@ public:
|
||||||
loadSharedResources();
|
loadSharedResources();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!tab.initialized) return;
|
if (!tab.initialized)
|
||||||
|
return;
|
||||||
// setGeometryConstraints(400, static_cast<uint>(300 * tabletAspectRatio), true, false);
|
// setGeometryConstraints(400, static_cast<uint>(300 * tabletAspectRatio), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
void TabUI::getTabletData()
|
||||||
|
|
||||||
void getTabletData()
|
|
||||||
{
|
{
|
||||||
if (!tab.initialized || !tab.GetPacket(pkt)) return;
|
if (!tab.initialized || !tab.GetPacket(pkt))
|
||||||
if (pkt == lastPkt) return;
|
return;
|
||||||
if (pkt.x != lastPkt.x) setParameterValue(ktpax, pkt.x);
|
if (pkt == lastPkt)
|
||||||
if (pkt.y != lastPkt.y) setParameterValue(ktpay, pkt.y);
|
return;
|
||||||
if (pkt.z != lastPkt.z) setParameterValue(ktpaz, pkt.z);
|
if (pkt.x != lastPkt.x)
|
||||||
if (pkt.p != lastPkt.p) setParameterValue(ktpap, pkt.p);
|
setParameterValue(ktpax, pkt.x);
|
||||||
if (pkt.buttons != lastPkt.buttons) setButtonsValue(pkt.buttons);
|
if (pkt.y != lastPkt.y)
|
||||||
|
setParameterValue(ktpay, pkt.y);
|
||||||
|
if (pkt.z != lastPkt.z)
|
||||||
|
setParameterValue(ktpaz, pkt.z);
|
||||||
|
if (pkt.p != lastPkt.p)
|
||||||
|
setParameterValue(ktpap, pkt.p);
|
||||||
|
if (pkt.buttons != lastPkt.buttons)
|
||||||
|
setButtonsValue(pkt.buttons);
|
||||||
lastPkt = pkt;
|
lastPkt = pkt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setButtonsValue(unsigned long buttonMask)
|
void TabUI::setButtonsValue(unsigned long buttonMask)
|
||||||
{
|
{
|
||||||
if (AButtonWidget.matchesMask(buttonMask))
|
if (AButtonWidget.matchesMask(buttonMask))
|
||||||
setParameterValue(kParameterButtonA, 1.f);
|
setParameterValue(kParameterButtonA, 1.f);
|
||||||
else setParameterValue(kParameterButtonA, 0.f);
|
else
|
||||||
|
setParameterValue(kParameterButtonA, 0.f);
|
||||||
|
|
||||||
if (BButtonWidget.matchesMask(buttonMask))
|
if (BButtonWidget.matchesMask(buttonMask))
|
||||||
setParameterValue(kParameterButtonB, 1.f);
|
setParameterValue(kParameterButtonB, 1.f);
|
||||||
else setParameterValue(kParameterButtonB, 0.f);
|
else
|
||||||
|
setParameterValue(kParameterButtonB, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void buttonClicked(SubWidget* const widget, int ) override
|
void TabUI::buttonClicked(SubWidget *const widget, int)
|
||||||
{
|
{
|
||||||
if (widget == &AButtonWidget) AButtonWidget.setMask(pkt.buttons);
|
if (widget == &AButtonWidget)
|
||||||
if (widget == &BButtonWidget) BButtonWidget.setMask(pkt.buttons);
|
AButtonWidget.setMask(pkt.buttons);
|
||||||
|
if (widget == &BButtonWidget)
|
||||||
|
BButtonWidget.setMask(pkt.buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parameterChanged(uint32_t index, float value) override
|
void TabUI::parameterChanged(uint32_t index, float value)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (index != kParameterTime && index < kParameterCount) {
|
if (index != kParameterTime && index < kParameterCount)
|
||||||
|
{
|
||||||
switch (index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case(ktpax): pkt.x = value;
|
case (ktpax):
|
||||||
case(ktpay): pkt.y = value;
|
pkt.x = value;
|
||||||
case(ktpaz): pkt.z = value;
|
case (ktpay):
|
||||||
case(ktpap): pkt.p = value;
|
pkt.y = value;
|
||||||
|
case (ktpaz):
|
||||||
|
pkt.z = value;
|
||||||
|
case (ktpap):
|
||||||
|
pkt.p = value;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -141,20 +128,20 @@ protected:
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiIdle() override
|
void TabUI::uiIdle()
|
||||||
{
|
{
|
||||||
getTabletData();
|
getTabletData();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onMouse(const MouseEvent& ev) override
|
bool TabUI::onMouse(const MouseEvent &ev)
|
||||||
{
|
{
|
||||||
getTabletData();
|
getTabletData();
|
||||||
repaint();
|
repaint();
|
||||||
return false; // Allow event to propagate.
|
return false; // Allow event to propagate.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onScroll(const ScrollEvent& ev) override
|
bool TabUI::onScroll(const ScrollEvent &ev)
|
||||||
{
|
{
|
||||||
double add;
|
double add;
|
||||||
const uint x = getWidth();
|
const uint x = getWidth();
|
||||||
|
@ -163,19 +150,23 @@ protected:
|
||||||
add = (ev.delta.getY() > 0) ? 1 : -1;
|
add = (ev.delta.getY() > 0) ? 1 : -1;
|
||||||
|
|
||||||
float tabletAspectRatio;
|
float tabletAspectRatio;
|
||||||
if (tab.initialized) tabletAspectRatio = tab.ext.y / tab.ext.x; else tabletAspectRatio = 1.f;
|
if (tab.initialized)
|
||||||
|
tabletAspectRatio = tab.ext.y / tab.ext.x;
|
||||||
|
else
|
||||||
|
tabletAspectRatio = 1.f;
|
||||||
setSize(static_cast<uint>(x + add + 0.5), static_cast<uint>(tabletAspectRatio * (x + add + 0.5)));
|
setSize(static_cast<uint>(x + add + 0.5), static_cast<uint>(tabletAspectRatio * (x + add + 0.5)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabUI::onNanoDisplay()
|
||||||
void onNanoDisplay() override
|
|
||||||
{
|
{
|
||||||
fontSize(15.0f);
|
fontSize(15.0f);
|
||||||
textLineHeight(1.f);
|
textLineHeight(1.f);
|
||||||
|
|
||||||
// Report tablet errors.
|
// Report tablet errors.
|
||||||
if (!tab.initialized) {
|
#ifdef DEBUG
|
||||||
|
if (!tab.initialized)
|
||||||
|
{
|
||||||
const std::string err = std::vformat("Tablet not supported:\n{}",
|
const std::string err = std::vformat("Tablet not supported:\n{}",
|
||||||
std::make_format_args(tab.errormsg));
|
std::make_format_args(tab.errormsg));
|
||||||
beginPath();
|
beginPath();
|
||||||
|
@ -190,14 +181,18 @@ protected:
|
||||||
fillColor(200, 200, 200);
|
fillColor(200, 200, 200);
|
||||||
textBox(0.f, 15.f, 250.f,
|
textBox(0.f, 15.f, 250.f,
|
||||||
std::format("x: {:.3f}\ny: {:.3f}\nz: {:.3f}\np: {:.3f}\nb: {}",
|
std::format("x: {:.3f}\ny: {:.3f}\nz: {:.3f}\np: {:.3f}\nb: {}",
|
||||||
pkt.x, pkt.y, pkt.z, pkt.p, pkt.buttons).c_str(), nullptr);
|
pkt.x, pkt.y, pkt.z, pkt.p, pkt.buttons)
|
||||||
|
.c_str(),
|
||||||
|
nullptr);
|
||||||
closePath();
|
closePath();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Pen position and pressure.
|
// Pen position and pressure.
|
||||||
drawCircle(pkt.x, pkt.y, pkt.z, pkt.p);
|
drawCircle(pkt.x, pkt.y, pkt.z, pkt.p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawCircle(float x, float y, float z, float p) {
|
void TabUI::drawCircle(float x, float y, float z, float p)
|
||||||
|
{
|
||||||
|
|
||||||
static constexpr float circleRadius = 25.f;
|
static constexpr float circleRadius = 25.f;
|
||||||
x *= getWidth();
|
x *= getWidth();
|
||||||
|
@ -233,33 +228,9 @@ protected:
|
||||||
closePath();
|
closePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Tablet context handler
|
|
||||||
Tablet tab;
|
|
||||||
Packet pkt = { 0 };
|
|
||||||
Packet lastPkt = { 0 };
|
|
||||||
|
|
||||||
// Button mapping widgets
|
|
||||||
ButtonMappingWidget AButtonWidget;
|
|
||||||
ButtonMappingWidget BButtonWidget;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Set our UI class as non-copyable and add a leak detector just in case.
|
|
||||||
*/
|
|
||||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabUI)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UI *createUI()
|
UI *createUI()
|
||||||
{
|
{
|
||||||
return new TabUI();
|
return new TabUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
END_NAMESPACE_DISTRHO
|
END_NAMESPACE_DISTRHO
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include "DistrhoUI.hpp"
|
||||||
|
#include "tablet.h"
|
||||||
|
#ifdef DEBUG
|
||||||
|
#include <format>
|
||||||
|
#include <optional>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
|
class ButtonMappingWidget : public NanoSubWidget,
|
||||||
|
public ButtonEventHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ButtonMappingWidget(
|
||||||
|
Widget *parent,
|
||||||
|
float initialSize,
|
||||||
|
float initialX,
|
||||||
|
float initialY,
|
||||||
|
Parameters associatedParameter,
|
||||||
|
ButtonEventHandler::Callback *const callback);
|
||||||
|
void onNanoDisplay() override;
|
||||||
|
bool onMouse(const MouseEvent &ev) override;
|
||||||
|
void setMask(const ButtonMask m) { mask = m; };
|
||||||
|
bool matchesMask(const ButtonMask m) { return isPenPressed = (m && mask == m); };
|
||||||
|
|
||||||
|
bool isClicked;
|
||||||
|
bool isPenPressed;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float x = 0;
|
||||||
|
float y = 0;
|
||||||
|
float size = 0;
|
||||||
|
const Parameters param;
|
||||||
|
ButtonMask mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TabUI : public UI,
|
||||||
|
public ButtonEventHandler::Callback
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit TabUI();
|
||||||
|
|
||||||
|
void buttonClicked(SubWidget *const widget, int) override;
|
||||||
|
void parameterChanged(uint32_t index, float value) override;
|
||||||
|
|
||||||
|
void uiIdle() override;
|
||||||
|
bool onMouse(const MouseEvent &ev) override;
|
||||||
|
bool onScroll(const ScrollEvent &ev) override;
|
||||||
|
void onNanoDisplay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void getTabletData();
|
||||||
|
void setButtonsValue(unsigned long buttonMask);
|
||||||
|
void drawCircle(float x, float y, float z, float p);
|
||||||
|
|
||||||
|
// Tablet context handler
|
||||||
|
Tablet tab;
|
||||||
|
Packet pkt = {0};
|
||||||
|
Packet lastPkt = {0};
|
||||||
|
|
||||||
|
// Button mapping widgets
|
||||||
|
ButtonMappingWidget AButtonWidget;
|
||||||
|
ButtonMappingWidget BButtonWidget;
|
||||||
|
|
||||||
|
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TabUI)
|
||||||
|
};
|
||||||
|
|
||||||
|
END_NAMESPACE_DISTRHO
|
Loading…
Reference in New Issue