Browse Source

Make it possible to override Window resize call in plugin UIs

gh-pages
falkTX 11 years ago
parent
commit
58f2cc61a9
3 changed files with 60 additions and 14 deletions
  1. +1
    -0
      distrho/DistrhoUI.hpp
  2. +15
    -0
      distrho/src/DistrhoUI.cpp
  3. +44
    -14
      distrho/src/DistrhoUIInternal.hpp

+ 1
- 0
distrho/DistrhoUI.hpp View File

@@ -81,6 +81,7 @@ protected:
// UI Callbacks (optional) // UI Callbacks (optional)


virtual void d_uiIdle() {} virtual void d_uiIdle() {}
virtual void d_uiReshape(int width, int height);


// ------------------------------------------------------------------- // -------------------------------------------------------------------




+ 15
- 0
distrho/src/DistrhoUI.cpp View File

@@ -94,6 +94,21 @@ void* UI::d_getPluginInstancePointer() const noexcept
} }
#endif #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 END_NAMESPACE_DISTRHO

+ 44
- 14
distrho/src/DistrhoUIInternal.hpp View File

@@ -22,6 +22,10 @@
#include "../../dgl/App.hpp" #include "../../dgl/App.hpp"
#include "../../dgl/Window.hpp" #include "../../dgl/Window.hpp"


using DGL::App;
using DGL::IdleCallback;
using DGL::Window;

START_NAMESPACE_DISTRHO START_NAMESPACE_DISTRHO


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -120,10 +124,45 @@ 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 // UI exporter class


class UIExporter : public DGL::IdleCallback
class UIExporter : public IdleCallback
{ {
public: public:
UIExporter(void* const ptr, const intptr_t winId, UIExporter(void* const ptr, const intptr_t winId,
@@ -131,7 +170,7 @@ public:
void* const dspPtr = nullptr) void* const dspPtr = nullptr)
: glApp(), : glApp(),
glWindow(glApp, winId), glWindow(glApp, winId),
fUi(createUI()),
fUi(glWindow.getUI()),
fData((fUi != nullptr) ? fUi->pData : nullptr) fData((fUi != nullptr) ? fUi->pData : nullptr)
{ {
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,); DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,);
@@ -144,9 +183,8 @@ public:
fData->sendNoteCallbackFunc = sendNoteCall; fData->sendNoteCallbackFunc = sendNoteCall;
fData->uiResizeCallbackFunc = uiResizeCall; fData->uiResizeCallbackFunc = uiResizeCall;


fUi->setSize(fUi->d_getWidth(), fUi->d_getHeight());
glWindow.setSize(fUi->d_getWidth(), fUi->d_getHeight());
glWindow.setResizable(false); glWindow.setResizable(false);
glWindow.setSize(fUi->d_getWidth(), fUi->d_getHeight());


#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
fData->dspPtr = dspPtr; fData->dspPtr = dspPtr;
@@ -156,11 +194,6 @@ public:
#endif #endif
} }


~UIExporter()
{
delete fUi;
}

// ------------------------------------------------------------------- // -------------------------------------------------------------------


const char* getName() const noexcept const char* getName() const noexcept
@@ -256,9 +289,6 @@ public:


void setSize(const uint width, const uint height) void setSize(const uint width, const uint height)
{ {
DISTRHO_SAFE_ASSERT_RETURN(fUi != nullptr,);

fUi->setSize(width, height);
glWindow.setSize(width, height); glWindow.setSize(width, height);
} }


@@ -289,8 +319,8 @@ private:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// DGL Application and Window for this widget // DGL Application and Window for this widget


DGL::App glApp;
DGL::Window glWindow;
App glApp;
PluginWindow glWindow;


// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Widget and DistrhoUI data // Widget and DistrhoUI data


Loading…
Cancel
Save