GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/cxx_paintsurfaces.cpp
Date: 2026-09-21 06:26:40
Exec Total Coverage
Lines: 104 241 43.2%
Functions: 18 50 36.0%
Branches: 22 98 22.4%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, 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 1 PaintSurfaceBase::PaintSurfaceBase()
36 1 : Control(&impl.ctrl)
37 {
38 1 Mem::clear(&this->impl, sizeof(this->impl));
39
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_ui_ctrl_init(&this->impl.ctrl);
40 1 }
41 2 PaintSurfaceBase::~PaintSurfaceBase() noexcept
42 {
43
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
2 if (this->isCreated())
44 {
45 this->destroy();
46 }
47 2 }
48
49 1 void PaintSurfaceBase::create(ControlContainer& parent, Position const& pose, uint32_t flags)
50 {
51 static char const* const func_name = "PaintSurfaceBase::create";
52 1 this->failIfCreated(func_name);
53 1 result_t const result = gate_ui_paintsurface_create(&this->impl, *parent, pose.c_impl(), flags, this);
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
55
56 1 this->impl.on_paint = &PaintSurfaceBase::on_paint;
57 1 this->impl.on_resize = &PaintSurfaceBase::on_resize;
58 1 this->impl.on_focus_changed = &PaintSurfaceBase::on_focus_changed;
59
60 1 this->impl.on_mouse_down = &PaintSurfaceBase::on_mouse_down;
61 1 this->impl.on_mouse_up = &PaintSurfaceBase::on_mouse_up;
62 1 this->impl.on_mouse_dblclick = &PaintSurfaceBase::on_mouse_dblclick;
63 1 this->impl.on_mouse_move = &PaintSurfaceBase::on_mouse_move;
64 1 this->impl.on_mouse_scroll = &PaintSurfaceBase::on_mouse_scroll;
65 1 this->impl.on_mouse_enter = &PaintSurfaceBase::on_mouse_enter;
66 1 this->impl.on_mouse_leave = &PaintSurfaceBase::on_mouse_leave;
67 1 this->impl.on_mouse_lost = &PaintSurfaceBase::on_mouse_lost;
68
69 1 this->impl.on_key_down = &PaintSurfaceBase::on_key_down;
70 1 this->impl.on_key_up = &PaintSurfaceBase::on_key_up;
71 1 this->impl.on_key_char = &PaintSurfaceBase::on_key_char;
72
73 1 this->attachNativeControl(&this->impl.ctrl);
74 1 }
75
76 1 void PaintSurfaceBase::redraw()
77 {
78 1 result_t const result = gate_ui_paintsurface_redraw(&this->impl);
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
80 1 }
81
82 1 void PaintSurfaceBase::setCursor(Cursor const& cursor)
83 {
84 1 result_t const result = gate_ui_paintsurface_set_cursor(&this->impl, cursor.c_impl());
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
86 1 }
87
88 3 void PaintSurfaceBase::performAction(enumint_t action, intptr_t param)
89 {
90 3 result_t const result = gate_ui_paintsurface_perform_action(&this->impl, action, param);
91
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATEXX_CHECK_EXCEPTION(result);
92 3 }
93
94 void PaintSurfaceBase::onPaint(Graphics& graphics, Position const& position)
95 {
96
97 }
98 void PaintSurfaceBase::onResize(Size const& size)
99 {
100
101 }
102 void PaintSurfaceBase::onFocusChanged(bool hasFocus)
103 {
104
105 }
106
107 void PaintSurfaceBase::onMouseDown(Point const& point, uint32_t button)
108 {
109
110 }
111 void PaintSurfaceBase::onMouseUp(Point const& point, uint32_t button)
112 {
113
114 }
115 void PaintSurfaceBase::onMouseDblClick(Point const& point, uint32_t button)
116 {
117
118 }
119 void PaintSurfaceBase::onMouseMove(Point const& point, uint32_t button)
120 {
121
122 }
123 void PaintSurfaceBase::onMouseScroll(Point const& point, uint32_t button, int32_t delta)
124 {
125
126 }
127 void PaintSurfaceBase::onMouseEnter()
128 {
129
130 }
131 void PaintSurfaceBase::onMouseLeave()
132 {
133
134 }
135 void PaintSurfaceBase::onMouseLost()
136 {
137
138 }
139
140 void PaintSurfaceBase::onKeyDown(Keyboard::KeyEnum keyCode, uint32_t ctrlKeys)
141 {
142
143 }
144 void PaintSurfaceBase::onKeyUp(Keyboard::KeyEnum keyCode, uint32_t ctrlKeys)
145 {
146
147 }
148 void PaintSurfaceBase::onKeyChar(char_32_t character, uint32_t ctrlKeys)
149 {
150
151 }
152
153
154 2 void PaintSurfaceBase::on_paint(gate_ui_ctrl_t* sender, gate_ui_graphics_t* graph, gate_ui_position_t const* position)
155 {
156 2 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
157
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ps != NULL)
158 {
159 try
160 {
161
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 Graphics graphics(*graph);
162 2 Position pos(*position);
163
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 ps->onPaint(graphics, pos);
164 }
165 catch (...) {}
166 }
167 2 }
168 void PaintSurfaceBase::on_resize(gate_ui_ctrl_t* sender, gate_ui_size_t const* size)
169 {
170 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
171 if (ps != NULL)
172 {
173 try
174 {
175 Size sz(*size);
176 ps->onResize(sz);
177 }
178 catch (...) {}
179 }
180 }
181 void PaintSurfaceBase::on_focus_changed(gate_ui_ctrl_t* sender, gate_bool_t hasfocus)
182 {
183 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
184 if (ps != NULL)
185 {
186 try
187 {
188 ps->onFocusChanged(hasfocus);
189 }
190 catch (...) {}
191 }
192 }
193
194 2 void PaintSurfaceBase::on_mouse_down(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
195 {
196 2 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
197
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ps != NULL)
198 {
199 try
200 {
201 2 Point pnt(*point);
202
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 ps->onMouseDown(pnt, button);
203 }
204 catch (...) {}
205 }
206 2 }
207 2 void PaintSurfaceBase::on_mouse_up(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
208 {
209 2 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
210
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (ps != NULL)
211 {
212 try
213 {
214 2 Point pnt(*point);
215
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 ps->onMouseUp(pnt, button);
216 }
217 catch (...) {}
218 }
219 2 }
220 void PaintSurfaceBase::on_mouse_dblclick(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
221 {
222 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
223 if (ps != NULL)
224 {
225 try
226 {
227 Point pnt(*point);
228 ps->onMouseDblClick(pnt, button);
229 }
230 catch (...) {}
231 }
232 }
233 void PaintSurfaceBase::on_mouse_move(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button)
234 {
235 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
236 if (ps != NULL)
237 {
238 try
239 {
240 Point pnt(*point);
241 ps->onMouseMove(pnt, button);
242 }
243 catch (...) {}
244 }
245 }
246 void PaintSurfaceBase::on_mouse_scroll(gate_ui_ctrl_t* sender, gate_ui_point_t const* point, gate_uint32_t button, gate_int32_t delta)
247 {
248 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
249 if (ps != NULL)
250 {
251 try
252 {
253 Point pnt(*point);
254 ps->onMouseScroll(pnt, button, delta);
255 }
256 catch (...) {}
257 }
258 }
259 void PaintSurfaceBase::on_mouse_enter(gate_ui_ctrl_t* sender)
260 {
261 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
262 if (ps != NULL)
263 {
264 try
265 {
266 ps->onMouseEnter();
267 }
268 catch (...) {}
269 }
270 }
271 void PaintSurfaceBase::on_mouse_leave(gate_ui_ctrl_t* sender)
272 {
273 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
274 if (ps != NULL)
275 {
276 try
277 {
278 ps->onMouseLeave();
279 }
280 catch (...) {}
281 }
282 }
283 void PaintSurfaceBase::on_mouse_lost(gate_ui_ctrl_t* sender)
284 {
285 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
286 if (ps != NULL)
287 {
288 try
289 {
290 ps->onMouseLost();
291 }
292 catch (...) {}
293 }
294 }
295
296 1 void PaintSurfaceBase::on_key_down(gate_ui_ctrl_t* sender, gate_input_keycode_t keycode, gate_input_keystates_t ctrlkeys)
297 {
298 1 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
299
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (ps != NULL)
300 {
301 try
302 {
303
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ps->onKeyDown(Keyboard::KeyEnum(keycode), ctrlkeys);
304 }
305 catch (...) {}
306 }
307 1 }
308 1 void PaintSurfaceBase::on_key_up(gate_ui_ctrl_t* sender, gate_input_keycode_t keycode, gate_input_keystates_t ctrlkeys)
309 {
310 1 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
311
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (ps != NULL)
312 {
313 try
314 {
315
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 ps->onKeyUp(Keyboard::KeyEnum(keycode), ctrlkeys);
316 }
317 catch (...) {}
318 }
319 1 }
320 void PaintSurfaceBase::on_key_char(gate_ui_ctrl_t* sender, gate_char32_t character, gate_input_keystates_t ctrlkeys)
321 {
322 PaintSurfaceBase* ps = static_cast<PaintSurfaceBase*>(gate_ui_ctrl_get_userparam(sender));
323 if (ps != NULL)
324 {
325 try
326 {
327 ps->onKeyChar(character, ctrlkeys);
328 }
329 catch (...) {}
330 }
331 }
332
333
334
335
336
337
338
339
340
341
342 1 PaintSurface::PaintSurface()
343 1 : PaintSurfaceBase()
344 {
345
346 1 }
347
348 2 PaintSurface::~PaintSurface() noexcept
349 {
350
351 2 }
352
353 2 void PaintSurface::onPaint(Graphics& graphics, Position const& position)
354 {
355 2 PaintEventArg arg(graphics, position);
356
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 this->PaintEvent(this, &arg);
357 2 }
358 void PaintSurface::onResize(Size const& size)
359 {
360 ResizeEventArg arg;
361 arg.NewSize = size;
362 this->ResizeEvent(this, &arg);
363 }
364 void PaintSurface::onFocusChanged(bool hasFocus)
365 {
366 FocusEventArg arg;
367 arg.HasFocus = hasFocus;
368 this->FocusEvent(this, &arg);
369 }
370
371 2 void PaintSurface::onMouseDown(Point const& point, uint32_t button)
372 {
373 2 MousePositionEventArg arg;
374 2 arg.Position = point;
375 2 arg.Button = button;
376 2 arg.Delta = 0;
377
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 this->MouseDownEvent(this, &arg);
378 2 }
379 2 void PaintSurface::onMouseUp(Point const& point, uint32_t button)
380 {
381 2 MousePositionEventArg arg;
382 2 arg.Position = point;
383 2 arg.Button = button;
384 2 arg.Delta = 0;
385
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 this->MouseUpEvent(this, &arg);
386 2 }
387 void PaintSurface::onMouseDblClick(Point const& point, uint32_t button)
388 {
389 MousePositionEventArg arg;
390 arg.Position = point;
391 arg.Button = button;
392 arg.Delta = 0;
393 this->MouseDblClickEvent(this, &arg);
394 }
395 void PaintSurface::onMouseMove(Point const& point, uint32_t button)
396 {
397 MousePositionEventArg arg;
398 arg.Position = point;
399 arg.Button = button;
400 arg.Delta = 0;
401 this->MouseMoveEvent(this, &arg);
402 }
403 void PaintSurface::onMouseScroll(Point const& point, uint32_t button, int32_t delta)
404 {
405 MousePositionEventArg arg;
406 arg.Position = point;
407 arg.Button = button;
408 arg.Delta = delta;
409 this->MouseScrollEvent(this, &arg);
410 }
411 void PaintSurface::onMouseEnter()
412 {
413 MouseEventArg arg;
414 this->MouseEnterEvent(this, &arg);
415 }
416 void PaintSurface::onMouseLeave()
417 {
418 MouseEventArg arg;
419 this->MouseLeaveEvent(this, &arg);
420
421 }
422 void PaintSurface::onMouseLost()
423 {
424 MouseEventArg arg;
425 this->MouseLostEvent(this, &arg);
426 }
427
428 1 void PaintSurface::onKeyDown(Keyboard::KeyEnum keyCode, uint32_t keyStates)
429 {
430 KeyEventArg arg;
431 1 arg.KeyCode = keyCode;
432 1 arg.CtrlKeys = keyStates;
433 1 arg.Character = 0;
434
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->KeyDownEvent(this, &arg);
435 1 }
436 1 void PaintSurface::onKeyUp(Keyboard::KeyEnum keyCode, uint32_t keyStates)
437 {
438 KeyEventArg arg;
439 1 arg.KeyCode = keyCode;
440 1 arg.CtrlKeys = keyStates;
441 1 arg.Character = 0;
442
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->KeyUpEvent(this, &arg);
443 1 }
444 void PaintSurface::onKeyChar(char_32_t character, uint32_t ctrlKeys)
445 {
446 KeyEventArg arg;
447 arg.KeyCode = Keyboard::Key_Unknown;
448 arg.CtrlKeys = ctrlKeys;
449 arg.Character = character;
450 this->KeyCharEvent(this, &arg);
451 }
452
453 } // end of namespace ui
454 } // end of namespace gate
455
456