From ed61894c516c765f17b9f746e11208f4304f51fa Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 15 May 2014 20:49:30 +0100 Subject: [PATCH] Rework StandaloneWindow class --- dgl/StandaloneWindow.hpp | 57 +++++++++++++++++++--------------------- dgl/Window.hpp | 5 ++-- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/dgl/StandaloneWindow.hpp b/dgl/StandaloneWindow.hpp index c98a0be8..4cbca0b1 100644 --- a/dgl/StandaloneWindow.hpp +++ b/dgl/StandaloneWindow.hpp @@ -18,59 +18,56 @@ #define DGL_STANDALONE_WINDOW_HPP_INCLUDED #include "App.hpp" +#include "Widget.hpp" #include "Window.hpp" START_NAMESPACE_DGL // ----------------------------------------------------------------------- -class StandaloneWindow +class StandaloneWindow : public App, + public Window { public: StandaloneWindow() - : fApp(), - fWindow(fApp) - { - } - - App& getApp() noexcept - { - return fApp; - } - - Window& getWindow() noexcept - { - return fWindow; - } + : App(), + Window((App&)*this), + fWidget(nullptr) {} void exec() { - fWindow.show(); - fApp.exec(); + Window::show(); + App::exec(); } - // ------------------------------------------------------------------- - // helpers - - void setResizable(bool yesNo) +protected: + void onReshape(int width, int height) override { - fWindow.setResizable(yesNo); + if (fWidget != nullptr) + { + fWidget->setSize(width, height); + fWidget->onReshape(width, height); + } + Window::onReshape(width, height); } - void setSize(uint width, uint height) +private: + Widget* fWidget; + + void _addWidget(Widget* const widget) override { - fWindow.setSize(width, height); + if (fWidget == nullptr) + fWidget = widget; + Window::_addWidget(widget); } - void setTitle(const char* title) + void _removeWidget(Widget* const widget) override { - fWindow.setTitle(title); + if (fWidget == widget) + fWidget = nullptr; + Window::_removeWidget(widget); } -protected: - App fApp; - Window fWindow; - DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneWindow) }; diff --git a/dgl/Window.hpp b/dgl/Window.hpp index 60c2587f..80e74bc3 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -76,9 +76,10 @@ private: PrivateData* const pData; friend class App; friend class Widget; + friend class StandaloneWindow; - void _addWidget(Widget* const widget); - void _removeWidget(Widget* const widget); + virtual void _addWidget(Widget* const widget); + virtual void _removeWidget(Widget* const widget); void _idle(); DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window)