commit 58f2cc61a99a5ba837097b9420b317eb79fb95eb
parent 51a6f9c3ba792374158b8ed2123844369a8f916d
Author: falkTX <falktx@gmail.com>
Date: Sun, 18 May 2014 02:10:02 +0100
Make it possible to override Window resize call in plugin UIs
Diffstat:
3 files changed, 60 insertions(+), 14 deletions(-)
diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp
@@ -81,6 +81,7 @@ protected:
// UI Callbacks (optional)
virtual void d_uiIdle() {}
+ virtual void d_uiReshape(int width, int height);
// -------------------------------------------------------------------
diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp
@@ -95,5 +95,20 @@ void* UI::d_getPluginInstancePointer() const noexcept
#endif
// -----------------------------------------------------------------------
+// UI Callbacks (optional)
+
+void UI::d_uiReshape(int width, int height)
+{
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, width, height, 0, 0.0f, 1.0f);
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+// -----------------------------------------------------------------------
END_NAMESPACE_DISTRHO
diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp
@@ -22,6 +22,10 @@
#include "../../dgl/App.hpp"
#include "../../dgl/Window.hpp"
+using DGL::App;
+using DGL::IdleCallback;
+using DGL::Window;
+
START_NAMESPACE_DISTRHO
// -----------------------------------------------------------------------
@@ -121,9 +125,44 @@ struct UI::PrivateData {
};
// -----------------------------------------------------------------------
+// Plugin Window, needed to take care of resize properly
+
+class PluginWindow : public Window
+{
+public:
+ PluginWindow(App& app, const intptr_t winId)
+ : Window(app, winId),
+ fUi(createUI())
+ {
+ }
+
+ ~PluginWindow()
+ {
+ delete fUi;
+ }
+
+ UI* getUI() const noexcept
+ {
+ return fUi;
+ }
+
+protected:
+ void onReshape(const int width, const int height) override
+ {
+ DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,);
+
+ fUi->setSize(width, height);
+ fUi->d_uiResize(width, height);
+ }
+
+private:
+ UI* const fUi;
+};
+
+// -----------------------------------------------------------------------
// UI exporter class
-class UIExporter : public DGL::IdleCallback
+class UIExporter : public IdleCallback
{
public:
UIExporter(void* const ptr, const intptr_t winId,
@@ -131,7 +170,7 @@ public:
void* const dspPtr = nullptr)
: glApp(),
glWindow(glApp, winId),
- fUi(createUI()),
+ fUi(glWindow.getUI()),
fData((fUi != nullptr) ? fUi->pData : nullptr)
{
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,);
@@ -144,9 +183,8 @@ public:
fData->sendNoteCallbackFunc = sendNoteCall;
fData->uiResizeCallbackFunc = uiResizeCall;
- fUi->setSize(fUi->d_getWidth(), fUi->d_getHeight());
- glWindow.setSize(fUi->d_getWidth(), fUi->d_getHeight());
glWindow.setResizable(false);
+ glWindow.setSize(fUi->d_getWidth(), fUi->d_getHeight());
#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
fData->dspPtr = dspPtr;
@@ -156,11 +194,6 @@ public:
#endif
}
- ~UIExporter()
- {
- delete fUi;
- }
-
// -------------------------------------------------------------------
const char* getName() const noexcept
@@ -256,9 +289,6 @@ public:
void setSize(const uint width, const uint height)
{
- DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,);
-
- fUi->setSize(width, height);
glWindow.setSize(width, height);
}
@@ -289,8 +319,8 @@ private:
// -------------------------------------------------------------------
// DGL Application and Window for this widget
- DGL::App glApp;
- DGL::Window glWindow;
+ App glApp;
+ PluginWindow glWindow;
// -------------------------------------------------------------------
// Widget and DistrhoUI data