DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
StandaloneWindow.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DGL_STANDALONE_WINDOW_HPP_INCLUDED
18 #define DGL_STANDALONE_WINDOW_HPP_INCLUDED
19 
20 #include "App.hpp"
21 #include "Widget.hpp"
22 #include "Window.hpp"
23 
24 START_NAMESPACE_DGL
25 
26 // -----------------------------------------------------------------------
27 
28 class StandaloneWindow : public App,
29  public Window
30 {
31 public:
33  : App(),
34  Window((App&)*this),
35  fWidget(nullptr) {}
36 
37  void exec()
38  {
39  Window::show();
40  App::exec();
41  }
42 
43 protected:
44  void onReshape(uint width, uint height) override
45  {
46  if (fWidget != nullptr)
47  fWidget->setSize(width, height);
48  Window::onReshape(width, height);
49  }
50 
51 private:
52  Widget* fWidget;
53 
54  void _addWidget(Widget* widget) override
55  {
56  if (fWidget == nullptr)
57  {
58  fWidget = widget;
59  fWidget->setNeedsFullViewport(true);
60  }
61  Window::_addWidget(widget);
62  }
63 
64  void _removeWidget(Widget* widget) override
65  {
66  if (fWidget == widget)
67  {
68  fWidget->setNeedsFullViewport(false);
69  fWidget = nullptr;
70  }
71  Window::_removeWidget(widget);
72  }
73 
74  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(StandaloneWindow)
75 };
76 
77 // -----------------------------------------------------------------------
78 
79 END_NAMESPACE_DGL
80 
81 #endif // DGL_STANDALONE_WINDOW_HPP_INCLUDED
void exec()
Definition: Window.hpp:30
void setSize(uint width, uint height) noexcept
void setNeedsFullViewport(bool yesNo) noexcept
Definition: StandaloneWindow.hpp:28
Definition: Widget.hpp:51
Definition: App.hpp:41