comparison DPF-Prymula-audioplugins/dpf/dgl/src/Widget.cpp @ 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-2022 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 #include "WidgetPrivateData.hpp"
18 #include "../TopLevelWidget.hpp"
19 #include "../Window.hpp"
20
21 START_NAMESPACE_DGL
22
23 // --------------------------------------------------------------------------------------------------------------------
24 // Widget
25
26 Widget::Widget(TopLevelWidget* const topLevelWidget)
27 : pData(new PrivateData(this, topLevelWidget)) {}
28
29 Widget::Widget(Widget* const parentWidget)
30 : pData(new PrivateData(this, parentWidget)) {}
31
32 Widget::~Widget()
33 {
34 delete pData;
35 }
36
37 bool Widget::isVisible() const noexcept
38 {
39 return pData->visible;
40 }
41
42 void Widget::setVisible(bool visible)
43 {
44 if (pData->visible == visible)
45 return;
46
47 pData->visible = visible;
48 repaint();
49
50 // FIXME check case of hiding a previously visible widget, does it trigger a repaint?
51 }
52
53 void Widget::show()
54 {
55 setVisible(true);
56 }
57
58 void Widget::hide()
59 {
60 setVisible(false);
61 }
62
63 uint Widget::getWidth() const noexcept
64 {
65 return pData->size.getWidth();
66 }
67
68 uint Widget::getHeight() const noexcept
69 {
70 return pData->size.getHeight();
71 }
72
73 const Size<uint> Widget::getSize() const noexcept
74 {
75 return pData->size;
76 }
77
78 void Widget::setWidth(uint width) noexcept
79 {
80 if (pData->size.getWidth() == width)
81 return;
82
83 ResizeEvent ev;
84 ev.oldSize = pData->size;
85 ev.size = Size<uint>(width, pData->size.getHeight());
86
87 pData->size.setWidth(width);
88 onResize(ev);
89
90 repaint();
91 }
92
93 void Widget::setHeight(uint height) noexcept
94 {
95 if (pData->size.getHeight() == height)
96 return;
97
98 ResizeEvent ev;
99 ev.oldSize = pData->size;
100 ev.size = Size<uint>(pData->size.getWidth(), height);
101
102 pData->size.setHeight(height);
103 onResize(ev);
104
105 repaint();
106 }
107
108 void Widget::setSize(uint width, uint height) noexcept
109 {
110 setSize(Size<uint>(width, height));
111 }
112
113 void Widget::setSize(const Size<uint>& size) noexcept
114 {
115 if (pData->size == size)
116 return;
117
118 ResizeEvent ev;
119 ev.oldSize = pData->size;
120 ev.size = size;
121
122 pData->size = size;
123 onResize(ev);
124
125 repaint();
126 }
127
128 Application& Widget::getApp() const noexcept
129 {
130 DISTRHO_SAFE_ASSERT(pData->topLevelWidget != nullptr);
131 return pData->topLevelWidget->getApp();
132 }
133
134 Window& Widget::getWindow() const noexcept
135 {
136 DISTRHO_SAFE_ASSERT(pData->topLevelWidget != nullptr);
137 return pData->topLevelWidget->getWindow();
138 }
139
140 const GraphicsContext& Widget::getGraphicsContext() const noexcept
141 {
142 DISTRHO_SAFE_ASSERT(pData->topLevelWidget != nullptr);
143 return pData->topLevelWidget->getWindow().getGraphicsContext();
144 }
145
146 TopLevelWidget* Widget::getTopLevelWidget() const noexcept
147 {
148 return pData->topLevelWidget;
149 }
150
151 std::list<SubWidget*> Widget::getChildren() const noexcept
152 {
153 return pData->subWidgets;
154 }
155
156 void Widget::repaint() noexcept
157 {
158 }
159
160 uint Widget::getId() const noexcept
161 {
162 return pData->id;
163 }
164
165 const char* Widget::getName() const noexcept
166 {
167 return pData->name != nullptr ? pData->name : "";
168 }
169
170 void Widget::setId(uint id) noexcept
171 {
172 pData->id = id;
173 }
174
175 void Widget::setName(const char* const name) noexcept
176 {
177 std::free(pData->name);
178 pData->name = strdup(name);
179 }
180
181 bool Widget::onKeyboard(const KeyboardEvent& ev)
182 {
183 return pData->giveKeyboardEventForSubWidgets(ev);
184 }
185
186 bool Widget::onCharacterInput(const CharacterInputEvent& ev)
187 {
188 return pData->giveCharacterInputEventForSubWidgets(ev);
189 }
190
191 bool Widget::onMouse(const MouseEvent& ev)
192 {
193 MouseEvent rev = ev;
194 return pData->giveMouseEventForSubWidgets(rev);
195 }
196
197 bool Widget::onMotion(const MotionEvent& ev)
198 {
199 MotionEvent rev = ev;
200 return pData->giveMotionEventForSubWidgets(rev);
201 }
202
203 bool Widget::onScroll(const ScrollEvent& ev)
204 {
205 ScrollEvent rev = ev;
206 return pData->giveScrollEventForSubWidgets(rev);
207 }
208
209 void Widget::onResize(const ResizeEvent&)
210 {
211 }
212
213 // --------------------------------------------------------------------------------------------------------------------
214
215 END_NAMESPACE_DGL