DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 12b54c705695a1cdbd7c8163bb22571a25991827
parent 4d6774fb0f1a2d8b81d574e21af16de245765c4c
Author: falkTX <falktx@falktx.com>
Date:   Fri,  3 Sep 2021 10:32:24 +0100

Sort out situation with some standalone windows

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/StandaloneWindow.hpp | 18++++++++++++++++--
Mdgl/Window.hpp | 9+++++++++
Mdgl/src/ImageBaseWidgets.cpp | 20++++++++++++--------
Mdgl/src/Window.cpp | 16++++++++++++----
Mdgl/src/pugl.cpp | 4++--
Mdgl/src/pugl.hpp | 2+-
Mtests/Demo.cpp | 1+
Mtests/FileBrowserDialog.cpp | 7+++++--
Mtests/widgets/ExampleColorWidget.hpp | 1+
Mtests/widgets/ExampleImagesWidget.hpp | 1+
Mtests/widgets/ExampleRectanglesWidget.hpp | 4++++
Mtests/widgets/ExampleShapesWidget.hpp | 4++++
Mtests/widgets/ExampleTextWidget.hpp | 4++++
13 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp @@ -33,14 +33,25 @@ public: */ StandaloneWindow(Application& app) : Window(app), - TopLevelWidget((Window&)*this) {} + TopLevelWidget((Window&)*this), + sgc((Window&)*this) {} /** Constructor with parent window, typically used to run as modal. */ StandaloneWindow(Application& app, Window& parentWindow) : Window(app, parentWindow), - TopLevelWidget((Window&)*this) {} + TopLevelWidget((Window&)*this), + sgc((Window&)*this) {} + + /** + Clear current graphics context. + Must be called at the end of your StandaloneWindow constructor. + */ + void done() + { + sgc.done(); + } /** Overloaded functions to ensure they apply to the Window class. @@ -66,6 +77,9 @@ public: bool keepAspectRatio = false, bool automaticallyScale = false) { Window::setGeometryConstraints(minimumWidth, minimumHeight, keepAspectRatio, automaticallyScale); } +private: + ScopedGraphicsContext sgc; + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneWindow) }; diff --git a/dgl/Window.hpp b/dgl/Window.hpp @@ -127,12 +127,21 @@ public: */ struct ScopedGraphicsContext { + /** Constructor that will make the @a window graphics context the current one */ explicit ScopedGraphicsContext(Window& window); + + /** Desstructor for clearing current context, if not done yet */ ~ScopedGraphicsContext(); + + /** Early context clearing, useful for standalone windows. */ + void done(); + DISTRHO_DECLARE_NON_COPYABLE(ScopedGraphicsContext) DISTRHO_PREVENT_HEAP_ALLOCATION + private: Window& window; + bool active; }; /** diff --git a/dgl/src/ImageBaseWidgets.cpp b/dgl/src/ImageBaseWidgets.cpp @@ -29,11 +29,13 @@ ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(Window& parentWindow, cons setResizable(false); setTitle("About"); - if (image.isInvalid()) - return; + if (image.isValid()) + { + setSize(image.getSize()); + setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + } - setSize(image.getSize()); - setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + done(); } template <class ImageType> @@ -44,11 +46,13 @@ ImageBaseAboutWindow<ImageType>::ImageBaseAboutWindow(TopLevelWidget* const pare setResizable(false); setTitle("About"); - if (image.isInvalid()) - return; + if (image.isValid()) + { + setSize(image.getSize()); + setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + } - setSize(image.getSize()); - setGeometryConstraints(image.getWidth(), image.getHeight(), true, true); + done(); } template <class ImageType> diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp @@ -24,14 +24,22 @@ START_NAMESPACE_DGL // ScopedGraphicsContext Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) - : window(win) + : window(win), + active(puglBackendEnter(window.pData->view)) {} + +Window::ScopedGraphicsContext::~ScopedGraphicsContext() { - puglBackendEnter(window.pData->view); + if (active) + puglBackendLeave(window.pData->view); } -Window::ScopedGraphicsContext::~ScopedGraphicsContext() +void Window::ScopedGraphicsContext::done() { - puglBackendLeave(window.pData->view); + if (active) + { + active = false; + puglBackendLeave(window.pData->view); + } } // ----------------------------------------------------------------------- diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp @@ -159,9 +159,9 @@ START_NAMESPACE_DGL // -------------------------------------------------------------------------------------------------------------------- // expose backend enter -void puglBackendEnter(PuglView* const view) +bool puglBackendEnter(PuglView* const view) { - view->backend->enter(view, NULL); + return view->backend->enter(view, NULL) == PUGL_SUCCESS; } // -------------------------------------------------------------------------------------------------------------------- diff --git a/dgl/src/pugl.hpp b/dgl/src/pugl.hpp @@ -48,7 +48,7 @@ USE_NAMESPACE_DGL PUGL_BEGIN_DECLS // expose backend enter -PUGL_API void +PUGL_API bool puglBackendEnter(PuglView* view); // expose backend leave diff --git a/tests/Demo.cpp b/tests/Demo.cpp @@ -435,6 +435,7 @@ public: resizer = new ResizeHandle(this); curPageChanged(0); + done(); } protected: diff --git a/tests/FileBrowserDialog.cpp b/tests/FileBrowserDialog.cpp @@ -37,6 +37,11 @@ public: #ifndef DGL_NO_SHARED_RESOURCES loadSharedResources(); #endif + setResizable(true); + setSize(500, 200); + setGeometryConstraints(500, 200, true, false); + setTitle("FileBrowserDialog"); + done(); } protected: @@ -170,8 +175,6 @@ int main() Application app(true); NanoFilePicker win(app); - win.setSize(500, 200); - win.setTitle("FileBrowserDialog"); win.show(); app.exec(); diff --git a/tests/widgets/ExampleColorWidget.hpp b/tests/widgets/ExampleColorWidget.hpp @@ -165,6 +165,7 @@ ExampleColorWidget<StandaloneWindow>::ExampleColorWidget(Application& app) { setSize(300, 300); addIdleCallback(this); + done(); } typedef ExampleColorWidget<SubWidget> ExampleColorSubWidget; diff --git a/tests/widgets/ExampleImagesWidget.hpp b/tests/widgets/ExampleImagesWidget.hpp @@ -115,6 +115,7 @@ public: BaseWidget::setSize(500, 400); app.addIdleCallback(this); + done(); } protected: diff --git a/tests/widgets/ExampleRectanglesWidget.hpp b/tests/widgets/ExampleRectanglesWidget.hpp @@ -37,22 +37,26 @@ class ExampleRectanglesWidget : public BaseWidget public: static constexpr const char* const kExampleWidgetName = "Rectangles"; + // SubWidget explicit ExampleRectanglesWidget(Widget* const parentWidget) : BaseWidget(parentWidget) { init(); } + // TopLevelWidget explicit ExampleRectanglesWidget(Window& windowToMapTo) : BaseWidget(windowToMapTo) { init(); } + // StandaloneWindow explicit ExampleRectanglesWidget(Application& app) : BaseWidget(app) { init(); + done(); } void init() diff --git a/tests/widgets/ExampleShapesWidget.hpp b/tests/widgets/ExampleShapesWidget.hpp @@ -40,22 +40,26 @@ class ExampleShapesWidget : public BaseWidget public: static constexpr const char* const kExampleWidgetName = "Shapes"; + // SubWidget explicit ExampleShapesWidget(Widget* const parentWidget) : BaseWidget(parentWidget) { this->setSize(300, 300); } + // TopLevelWidget explicit ExampleShapesWidget(Window& windowToMapTo) : BaseWidget(windowToMapTo) { this->setSize(300, 300); } + // StandaloneWindow explicit ExampleShapesWidget(Application& app) : BaseWidget(app) { this->setSize(300, 300); + done(); } protected: diff --git a/tests/widgets/ExampleTextWidget.hpp b/tests/widgets/ExampleTextWidget.hpp @@ -62,6 +62,7 @@ protected: } }; +// SubWidget template<> inline ExampleTextWidget<NanoSubWidget>::ExampleTextWidget(Widget* const parent) : NanoSubWidget(parent) @@ -70,6 +71,7 @@ ExampleTextWidget<NanoSubWidget>::ExampleTextWidget(Widget* const parent) setSize(500, 300); } +// TopLevelWidget template<> inline ExampleTextWidget<NanoTopLevelWidget>::ExampleTextWidget(Window& windowToMapTo) : NanoTopLevelWidget(windowToMapTo) @@ -78,12 +80,14 @@ ExampleTextWidget<NanoTopLevelWidget>::ExampleTextWidget(Window& windowToMapTo) setSize(500, 300); } +// StandaloneWindow template<> inline ExampleTextWidget<NanoStandaloneWindow>::ExampleTextWidget(Application& app) : NanoStandaloneWindow(app) { loadSharedResources(); setSize(500, 300); + done(); } template class ExampleTextWidget<NanoSubWidget>;