-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
SubWidget.hpp
185 lines (148 loc) · 5.25 KB
/
SubWidget.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with
* or without fee is hereby granted, provided that the above copyright notice and this
* permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
* TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef DGL_SUBWIDGET_HPP_INCLUDED
#define DGL_SUBWIDGET_HPP_INCLUDED
#include "Widget.hpp"
START_NAMESPACE_DGL
// --------------------------------------------------------------------------------------------------------------------
/**
Sub-Widget class.
This class is the main entry point for creating any reusable widgets from within DGL.
It can be freely positioned from within a parent widget, thus being named subwidget.
Many subwidgets can share the same parent, and subwidgets themselves can also have its own subwidgets.
It is subwidgets all the way down.
TODO check absolute vs relative position and see what makes more sense.
@see CairoSubWidget
*/
class SubWidget : public Widget
{
public:
/**
Constructor.
*/
explicit SubWidget(Widget* parentWidget);
/**
Destructor.
*/
~SubWidget() override;
/**
Check if this widget contains the point defined by @a x and @a y.
*/
// TODO rename as containsRelativePos
template<typename T>
bool contains(T x, T y) const noexcept;
/**
Check if this widget contains the point @a pos.
*/
// TODO rename as containsRelativePos
template<typename T>
bool contains(const Point<T>& pos) const noexcept;
/**
Get absolute X.
*/
int getAbsoluteX() const noexcept;
/**
Get absolute Y.
*/
int getAbsoluteY() const noexcept;
/**
Get absolute position.
*/
Point<int> getAbsolutePos() const noexcept;
/**
Get absolute area of this subwidget.
This is the same as `Rectangle<int>(getAbsolutePos(), getSize());`
@see getConstrainedAbsoluteArea()
*/
Rectangle<int> getAbsoluteArea() const noexcept;
/**
Get absolute area of this subwidget, with special consideration for not allowing negative values.
@see getAbsoluteArea()
*/
Rectangle<uint> getConstrainedAbsoluteArea() const noexcept;
/**
Set absolute X.
*/
void setAbsoluteX(int x) noexcept;
/**
Set absolute Y.
*/
void setAbsoluteY(int y) noexcept;
/**
Set absolute position using @a x and @a y values.
*/
void setAbsolutePos(int x, int y) noexcept;
/**
Set absolute position.
*/
void setAbsolutePos(const Point<int>& pos) noexcept;
/**
Get the margin currently in use for widget coordinates.
By default this value is (0,0).
*/
Point<int> getMargin() const noexcept;
/**
Set a margin to be used for widget coordinates using @a x and @a y values.
*/
void setMargin(int x, int y) noexcept;
/**
Set a margin to be used for widget coordinates.
*/
void setMargin(const Point<int>& offset) noexcept;
/**
Get parent Widget, as passed in the constructor.
*/
Widget* getParentWidget() const noexcept;
/**
Request repaint of this subwidget's area to the window this widget belongs to.
*/
void repaint() noexcept override;
/**
Pushes this widget to the "bottom" of the parent widget.
Makes the widget behave as if it was the first to be registered on the parent widget, thus being "on bottom".
*/
virtual void toBottom();
/**
Bring this widget to the "front" of the parent widget.
Makes the widget behave as if it was the last to be registered on the parent widget, thus being "in front".
*/
virtual void toFront();
/**
Indicate that this subwidget will draw out of bounds, and thus needs the entire viewport available for drawing.
*/
void setNeedsFullViewportDrawing(bool needsFullViewportForDrawing = true);
/**
Indicate that this subwidget will always draw at its own internal size and needs scaling to fit target size.
*/
void setNeedsViewportScaling(bool needsViewportScaling = true, double autoScaleFactor = 0.0);
/**
Indicate that this subwidget should not be drawn on screen, typically because it is managed by something else.
*/
void setSkipDrawing(bool skipDrawing = true);
protected:
/**
A function called when the subwidget's absolute position is changed.
*/
virtual void onPositionChanged(const PositionChangedEvent&);
private:
struct PrivateData;
PrivateData* const pData;
friend class Widget;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SubWidget)
};
// --------------------------------------------------------------------------------------------------------------------
END_NAMESPACE_DGL
#endif // DGL_SUBWIDGET_HPP_INCLUDED