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