Dusk Audio Framework
Loading...
Searching...
No Matches
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 DAF_DEFINES_H_INCLUDED
24class UI;
26#endif
27
28START_NAMESPACE_DGL
29
30class 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 DAF Plugin UIs.
44 So anything that a plugin UI might need that does not belong in a simple Widget will go here.
45 */
46class TopLevelWidget : public Widget
47{
48public:
49 /**
50 Constructor.
51 */
52 explicit TopLevelWidget(Window& windowToMapTo);
53
54 /**
55 Destructor.
56 */
57 ~TopLevelWidget() override;
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 /**
70 Set width of this widget's window.
71 @note This will not change the widget's size right away, but be pending on the OS resizing the window
72 */
73 void setWidth(uint width);
74
75 /**
76 Set height of this widget's window.
77 @note This will not change the widget's size right away, but be pending on the OS resizing the window
78 */
79 void setHeight(uint height);
80
81 /**
82 Set size of this widget's window, using @a width and @a height values.
83 @note This will not change the widget's size right away, but be pending on the OS resizing the window
84 */
85 void setSize(uint width, uint height);
86
87 /**
88 Set size of this widget's window.
89 @note This will not change the widget's size right away, but be pending on the OS resizing the window
90 */
91 void setSize(const Size<uint>& size);
92
93 /**
94 TODO document this.
95 */
96 void repaint() noexcept override;
97
98 /**
99 TODO document this.
100 */
101 void repaint(const Rectangle<uint>& rect) noexcept;
102
103 // TODO group stuff after here, convenience functions present in Window class
104 const void* getClipboard(size_t& dataSize);
105 bool setClipboard(const char* mimeType, const void* data, size_t dataSize);
106 bool setCursor(MouseCursor cursor);
107 bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0);
108 bool removeIdleCallback(IdleCallback* callback);
109 double getScaleFactor() const noexcept;
110 void setGeometryConstraints(uint minimumWidth,
111 uint minimumHeight,
112 bool keepAspectRatio = false,
113 bool automaticallyScale = false,
114 bool resizeNowIfAutoScaling = true);
115
116 DAF_DEPRECATED_BY("getApp()")
117 Application& getParentApp() const noexcept { return getApp(); }
118
119 DAF_DEPRECATED_BY("getWindow()")
120 Window& getParentWindow() const noexcept { return getWindow(); }
121
122protected:
123 bool onKeyboard(const KeyboardEvent&) override;
125 bool onMouse(const MouseEvent&) override;
126 bool onMotion(const MotionEvent&) override;
127 bool onScroll(const ScrollEvent&) override;
128
129private:
130 struct PrivateData;
131 PrivateData* const pData;
132 friend class Window;
133#ifdef DAF_DEFINES_H_INCLUDED
134 friend class DAF_NAMESPACE::UI;
135#endif
136 /** @internal */
137 virtual void requestSizeChange(uint width, uint height);
138
139 DAF_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TopLevelWidget)
140};
141
142// -----------------------------------------------------------------------
143
144END_NAMESPACE_DGL
145
146#endif // DGL_TOP_LEVEL_WIDGET_HPP_INCLUDED
Definition Application.hpp:90
Definition Geometry.hpp:612
Definition Geometry.hpp:133
Application & getApp() const noexcept
TopLevelWidget(Window &windowToMapTo)
bool onScroll(const ScrollEvent &) override
void setSize(uint width, uint height)
void setWidth(uint width)
bool onCharacterInput(const CharacterInputEvent &) override
void repaint() noexcept override
void setHeight(uint height)
bool onKeyboard(const KeyboardEvent &) override
bool onMouse(const MouseEvent &) override
Window & getWindow() const noexcept
bool onMotion(const MotionEvent &) override
~TopLevelWidget() override
Definition DafUI.hpp:73
Definition Window.hpp:67
#define END_NAMESPACE_DAF
Definition DafInfo.hpp:996
#define START_NAMESPACE_DAF
Definition DafInfo.hpp:990
Definition Base.hpp:293
Definition Widget.hpp:137
Definition Widget.hpp:92
Definition Widget.hpp:184
Definition Widget.hpp:161
Definition Widget.hpp:208