commit 2ed5e0a66577f7f32f97cc4811d469b2226eaf83
parent 636835f63cb1b7ffa5278c4f206a0bcb95fd6b5a
Author: falkTX <falktx@falktx.com>
Date: Wed, 27 Mar 2019 16:23:57 +0100
Handle scaling of plugins via host (TESTING)
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
13 files changed, 162 insertions(+), 101 deletions(-)
diff --git a/dgl/Window.hpp b/dgl/Window.hpp
@@ -77,7 +77,7 @@ public:
explicit Window(Application& app);
explicit Window(Application& app, Window& parent);
- explicit Window(Application& app, intptr_t parentId, bool resizable);
+ explicit Window(Application& app, intptr_t parentId, double scaling, bool resizable);
virtual ~Window();
void show();
@@ -113,7 +113,6 @@ public:
void setTransientWinId(uintptr_t winId);
double getScaling() const noexcept;
- void setScaling(double scaling) noexcept;
bool getIgnoringKeyRepeat() const noexcept;
void setIgnoringKeyRepeat(bool ignore) noexcept;
@@ -136,6 +135,9 @@ protected:
virtual void fileBrowserSelected(const char* filename);
#endif
+ // internal
+ void _setAutoScaling(double scaling) noexcept;
+
private:
struct PrivateData;
PrivateData* const pData;
diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp
@@ -93,6 +93,7 @@ struct Window::PrivateData {
fWidth(1),
fHeight(1),
fScaling(1.0),
+ fAutoScaling(1.0),
fTitle(nullptr),
fWidgets(),
fModal(),
@@ -124,6 +125,7 @@ struct Window::PrivateData {
fWidth(1),
fHeight(1),
fScaling(1.0),
+ fAutoScaling(1.0),
fTitle(nullptr),
fWidgets(),
fModal(parent.pData),
@@ -156,7 +158,7 @@ struct Window::PrivateData {
#endif
}
- PrivateData(Application& app, Window* const self, const intptr_t parentId, const bool resizable)
+ PrivateData(Application& app, Window* const self, const intptr_t parentId, const double scaling, const bool resizable)
: fApp(app),
fSelf(self),
fView(puglInit()),
@@ -166,7 +168,8 @@ struct Window::PrivateData {
fUsingEmbed(parentId != 0),
fWidth(1),
fHeight(1),
- fScaling(1.0),
+ fScaling(scaling),
+ fAutoScaling(1.0),
fTitle(nullptr),
fWidgets(),
fModal(),
@@ -565,6 +568,7 @@ struct Window::PrivateData {
void setGeometryConstraints(uint width, uint height, bool aspect)
{
+ // Did you forget to set DISTRHO_UI_USER_RESIZABLE ?
DISTRHO_SAFE_ASSERT_RETURN(fResizable,);
fView->min_width = width;
@@ -711,11 +715,12 @@ struct Window::PrivateData {
return fScaling;
}
- void setScaling(double scaling) noexcept
+ void setAutoScaling(const double scaling) noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(scaling > 0.0,);
+ d_stdout("setAutoScaling called with %f", scaling);
- fScaling = scaling;
+ fAutoScaling = scaling;
}
// -------------------------------------------------------------------
@@ -783,7 +788,7 @@ struct Window::PrivateData {
FOR_EACH_WIDGET(it)
{
Widget* const widget(*it);
- widget->pData->display(fWidth, fHeight, fScaling, false);
+ widget->pData->display(fWidth, fHeight, fAutoScaling, false);
}
fSelf->onDisplayAfter();
@@ -853,8 +858,8 @@ struct Window::PrivateData {
if (fModal.childFocus != nullptr)
return fModal.childFocus->focus();
- x /= fScaling;
- y /= fScaling;
+ x /= fAutoScaling;
+ y /= fAutoScaling;
Widget::MouseEvent ev;
ev.button = button;
@@ -880,8 +885,8 @@ struct Window::PrivateData {
if (fModal.childFocus != nullptr)
return;
- x /= fScaling;
- y /= fScaling;
+ x /= fAutoScaling;
+ y /= fAutoScaling;
Widget::MotionEvent ev;
ev.mod = static_cast<Modifier>(puglGetModifiers(fView));
@@ -905,10 +910,10 @@ struct Window::PrivateData {
if (fModal.childFocus != nullptr)
return;
- x /= fScaling;
- y /= fScaling;
- dx /= fScaling;
- dy /= fScaling;
+ x /= fAutoScaling;
+ y /= fAutoScaling;
+ dx /= fAutoScaling;
+ dy /= fAutoScaling;
Widget::ScrollEvent ev;
ev.delta = Point<float>(dx, dy);
@@ -1060,6 +1065,7 @@ struct Window::PrivateData {
uint fWidth;
uint fHeight;
double fScaling;
+ double fAutoScaling;
char* fTitle;
std::list<Widget*> fWidgets;
@@ -1166,8 +1172,8 @@ Window::Window(Application& app)
Window::Window(Application& app, Window& parent)
: pData(new PrivateData(app, this, parent)) {}
-Window::Window(Application& app, intptr_t parentId, bool resizable)
- : pData(new PrivateData(app, this, parentId, resizable)) {}
+Window::Window(Application& app, intptr_t parentId, double scaling, bool resizable)
+ : pData(new PrivateData(app, this, parentId, scaling, resizable)) {}
Window::~Window()
{
@@ -1358,11 +1364,6 @@ double Window::getScaling() const noexcept
return pData->getScaling();
}
-void Window::setScaling(double scaling) noexcept
-{
- pData->setScaling(scaling);
-}
-
bool Window::getIgnoringKeyRepeat() const noexcept
{
return pData->getIgnoringKeyRepeat();
@@ -1392,6 +1393,11 @@ const GraphicsContext& Window::getGraphicsContext() const noexcept
return context;
}
+void Window::_setAutoScaling(double scaling) noexcept
+{
+ pData->setAutoScaling(scaling);
+}
+
void Window::_addWidget(Widget* const widget)
{
pData->addWidget(widget);
diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp
@@ -69,7 +69,7 @@ public:
*/
virtual ~UI();
-#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+#if DISTRHO_UI_USER_RESIZABLE && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
/**
Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically.
@see Window::setGeometryConstraints(uint,uint,bool)
@@ -138,6 +138,13 @@ public:
*/
static const char* getNextBundlePath() noexcept;
+ /**
+ Get the scale factor that will be used for the next UI.
+ @note: This function is only valid during createUI(),
+ it will return null when called from anywhere else.
+ */
+ static double getNextScaleFactor() noexcept;
+
# if DISTRHO_PLUGIN_HAS_EMBED_UI
/**
Get the Window Id that will be used for the next created window.
diff --git a/distrho/src/DistrhoPluginJack.cpp b/distrho/src/DistrhoPluginJack.cpp
@@ -82,6 +82,16 @@ static void initSignalHandler()
// -----------------------------------------------------------------------
#if DISTRHO_PLUGIN_HAS_UI
+// TODO
+static double getDesktopScaleFactor() noexcept
+{
+ return 1.0;
+}
+#endif
+
+// -----------------------------------------------------------------------
+
+#if DISTRHO_PLUGIN_HAS_UI
class PluginJack : public IdleCallback
#else
class PluginJack
@@ -91,7 +101,7 @@ public:
PluginJack(jack_client_t* const client)
: fPlugin(this, writeMidiCallback),
#if DISTRHO_PLUGIN_HAS_UI
- fUI(this, 0, nullptr, setParameterValueCallback, setStateCallback, nullptr, setSizeCallback, fPlugin.getInstancePointer()),
+ fUI(this, 0, nullptr, setParameterValueCallback, setStateCallback, nullptr, setSizeCallback, getDesktopScaleFactor(), fPlugin.getInstancePointer()),
#endif
fClient(client)
{
diff --git a/distrho/src/DistrhoPluginVST.cpp b/distrho/src/DistrhoPluginVST.cpp
@@ -161,12 +161,12 @@ public:
class UIVst
{
public:
- UIVst(const audioMasterCallback audioMaster, AEffect* const effect, ParameterCheckHelper* const uiHelper, PluginExporter* const plugin, const intptr_t winId)
+ UIVst(const audioMasterCallback audioMaster, AEffect* const effect, ParameterCheckHelper* const uiHelper, PluginExporter* const plugin, const intptr_t winId, const float scaleFactor)
: fAudioMaster(audioMaster),
fEffect(effect),
fUiHelper(uiHelper),
fPlugin(plugin),
- fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, plugin->getInstancePointer()),
+ fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, scaleFactor, plugin->getInstancePointer()),
fShouldCaptureVstKeys(false)
{
// FIXME only needed for windows?
@@ -575,8 +575,11 @@ public:
else
{
d_lastUiSampleRate = fPlugin.getSampleRate();
+
+ // TODO
+ const float scaleFactor = 1.0f;
- UIExporter tmpUI(nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, fPlugin.getInstancePointer());
+ UIExporter tmpUI(nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, scaleFactor, fPlugin.getInstancePointer());
fVstRect.right = tmpUI.getWidth();
fVstRect.bottom = tmpUI.getHeight();
tmpUI.quit();
@@ -595,8 +598,11 @@ public:
}
# endif
d_lastUiSampleRate = fPlugin.getSampleRate();
+
+ // TODO
+ const float scaleFactor = 1.0f;
- fVstUI = new UIVst(fAudioMaster, fEffect, this, &fPlugin, (intptr_t)ptr);
+ fVstUI = new UIVst(fAudioMaster, fEffect, this, &fPlugin, (intptr_t)ptr, scaleFactor);
# if DISTRHO_PLUGIN_WANT_FULL_STATE
// Update current state from plugin side
diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp
@@ -27,8 +27,9 @@ START_NAMESPACE_DISTRHO
double d_lastUiSampleRate = 0.0;
void* d_lastUiDspPtr = nullptr;
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
-uintptr_t g_nextWindowId = 0;
const char* g_nextBundlePath = nullptr;
+double g_nextScaleFactor = 1.0;
+uintptr_t g_nextWindowId = 0;
#else
Window* d_lastUiWindow = nullptr;
#endif
@@ -57,7 +58,7 @@ UI::~UI()
delete pData;
}
-#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+#if DISTRHO_UI_USER_RESIZABLE && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale)
{
DISTRHO_SAFE_ASSERT_RETURN(minWidth > 0,);
@@ -67,7 +68,13 @@ void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRa
pData->minWidth = minWidth;
pData->minHeight = minHeight;
- getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio);
+ Window& window(getParentWindow());
+
+ const double uiScaleFactor = window.getScaling();
+ window.setGeometryConstraints(minWidth * uiScaleFactor, minHeight * uiScaleFactor, keepAspectRatio);
+
+ if (d_isNotZero(uiScaleFactor - 1.0))
+ setSize(getWidth() * uiScaleFactor, getHeight() * uiScaleFactor);
}
#endif
@@ -122,6 +129,11 @@ const char* UI::getNextBundlePath() noexcept
return g_nextBundlePath;
}
+double UI::getNextScaleFactor() noexcept
+{
+ return g_nextScaleFactor;
+}
+
# if DISTRHO_PLUGIN_HAS_EMBED_UI
uintptr_t UI::getNextWindowId() noexcept
{
diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp
@@ -37,11 +37,13 @@ START_NAMESPACE_DISTRHO
extern double d_lastUiSampleRate;
extern void* d_lastUiDspPtr;
-#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+extern const char* g_nextBundlePath;
+extern double g_nextScaleFactor;
+extern uintptr_t g_nextWindowId;
+#else
extern Window* d_lastUiWindow;
#endif
-extern uintptr_t g_nextWindowId;
-extern const char* g_nextBundlePath;
// -----------------------------------------------------------------------
// UI callbacks
@@ -149,15 +151,17 @@ struct UI::PrivateData {
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
static inline
-UI* createUiWrapper(void* const dspPtr, const uintptr_t winId, const char* const bundlePath)
+UI* createUiWrapper(void* const dspPtr, const uintptr_t winId, const double scaleFactor, const char* const bundlePath)
{
- d_lastUiDspPtr = dspPtr;
- g_nextWindowId = winId;
- g_nextBundlePath = bundlePath;
- UI* const ret = createUI();
- d_lastUiDspPtr = nullptr;
- g_nextWindowId = 0;
- g_nextBundlePath = nullptr;
+ d_lastUiDspPtr = dspPtr;
+ g_nextWindowId = winId;
+ g_nextScaleFactor = scaleFactor;
+ g_nextBundlePath = bundlePath;
+ UI* const ret = createUI();
+ d_lastUiDspPtr = nullptr;
+ g_nextWindowId = 0;
+ g_nextScaleFactor = 1.0;
+ g_nextBundlePath = nullptr;
return ret;
}
#else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI
@@ -175,8 +179,8 @@ UI* createUiWrapper(void* const dspPtr, Window* const window)
class UIExporterWindow : public Window
{
public:
- UIExporterWindow(Application& app, const intptr_t winId, void* const dspPtr)
- : Window(app, winId, DISTRHO_UI_USER_RESIZABLE),
+ UIExporterWindow(Application& app, const intptr_t winId, const double scaleFactor, void* const dspPtr)
+ : Window(app, winId, scaleFactor, DISTRHO_UI_USER_RESIZABLE),
fUI(createUiWrapper(dspPtr, this)),
fIsReady(false)
{
@@ -214,7 +218,7 @@ protected:
{
const double scaleHorizontal = static_cast<double>(width) / static_cast<double>(pData->minWidth);
const double scaleVertical = static_cast<double>(height) / static_cast<double>(pData->minHeight);
- setScaling(scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical);
+ _setAutoScaling(scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical);
}
pData->resizeInProgress = true;
@@ -254,13 +258,14 @@ public:
const setStateFunc setStateCall,
const sendNoteFunc sendNoteCall,
const setSizeFunc setSizeCall,
+ const float scaleFactor = 1.0f,
void* const dspPtr = nullptr,
const char* const bundlePath = nullptr)
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
- : fUI(createUiWrapper(dspPtr, winId, bundlePath)),
+ : fUI(createUiWrapper(dspPtr, winId, scaleFactor, bundlePath)),
#else
: glApp(),
- glWindow(glApp, winId, dspPtr),
+ glWindow(glApp, winId, scaleFactor, dspPtr),
fChangingSize(false),
fUI(glWindow.getUI()),
#endif
diff --git a/distrho/src/DistrhoUILV2.cpp b/distrho/src/DistrhoUILV2.cpp
@@ -53,8 +53,8 @@ public:
UiLv2(const char* const bundlePath, const intptr_t winId,
const LV2_Options_Option* options, const LV2_URID_Map* const uridMap, const LV2UI_Resize* const uiResz, const LV2UI_Touch* uiTouch,
const LV2UI_Controller controller, const LV2UI_Write_Function writeFunc,
- LV2UI_Widget* const widget, void* const dspPtr)
- : fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, dspPtr, bundlePath),
+ const float scaleFactor, LV2UI_Widget* const widget, void* const dspPtr)
+ : fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, scaleFactor, dspPtr, bundlePath),
fUridMap(uridMap),
fUiResize(uiResz),
fUiTouch(uiTouch),
@@ -434,22 +434,30 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char* uri,
}
#endif
+ float scaleFactor = 1.0f;
const intptr_t winId((intptr_t)parentId);
if (options != nullptr)
{
+ const LV2_URID uridAtomFloat(uridMap->map(uridMap->handle, LV2_ATOM__Float));
const LV2_URID uridSampleRate(uridMap->map(uridMap->handle, LV2_PARAMETERS__sampleRate));
+ const LV2_URID uridScaleFactor(uridMap->map(uridMap->handle, "urn:carla:scale"));
for (int i=0; options[i].key != 0; ++i)
{
- if (options[i].key == uridSampleRate)
+ /**/ if (options[i].key == uridSampleRate)
{
- if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Float))
+ if (options[i].type == uridAtomFloat)
d_lastUiSampleRate = *(const float*)options[i].value;
else
d_stderr("Host provides UI sample-rate but has wrong value type");
-
- break;
+ }
+ else if (options[i].key == uridScaleFactor)
+ {
+ if (options[i].type == uridAtomFloat)
+ scaleFactor = *(const float*)options[i].value;
+ else
+ d_stderr("Host provides UI scale factor but has wrong value type");
}
}
}
@@ -460,7 +468,7 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char* uri,
d_lastUiSampleRate = 44100.0;
}
- return new UiLv2(bundlePath, winId, options, uridMap, uiResize, uiTouch, controller, writeFunction, widget, instance);
+ return new UiLv2(bundlePath, winId, options, uridMap, uiResize, uiTouch, controller, writeFunction, scaleFactor, widget, instance);
}
#define uiPtr ((UiLv2*)ui)
diff --git a/examples/Meters/ExampleUIMeters.cpp b/examples/Meters/ExampleUIMeters.cpp
@@ -43,6 +43,7 @@ public:
fOutLeft(0.0f),
fOutRight(0.0f)
{
+ setGeometryConstraints(32, 128, false);
}
protected:
diff --git a/examples/Parameters/DistrhoPluginInfo.h b/examples/Parameters/DistrhoPluginInfo.h
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2019 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
@@ -26,5 +26,6 @@
#define DISTRHO_PLUGIN_NUM_INPUTS 2
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
+#define DISTRHO_UI_USER_RESIZABLE 1
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
diff --git a/examples/Parameters/ExampleUIParameters.cpp b/examples/Parameters/ExampleUIParameters.cpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2019 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
@@ -28,21 +28,18 @@ using DGL::Rectangle;
class ExampleUIParameters : public UI
{
public:
- /**
- For simplicity this UI will be of constant size.
- */
- static const int kUIWidth = 512;
- static const int kUIHeight = 512;
-
/* constructor */
ExampleUIParameters()
- : UI(kUIWidth, kUIHeight)
+ : UI(512, 512)
{
/**
Initialize all our parameters to their defaults.
In this example all default values are false, so we can simply zero them.
*/
std::memset(fParamGrid, 0, sizeof(bool)*9);
+
+ // TODO explain why this is here
+ setGeometryConstraints(128, 128, true);
}
protected:
@@ -105,15 +102,18 @@ protected:
*/
void onDisplay() override
{
+ const uint width = getWidth();
+ const uint height = getHeight();
+
Rectangle<int> r;
- r.setWidth(kUIWidth/3 - 6);
- r.setHeight(kUIHeight/3 - 6);
+ r.setWidth(width/3 - 6);
+ r.setHeight(height/3 - 6);
// draw left, center and right columns
for (int i=0; i<3; ++i)
{
- r.setX(3 + i*kUIWidth/3);
+ r.setX(3 + i*width/3);
// top
r.setY(3);
@@ -126,7 +126,7 @@ protected:
r.draw();
// middle
- r.setY(3 + kUIHeight/3);
+ r.setY(3 + height/3);
if (fParamGrid[3+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -136,7 +136,7 @@ protected:
r.draw();
// bottom
- r.setY(3 + kUIHeight*2/3);
+ r.setY(3 + height*2/3);
if (fParamGrid[6+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -157,15 +157,18 @@ protected:
if (ev.button != 1 || ! ev.press)
return false;
+ const uint width = getWidth();
+ const uint height = getHeight();
+
Rectangle<int> r;
- r.setWidth(kUIWidth/3 - 6);
- r.setHeight(kUIHeight/3 - 6);
+ r.setWidth(width/3 - 6);
+ r.setHeight(height/3 - 6);
// handle left, center and right columns
for (int i=0; i<3; ++i)
{
- r.setX(3 + i*kUIWidth/3);
+ r.setX(3 + i*width/3);
// top
r.setY(3);
@@ -187,7 +190,7 @@ protected:
}
// middle
- r.setY(3 + kUIHeight/3);
+ r.setY(3 + height/3);
if (r.contains(ev.pos))
{
@@ -200,7 +203,7 @@ protected:
}
// bottom
- r.setY(3 + kUIHeight*2/3);
+ r.setY(3 + height*2/3);
if (r.contains(ev.pos))
{
diff --git a/examples/States/DistrhoPluginInfo.h b/examples/States/DistrhoPluginInfo.h
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2019 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
@@ -21,12 +21,13 @@
#define DISTRHO_PLUGIN_NAME "States"
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/States"
-#define DISTRHO_PLUGIN_HAS_UI 1
-#define DISTRHO_PLUGIN_IS_RT_SAFE 1
-#define DISTRHO_PLUGIN_NUM_INPUTS 2
-#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
-#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
-#define DISTRHO_PLUGIN_WANT_STATE 1
+#define DISTRHO_PLUGIN_HAS_UI 1
+#define DISTRHO_PLUGIN_IS_RT_SAFE 1
+#define DISTRHO_PLUGIN_NUM_INPUTS 2
+#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
+#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
+#define DISTRHO_PLUGIN_WANT_STATE 1
#define DISTRHO_PLUGIN_WANT_FULL_STATE 1
+#define DISTRHO_UI_USER_RESIZABLE 1
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED
diff --git a/examples/States/ExampleUIStates.cpp b/examples/States/ExampleUIStates.cpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2019 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
@@ -24,12 +24,6 @@ class ExampleUIParameters : public UI
{
public:
/**
- For simplicity this UI will be of constant size.
- */
- static const int kUIWidth = 512;
- static const int kUIHeight = 512;
-
- /**
Get key name from an index.
*/
static const char* getStateKeyFromIndex(const uint32_t index) noexcept
@@ -52,14 +46,15 @@ public:
/* constructor */
ExampleUIParameters()
- : UI()
+ : UI(512, 512)
{
/**
Initialize the grid to all off per default.
*/
std::memset(fParamGrid, 0, sizeof(bool)*9);
- setSize(kUIWidth, kUIHeight);
+ // TODO explain why this is here
+ setGeometryConstraints(128, 128, true);
}
protected:
@@ -77,8 +72,6 @@ protected:
*/
void programLoaded(uint32_t index) override
{
- d_stdout("UI programLoaded %i", index);
-
switch (index)
{
case 0:
@@ -148,15 +141,18 @@ protected:
*/
void onDisplay() override
{
+ const uint width = getWidth();
+ const uint height = getHeight();
+
Rectangle<int> r;
- r.setWidth(kUIWidth/3 - 6);
- r.setHeight(kUIHeight/3 - 6);
+ r.setWidth(width/3 - 6);
+ r.setHeight(height/3 - 6);
// draw left, center and right columns
for (int i=0; i<3; ++i)
{
- r.setX(3 + i*kUIWidth/3);
+ r.setX(3 + i*width/3);
// top
r.setY(3);
@@ -169,7 +165,7 @@ protected:
r.draw();
// middle
- r.setY(3 + kUIHeight/3);
+ r.setY(3 + height/3);
if (fParamGrid[3+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -179,7 +175,7 @@ protected:
r.draw();
// bottom
- r.setY(3 + kUIHeight*2/3);
+ r.setY(3 + height*2/3);
if (fParamGrid[6+i])
glColor3f(0.8f, 0.5f, 0.3f);
@@ -200,15 +196,18 @@ protected:
if (ev.button != 1 || ! ev.press)
return false;
+ const uint width = getWidth();
+ const uint height = getHeight();
+
Rectangle<int> r;
- r.setWidth(kUIWidth/3 - 6);
- r.setHeight(kUIHeight/3 - 6);
+ r.setWidth(width/3 - 6);
+ r.setHeight(height/3 - 6);
// handle left, center and right columns
for (int i=0; i<3; ++i)
{
- r.setX(3 + i*kUIWidth/3);
+ r.setX(3 + i*width/3);
// top
r.setY(3);
@@ -230,7 +229,7 @@ protected:
}
// middle
- r.setY(3 + kUIHeight/3);
+ r.setY(3 + height/3);
if (r.contains(ev.pos))
{
@@ -243,7 +242,7 @@ protected:
}
// bottom
- r.setY(3 + kUIHeight*2/3);
+ r.setY(3 + height*2/3);
if (r.contains(ev.pos))
{