DISTRHO Plugin Framework
TopLevelWidget.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 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_TOP_LEVEL_WIDGET_HPP_INCLUDED
18 #define DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
19 
20 #include "Widget.hpp"
21 
22 #ifdef DISTRHO_DEFINES_H_INCLUDED
23 START_NAMESPACE_DISTRHO
24 class UI;
25 END_NAMESPACE_DISTRHO
26 #endif
27 
28 START_NAMESPACE_DGL
29 
30 class Window;
31 
32 // -----------------------------------------------------------------------
33 
34 /**
35  Top-Level Widget class.
36 
37  This is the only Widget class that is allowed to be used directly on a Window.
38 
39  This widget takes the full size of the Window it is mapped to.
40  Sub-widgets can be added on top of this top-level widget, by creating them with this class as parent.
41  Doing so allows for custom position and sizes.
42 
43  This class is used as the type for DPF Plugin UIs.
44  So anything that a plugin UI might need that does not belong in a simple Widget will go here.
45  */
46 class TopLevelWidget : public Widget
47 {
48 public:
49  /**
50  Constructor.
51  */
52  explicit TopLevelWidget(Window& windowToMapTo);
53 
54  /**
55  Destructor.
56  */
57  virtual ~TopLevelWidget();
58 
59  /**
60  Get the application associated with this top-level widget's window.
61  */
62  Application& getApp() const noexcept;
63 
64  /**
65  Get the window associated with this top-level widget.
66  */
67  Window& getWindow() const noexcept;
68 
69  // TODO group stuff after here, convenience functions present in Window class
70  bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0);
71  bool removeIdleCallback(IdleCallback* callback);
72  double getScaleFactor() const noexcept;
73  void repaint() noexcept;
74  void repaint(const Rectangle<uint>& rect) noexcept;
75  void setGeometryConstraints(uint minimumWidth,
76  uint minimumHeight,
77  bool keepAspectRatio = false,
78  bool automaticallyScale = false);
79 
80  DISTRHO_DEPRECATED_BY("getApp()")
81  Application& getParentApp() const noexcept { return getApp(); }
82 
83  DISTRHO_DEPRECATED_BY("getWindow()")
84  Window& getParentWindow() const noexcept { return getWindow(); }
85 
86 private:
87  struct PrivateData;
88  PrivateData* const pData;
89  friend class Window;
90 #ifdef DISTRHO_DEFINES_H_INCLUDED
91  friend class DISTRHO_NAMESPACE::UI;
92 #endif
93 
94  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TopLevelWidget)
95 };
96 
97 // -----------------------------------------------------------------------
98 
99 END_NAMESPACE_DGL
100 
101 #endif // DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
TopLevelWidget::repaint
void repaint() noexcept
TopLevelWidget::getApp
Application & getApp() const noexcept
Window
Definition: Window.hpp:50
Rectangle
Definition: Geometry.hpp:30
Application
Definition: Application.hpp:34
TopLevelWidget::getWindow
Window & getWindow() const noexcept
UI
Definition: DistrhoUI.hpp:67
TopLevelWidget::~TopLevelWidget
virtual ~TopLevelWidget()
IdleCallback
Definition: Base.hpp:159
TopLevelWidget
Definition: TopLevelWidget.hpp:46
Widget
Definition: Widget.hpp:53