GCC Code Coverage Report


Directory: src/gate/
File: src/gate/ui/paintsurfaces.hpp
Date: 2026-09-21 06:26:40
Exec Total Coverage
Lines: 3 3 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

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 /** @file
30 * @brief Paint surface controls
31 * @ingroup gateui_cpp
32 */
33
34 #ifndef GATE_UI_PAINTSURFACES_HPP_INCLUDED
35 #define GATE_UI_PAINTSURFACES_HPP_INCLUDED
36
37 #include "gate/ui/gate_ui_api.hpp"
38 #include "gate/ui/paintsurfaces.h"
39 #include "gate/ui/gateui.hpp"
40 #include "gate/ui/graphics.hpp"
41 #include "gate/inputs.hpp"
42
43 namespace gate
44 {
45 namespace ui
46 {
47 /// @brief Graphics painting surface control base class
48 class GATE_UI_CPP_API PaintSurfaceBase : public Control
49 {
50 public:
51
52 PaintSurfaceBase();
53 virtual ~PaintSurfaceBase() noexcept;
54
55 void create(ControlContainer& parent, Position const& pose,
56 uint32_t flags = (PaintSurfaceBase::Flag_Enabled | PaintSurfaceBase::Flag_Visible));
57
58 void redraw();
59
60 void setCursor(Cursor const& cursor);
61
62 void performAction(enumint_t action, intptr_t param = 0);
63
64 protected:
65 virtual void onPaint(Graphics& graphics, Position const& position);
66 virtual void onResize(Size const& size);
67 virtual void onFocusChanged(bool hasFocus);
68
69 virtual void onMouseDown(Point const& point, uint32_t button);
70 virtual void onMouseUp(Point const& point, uint32_t button);
71 virtual void onMouseDblClick(Point const& point, uint32_t button);
72 virtual void onMouseMove(Point const& point, uint32_t button);
73 virtual void onMouseScroll(Point const& point, uint32_t button, int32_t delta);
74 virtual void onMouseEnter();
75 virtual void onMouseLeave();
76 virtual void onMouseLost();
77
78 virtual void onKeyDown(Keyboard::KeyEnum keyCode, Keyboard::states_t keyStates);
79 virtual void onKeyUp(Keyboard::KeyEnum keyCode, Keyboard::states_t keyStates);
80 virtual void onKeyChar(char_32_t character, Keyboard::states_t ctrlKeys);
81 private:
82 gate_ui_paintsurface_t impl;
83
84 static void GATE_CALL on_paint(gate_ui_ctrl_t* sender, gate_ui_graphics_t* graph, gate_ui_position_t const* position);
85 static void GATE_CALL on_resize(gate_ui_ctrl_t* sender, gate_ui_size_t const* size);
86 static void GATE_CALL on_focus_changed(gate_ui_ctrl_t* sender, gate_bool_t hasfocus);
87
88 static void GATE_CALL on_mouse_down(gate_ui_ctrl_t* sender, gate_ui_point_t const* position, gate_uint32_t button);
89 static void GATE_CALL on_mouse_up(gate_ui_ctrl_t* sender, gate_ui_point_t const* position, gate_uint32_t button);
90 static void GATE_CALL on_mouse_dblclick(gate_ui_ctrl_t* sender, gate_ui_point_t const* position, gate_uint32_t button);
91 static void GATE_CALL on_mouse_move(gate_ui_ctrl_t* sender, gate_ui_point_t const* position, gate_uint32_t button);
92 static void GATE_CALL on_mouse_scroll(gate_ui_ctrl_t* sender, gate_ui_point_t const* position, gate_uint32_t button, gate_int32_t delta);
93 static void GATE_CALL on_mouse_enter(gate_ui_ctrl_t* sender);
94 static void GATE_CALL on_mouse_leave(gate_ui_ctrl_t* sender);
95 static void GATE_CALL on_mouse_lost(gate_ui_ctrl_t* sender);
96
97 static void GATE_CALL on_key_down(gate_ui_ctrl_t* sender, gate_input_keycode_t keycode, gate_input_keystates_t ctrlkeys);
98 static void GATE_CALL on_key_up(gate_ui_ctrl_t* sender, gate_input_keycode_t keycode, gate_input_keystates_t ctrlkeys);
99 static void GATE_CALL on_key_char(gate_ui_ctrl_t* sender, gate_char32_t character, gate_input_keystates_t ctrlkeys);
100 };
101
102 /// @brief Event-publishing graphics paint surface control
103 class GATE_UI_CPP_API PaintSurface : public PaintSurfaceBase
104 {
105 public:
106 PaintSurface();
107
108 ~PaintSurface() noexcept;
109
110 protected:
111 virtual void onPaint(Graphics& graphics, Position const& position);
112 virtual void onResize(Size const& size);
113 virtual void onFocusChanged(bool hasFocus);
114
115 virtual void onMouseDown(Point const& point, uint32_t button);
116 virtual void onMouseUp(Point const& point, uint32_t button);
117 virtual void onMouseDblClick(Point const& point, uint32_t button);
118 virtual void onMouseMove(Point const& point, uint32_t button);
119 virtual void onMouseScroll(Point const& point, uint32_t button, int32_t delta);
120 virtual void onMouseEnter();
121 virtual void onMouseLeave();
122 virtual void onMouseLost();
123
124 virtual void onKeyDown(Keyboard::KeyEnum keyCode, uint32_t keyStates);
125 virtual void onKeyUp(Keyboard::KeyEnum keyCode, uint32_t keyStates);
126 virtual void onKeyChar(char_32_t character, uint32_t ctrlKeys);
127
128 public:
129 struct GATE_UI_CPP_API PaintEventArg : public EventArg
130 {
131 Graphics& Context;
132 Position DrawRectangle;
133
134 2 inline PaintEventArg(Graphics& context, Position const& rect)
135 2 : Context(context), DrawRectangle(rect)
136 {
137 2 }
138 };
139 struct GATE_UI_CPP_API ResizeEventArg : public EventArg
140 {
141 Size NewSize;
142 };
143 struct GATE_UI_CPP_API FocusEventArg : public EventArg
144 {
145 bool_t HasFocus;
146 };
147
148 struct GATE_UI_CPP_API MouseEventArg : public EventArg
149 {
150 };
151
152 struct GATE_UI_CPP_API MousePositionEventArg : public EventArg
153 {
154 Point Position;
155 uint32_t Button;
156 int32_t Delta;
157 };
158 struct GATE_UI_CPP_API KeyEventArg : public EventArg
159 {
160 Keyboard::KeyEnum KeyCode;
161 uint32_t CtrlKeys;
162 char_32_t Character;
163 };
164
165 typedef Event<PaintSurface, PaintEventArg>::delegate_t PaintEventHandler;
166 Event<PaintSurface, PaintEventArg> PaintEvent;
167
168 typedef Event<PaintSurface, ResizeEventArg>::delegate_t ResizeEventHandler;
169 Event<PaintSurface, ResizeEventArg> ResizeEvent;
170
171 typedef Event<PaintSurface, FocusEventArg>::delegate_t FocusEventHandler;
172 Event<PaintSurface, FocusEventArg> FocusEvent;
173
174 typedef Event<PaintSurface, MouseEventArg>::delegate_t MouseEnterEventHandler;
175 Event<PaintSurface, MouseEventArg> MouseEnterEvent;
176
177 typedef Event<PaintSurface, MouseEventArg>::delegate_t MouseLeaveEventHandler;
178 Event<PaintSurface, MouseEventArg> MouseLeaveEvent;
179
180 typedef Event<PaintSurface, MouseEventArg>::delegate_t MouseLostEventHandler;
181 Event<PaintSurface, MouseEventArg> MouseLostEvent;
182
183 typedef Event<PaintSurface, MousePositionEventArg>::delegate_t MouseDownEventHandler;
184 Event<PaintSurface, MousePositionEventArg> MouseDownEvent;
185
186 typedef Event<PaintSurface, MousePositionEventArg>::delegate_t MouseUpEventHandler;
187 Event<PaintSurface, MousePositionEventArg> MouseUpEvent;
188
189 typedef Event<PaintSurface, MousePositionEventArg>::delegate_t MouseDblClickEventHandler;
190 Event<PaintSurface, MousePositionEventArg> MouseDblClickEvent;
191
192 typedef Event<PaintSurface, MousePositionEventArg>::delegate_t MouseMoveEventHandler;
193 Event<PaintSurface, MousePositionEventArg> MouseMoveEvent;
194
195 typedef Event<PaintSurface, MousePositionEventArg>::delegate_t MouseScrollEventHandler;
196 Event<PaintSurface, MousePositionEventArg> MouseScrollEvent;
197
198 typedef Event<PaintSurface, KeyEventArg>::delegate_t KeyDownEventHandler;
199 Event<PaintSurface, KeyEventArg> KeyDownEvent;
200
201 typedef Event<PaintSurface, KeyEventArg>::delegate_t KeyUpEventHandler;
202 Event<PaintSurface, KeyEventArg> KeyUpEvent;
203
204 typedef Event<PaintSurface, KeyEventArg>::delegate_t KeyCharEventHandler;
205 Event<PaintSurface, KeyEventArg> KeyCharEvent;
206 };
207
208 } // end of namespace ui
209 } // end of namespace gate
210
211
212 #endif
213