GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_paintsurfaces.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 237 0.0%
Functions: 0 49 0.0%
Branches: 0 96 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/ui/paintsurfaces.hpp"
30
31 namespace gate
32 {
33 namespace ui
34 {
35 PaintSurfaceBase::PaintSurfaceBase()
36 : Control(&impl.ctrl)
37 {
38 Mem::clear(&this->impl, sizeof(this->impl));
39 gate_ui_ctrl_init(&this->impl.ctrl);
40 }
41 PaintSurfaceBase::~PaintSurfaceBase() noexcept
42 {
43 if (this->isCreated())
44 {
45 this->destroy();
46 }
47 }
48
49 void PaintSurfaceBase::create(ControlContainer& parent, Position const& pose, uint32_t flags)
50 {
51 static char const* const func_name = "PaintSurfaceBase::create";
52 this->failIfCreated(func_name);
53 result_t result = gate_ui_paintsurface_create(&this->impl, *parent, pose.c_impl(), flags, this);
54 GATEXX_CHECK_ERROR(result);
55
56 this->impl.on_paint = &PaintSurfaceBase::on_paint;
57 this->impl.on_resize = &PaintSurfaceBase::on_resize;
58 this->impl.on_focus_changed = &PaintSurfaceBase::on_focus_changed;
59
60 this->impl.on_mouse_down = &PaintSurfaceBase::on_mouse_down;
61 this->impl.on_mouse_up = &PaintSurfaceBase::on_mouse_up;
62 this->impl.on_mouse_dblclick = &PaintSurfaceBase::on_mouse_dblclick;
63 this->impl.on_mouse_move = &PaintSurfaceBase::on_mouse_move;
64 this->impl.on_mouse_scroll = &PaintSurfaceBase::on_mouse_scroll;
65 this->impl.on_mouse_enter = &PaintSurfaceBase::on_mouse_enter;
66 this->impl.on_mouse_leave = &PaintSurfaceBase::on_mouse_leave;
67 this->impl.on_mouse_lost = &PaintSurfaceBase::on_mouse_lost;
68
69 this->impl.on_key_down = &PaintSurfaceBase::on_key_down;
70 this->impl.on_key_up = &PaintSurfaceBase::on_key_up;
71 this->impl.on_key_char = &PaintSurfaceBase::on_key_char;
72
73 this->attachNativeControl(&this->impl.ctrl);
74 }
75
76 void PaintSurfaceBase::redraw()
77 {
78 result_t result = gate_ui_paintsurface_redraw(&this->impl);
79 GATEXX_CHECK_EXCEPTION(result);
80 }
81
82 void PaintSurfaceBase::setCursor(Cursor& cursor)
83 {
84 result_t result = gate_ui_paintsurface_set_cursor(&this->impl, cursor.c_impl());
85 GATEXX_CHECK_EXCEPTION(result);
86 }
87
88 void PaintSurfaceBase::onPaint(Graphics& graphics, Position const& position)
89 {
90
91 }
92 void PaintSurfaceBase::onResize(Size const& size)
93 {
94
95 }
96 void PaintSurfaceBase::onFocusChanged(bool hasFocus)
97 {
98
99 }
100
101 void PaintSurfaceBase::onMouseDown(Point const& point, uint32_t button)
102 {
103
104 }
105 void PaintSurfaceBase::onMouseUp(Point const& point, uint32_t button)
106 {
107
108 }
109 void PaintSurfaceBase::onMouseDblClick(Point const& point, uint32_t button)
110 {
111
112 }
113 void PaintSurfaceBase::onMouseMove(Point const& point, uint32_t button)
114 {
115
116 }
117 void PaintSurfaceBase::onMouseScroll(Point const& point, uint32_t button, int32_t delta)
118 {
119
120 }
121 void PaintSurfaceBase::onMouseEnter()
122 {
123
124 }
125 void PaintSurfaceBase::onMouseLeave()
126 {
127
128 }
129 void PaintSurfaceBase::onMouseLost()
130 {
131
132 }
133
134 void PaintSurfaceBase::onKeyDown(Keyboard::KeyEnum keyCode, uint32_t ctrlKeys)
135 {
136
137 }
138 void PaintSurfaceBase::onKeyUp(Keyboard::KeyEnum keyCode, uint32_t ctrlKeys)
139 {
140
141 }
142 void PaintSurfaceBase::onKeyChar(char_32_t character, uint32_t ctrlKeys)
143 {
144
145 }
146
147
148 void PaintSurfaceBase::on_paint(gate_ui_ctrl_t* sender, gate_ui_graphics_t* graph, gate_ui_position_t const* position)
149 {
150 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
151 if (ps != NULL)
152 {
153 try
154 {
155 Graphics graphics(*graph);
156 Position pos(*position);
157 ps->onPaint(graphics, pos);
158 }
159 catch (...) {}
160 }
161 }
162 void PaintSurfaceBase::on_resize(gate_ui_ctrl_t* sender, gate_ui_size_t const* size)
163 {
164 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
165 if (ps != NULL)
166 {
167 try
168 {
169 Size sz(*size);
170 ps->onResize(sz);
171 }
172 catch (...) {}
173 }
174 }
175 void PaintSurfaceBase::on_focus_changed(gate_ui_ctrl_t* sender, gate_bool_t hasfocus)
176 {
177 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
178 if (ps != NULL)
179 {
180 try
181 {
182 ps->onFocusChanged(hasfocus);
183 }
184 catch (...) {}
185 }
186 }
187
188 void PaintSurfaceBase::on_mouse_down(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
189 {
190 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
191 if (ps != NULL)
192 {
193 try
194 {
195 Point pnt(*point);
196 ps->onMouseDown(pnt, button);
197 }
198 catch (...) {}
199 }
200 }
201 void PaintSurfaceBase::on_mouse_up(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
202 {
203 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
204 if (ps != NULL)
205 {
206 try
207 {
208 Point pnt(*point);
209 ps->onMouseUp(pnt, button);
210 }
211 catch (...) {}
212 }
213 }
214 void PaintSurfaceBase::on_mouse_dblclick(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
215 {
216 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
217 if (ps != NULL)
218 {
219 try
220 {
221 Point pnt(*point);
222 ps->onMouseDblClick(pnt, button);
223 }
224 catch (...) {}
225 }
226 }
227 void PaintSurfaceBase::on_mouse_move(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
228 {
229 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
230 if (ps != NULL)
231 {
232 try
233 {
234 Point pnt(*point);
235 ps->onMouseMove(pnt, button);
236 }
237 catch (...) {}
238 }
239 }
240 void PaintSurfaceBase::on_mouse_scroll(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button, gate_int32_t delta)
241 {
242 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
243 if (ps != NULL)
244 {
245 try
246 {
247 Point pnt(*point);
248 ps->onMouseScroll(pnt, button, delta);
249 }
250 catch (...) {}
251 }
252 }
253 void PaintSurfaceBase::on_mouse_enter(gate_ui_ctrl_t* sender)
254 {
255 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
256 if (ps != NULL)
257 {
258 try
259 {
260 ps->onMouseEnter();
261 }
262 catch (...) {}
263 }
264 }
265 void PaintSurfaceBase::on_mouse_leave(gate_ui_ctrl_t* sender)
266 {
267 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
268 if (ps != NULL)
269 {
270 try
271 {
272 ps->onMouseLeave();
273 }
274 catch (...) {}
275 }
276 }
277 void PaintSurfaceBase::on_mouse_lost(gate_ui_ctrl_t* sender)
278 {
279 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
280 if (ps != NULL)
281 {
282 try
283 {
284 ps->onMouseLost();
285 }
286 catch (...) {}
287 }
288 }
289
290 void PaintSurfaceBase::on_key_down(gate_ui_ctrl_t* sender, gate_input_keycode_t keycode, gate_input_keystates_t ctrlkeys)
291 {
292 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
293 if (ps != NULL)
294 {
295 try
296 {
297 ps->onKeyDown(Keyboard::KeyEnum(keycode), ctrlkeys);
298 }
299 catch (...) {}
300 }
301 }
302 void PaintSurfaceBase::on_key_up(gate_ui_ctrl_t* sender, gate_input_keycode_t keycode, gate_input_keystates_t ctrlkeys)
303 {
304 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
305 if (ps != NULL)
306 {
307 try
308 {
309 ps->onKeyUp(Keyboard::KeyEnum(keycode), ctrlkeys);
310 }
311 catch (...) {}
312 }
313 }
314 void PaintSurfaceBase::on_key_char(gate_ui_ctrl_t* sender, gate_char32_t character, gate_input_keystates_t ctrlkeys)
315 {
316 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
317 if (ps != NULL)
318 {
319 try
320 {
321 ps->onKeyChar(character, ctrlkeys);
322 }
323 catch (...) {}
324 }
325 }
326
327
328
329
330
331
332
333
334
335
336 PaintSurface::PaintSurface()
337 : PaintSurfaceBase()
338 {
339
340 }
341
342 PaintSurface::~PaintSurface() noexcept
343 {
344
345 }
346
347 void PaintSurface::onPaint(Graphics& graphics, Position const& position)
348 {
349 PaintEventArg arg(graphics, position);
350 this->PaintEvent(this, &arg);
351 }
352 void PaintSurface::onResize(Size const& size)
353 {
354 ResizeEventArg arg;
355 arg.NewSize = size;
356 this->ResizeEvent(this, &arg);
357 }
358 void PaintSurface::onFocusChanged(bool hasFocus)
359 {
360 FocusEventArg arg;
361 arg.HasFocus = hasFocus;
362 this->FocusEvent(this, &arg);
363 }
364
365 void PaintSurface::onMouseDown(Point const& point, uint32_t button)
366 {
367 MousePositionEventArg arg;
368 arg.Position = point;
369 arg.Button = button;
370 arg.Delta = 0;
371 this->MouseDownEvent(this, &arg);
372 }
373 void PaintSurface::onMouseUp(Point const& point, uint32_t button)
374 {
375 MousePositionEventArg arg;
376 arg.Position = point;
377 arg.Button = button;
378 arg.Delta = 0;
379 this->MouseUpEvent(this, &arg);
380 }
381 void PaintSurface::onMouseDblClick(Point const& point, uint32_t button)
382 {
383 MousePositionEventArg arg;
384 arg.Position = point;
385 arg.Button = button;
386 arg.Delta = 0;
387 this->MouseDblClickEvent(this, &arg);
388 }
389 void PaintSurface::onMouseMove(Point const& point, uint32_t button)
390 {
391 MousePositionEventArg arg;
392 arg.Position = point;
393 arg.Button = button;
394 arg.Delta = 0;
395 this->MouseMoveEvent(this, &arg);
396 }
397 void PaintSurface::onMouseScroll(Point const& point, uint32_t button, int32_t delta)
398 {
399 MousePositionEventArg arg;
400 arg.Position = point;
401 arg.Button = button;
402 arg.Delta = delta;
403 this->MouseScrollEvent(this, &arg);
404 }
405 void PaintSurface::onMouseEnter()
406 {
407 MouseEventArg arg;
408 this->MouseEnterEvent(this, &arg);
409 }
410 void PaintSurface::onMouseLeave()
411 {
412 MouseEventArg arg;
413 this->MouseLeaveEvent(this, &arg);
414
415 }
416 void PaintSurface::onMouseLost()
417 {
418 MouseEventArg arg;
419 this->MouseLostEvent(this, &arg);
420 }
421
422 void PaintSurface::onKeyDown(Keyboard::KeyEnum keyCode, uint32_t keyStates)
423 {
424 KeyEventArg arg;
425 arg.KeyCode = keyCode;
426 arg.CtrlKeys = keyStates;
427 arg.Character = 0;
428 this->KeyDownEvent(this, &arg);
429 }
430 void PaintSurface::onKeyUp(Keyboard::KeyEnum keyCode, uint32_t keyStates)
431 {
432 KeyEventArg arg;
433 arg.KeyCode = keyCode;
434 arg.CtrlKeys = keyStates;
435 arg.Character = 0;
436 this->KeyUpEvent(this, &arg);
437 }
438 void PaintSurface::onKeyChar(char_32_t character, uint32_t ctrlKeys)
439 {
440 KeyEventArg arg;
441 arg.KeyCode = Keyboard::Key_Unknown;
442 arg.CtrlKeys = ctrlKeys;
443 arg.Character = character;
444 this->KeyCharEvent(this, &arg);
445 }
446
447 } // end of namespace ui
448 } // end of namespace gate
449
450