comparison DPF-Prymula-audioplugins/dpf/dgl/SubWidget.hpp @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents
children
comparison
equal deleted inserted replaced
2:cf2cb71d31dd 3:84e66ea83026
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_SUBWIDGET_HPP_INCLUDED
18 #define DGL_SUBWIDGET_HPP_INCLUDED
19
20 #include "Widget.hpp"
21
22 START_NAMESPACE_DGL
23
24 // --------------------------------------------------------------------------------------------------------------------
25
26 /**
27 Sub-Widget class.
28
29 This class is the main entry point for creating any reusable widgets from within DGL.
30 It can be freely positioned from within a parent widget, thus being named subwidget.
31
32 Many subwidgets can share the same parent, and subwidgets themselves can also have its own subwidgets.
33 It is subwidgets all the way down.
34
35 TODO check absolute vs relative position and see what makes more sense.
36
37 @see CairoSubWidget
38 */
39 class SubWidget : public Widget
40 {
41 public:
42 /**
43 Constructor.
44 */
45 explicit SubWidget(Widget* parentWidget);
46
47 /**
48 Destructor.
49 */
50 ~SubWidget() override;
51
52 /**
53 Check if this widget contains the point defined by @a x and @a y.
54 */
55 // TODO rename as containsRelativePos
56 template<typename T>
57 bool contains(T x, T y) const noexcept;
58
59 /**
60 Check if this widget contains the point @a pos.
61 */
62 // TODO rename as containsRelativePos
63 template<typename T>
64 bool contains(const Point<T>& pos) const noexcept;
65
66 /**
67 Get absolute X.
68 */
69 int getAbsoluteX() const noexcept;
70
71 /**
72 Get absolute Y.
73 */
74 int getAbsoluteY() const noexcept;
75
76 /**
77 Get absolute position.
78 */
79 Point<int> getAbsolutePos() const noexcept;
80
81 /**
82 Get absolute area of this subwidget.
83 This is the same as `Rectangle<int>(getAbsolutePos(), getSize());`
84 @see getConstrainedAbsoluteArea()
85 */
86 Rectangle<int> getAbsoluteArea() const noexcept;
87
88 /**
89 Get absolute area of this subwidget, with special consideration for not allowing negative values.
90 @see getAbsoluteArea()
91 */
92 Rectangle<uint> getConstrainedAbsoluteArea() const noexcept;
93
94 /**
95 Set absolute X.
96 */
97 void setAbsoluteX(int x) noexcept;
98
99 /**
100 Set absolute Y.
101 */
102 void setAbsoluteY(int y) noexcept;
103
104 /**
105 Set absolute position using @a x and @a y values.
106 */
107 void setAbsolutePos(int x, int y) noexcept;
108
109 /**
110 Set absolute position.
111 */
112 void setAbsolutePos(const Point<int>& pos) noexcept;
113
114 /**
115 Get the margin currently in use for widget coordinates.
116 By default this value is (0,0).
117 */
118 Point<int> getMargin() const noexcept;
119
120 /**
121 Set a margin to be used for widget coordinates using @a x and @a y values.
122 */
123 void setMargin(int x, int y) noexcept;
124
125 /**
126 Set a margin to be used for widget coordinates.
127 */
128 void setMargin(const Point<int>& offset) noexcept;
129
130 /**
131 Get parent Widget, as passed in the constructor.
132 */
133 Widget* getParentWidget() const noexcept;
134
135 /**
136 Request repaint of this subwidget's area to the window this widget belongs to.
137 */
138 void repaint() noexcept override;
139
140 /**
141 Pushes this widget to the "bottom" of the parent widget.
142 Makes the widget behave as if it was the first to be registered on the parent widget, thus being "on bottom".
143 */
144 virtual void toBottom();
145
146 /**
147 Bring this widget to the "front" of the parent widget.
148 Makes the widget behave as if it was the last to be registered on the parent widget, thus being "in front".
149 */
150 virtual void toFront();
151
152 /**
153 Indicate that this subwidget will draw out of bounds, and thus needs the entire viewport available for drawing.
154 */
155 void setNeedsFullViewportDrawing(bool needsFullViewportForDrawing = true);
156
157 /**
158 Indicate that this subwidget will always draw at its own internal size and needs scaling to fit target size.
159 */
160 void setNeedsViewportScaling(bool needsViewportScaling = true, double autoScaleFactor = 0.0);
161
162 /**
163 Indicate that this subwidget should not be drawn on screen, typically because it is managed by something else.
164 */
165 void setSkipDrawing(bool skipDrawing = true);
166
167 protected:
168 /**
169 A function called when the subwidget's absolute position is changed.
170 */
171 virtual void onPositionChanged(const PositionChangedEvent&);
172
173 private:
174 struct PrivateData;
175 PrivateData* const pData;
176 friend class Widget;
177 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget)
178 };
179
180 // --------------------------------------------------------------------------------------------------------------------
181
182 END_NAMESPACE_DGL
183
184 #endif // DGL_SUBWIDGET_HPP_INCLUDED
185