libdonut  2.3.2
Application framework for cross-platform game development in C++20
Event.hpp
Go to the documentation of this file.
1 #ifndef DONUT_EVENTS_EVENT_HPP
2 #define DONUT_EVENTS_EVENT_HPP
3 
4 #include <donut/Variant.hpp>
5 #include <donut/events/Input.hpp>
6 #include <donut/math.hpp>
7 
8 #include <cstdint> // std::int16_t, std::int32_t, std::uint8_t, std::uint16_t, std::uint32_t
9 #include <string> // std::string
10 
11 namespace donut::events {
12 
14 struct EventBase {};
15 
18 
21  std::uint32_t windowId;
22 };
23 
26  std::uint32_t windowId;
27 };
28 
32  using KeyModifiers = std::uint16_t;
33 
37  MODIFIER_LSHIFT = 1 << 0,
38  MODIFIER_RSHIFT = 1 << 1,
39  MODIFIER_LCTRL = 1 << 6,
40  MODIFIER_RCTRL = 1 << 7,
41  MODIFIER_LALT = 1 << 8,
42  MODIFIER_RALT = 1 << 9,
43  MODIFIER_LSUPER = 1 << 10,
44  MODIFIER_RSUPER = 1 << 11,
45  MODIFIER_NUM_LOCK = 1 << 12,
46  MODIFIER_CAPS_LOCK = 1 << 13,
47  MODIFIER_MODE = 1 << 14,
49 
54  };
55 
59 };
60 
63  std::string inputText;
64 };
65 
68  std::uint32_t mouseId;
69  ivec2 mousePosition;
71 };
72 
76  std::uint8_t clickCount;
77 };
78 
81  std::int32_t controllerId;
82 };
83 
89  enum class ControllerAxis : std::uint8_t {
90  LEFT_STICK_X = 0,
91  LEFT_STICK_Y = 1,
92  RIGHT_STICK_X = 2,
93  RIGHT_STICK_Y = 3,
94  LEFT_TRIGGER = 4,
95  RIGHT_TRIGGER = 5,
96  INVALID = 255,
97  };
98 
100  i16 axisValue;
101 };
102 
106 };
107 
110  std::int64_t touchDeviceId;
111  std::int64_t fingerId;
115 };
116 
119 
122 
125  std::uint32_t windowId;
126 };
127 
130 
133 
136 
139 
142 
145 
148 
151 
154 
157 
161 };
162 
165  ivec2 windowSize;
166 };
167 
170  ivec2 windowSize;
171 };
172 
175 
178 
181 
184 
187 
190 
193 
196 
200 };
201 
204 
207 
210 
213  std::int32_t textCursorOffset;
215 };
216 
219 
222 
225 
228 
231  ivec2 scrollTicks;
233 };
234 
237 
240 
243 
246 
249 
252 
255 
258 
261 
264 
267 
270  std::string droppedFilepath;
271 };
272 
275  std::string droppedText;
276 };
277 
280 
283 
292 struct Event
293  : Variant< //
294  ApplicationQuitRequestedEvent, //
295  ApplicationTerminatingEvent, //
296  ApplicationLowMemoryEvent, //
297  ApplicationPausingEvent, //
298  ApplicationPausedEvent, //
299  ApplicationUnpausingEvent, //
300  ApplicationUnpausedEvent, //
301  WindowShownEvent, //
302  WindowHiddenEvent, //
303  WindowExposedEvent, //
304  WindowMovedEvent, //
305  WindowResizedEvent, //
306  WindowSizeChangedEvent, //
307  WindowMinimizedEvent, //
308  WindowMaximizedEvent, //
309  WindowRestoredEvent, //
310  WindowMouseFocusGainedEvent, //
311  WindowMouseFocusLostEvent, //
312  WindowKeyboardFocusGainedEvent, //
313  WindowKeyboardFocusLostEvent, //
314  WindowCloseRequestedEvent, //
315  WindowDisplayChangedEvent, //
316  KeyPressedEvent, //
317  KeyPressRepeatedEvent, //
318  KeyReleasedEvent, //
319  TextInputEditedEvent, //
320  TextInputSubmittedEvent, //
321  MouseMovedEvent, //
322  MouseButtonPressedEvent, //
323  MouseButtonReleasedEvent, //
324  MouseWheelScrolledEvent, //
325  ControllerAddedEvent, //
326  ControllerRemovedEvent, //
327  ControllerRemappedEvent, //
328  ControllerAxisMovedEvent, //
329  ControllerButtonPressedEvent, //
330  ControllerButtonReleasedEvent, //
331  TouchMovedEvent, //
332  TouchPressedEvent, //
333  TouchReleasedEvent, //
334  KeymapChangedEvent, //
335  ClipboardUpdatedEvent, //
336  DropFileEvent, //
337  DropTextEvent, //
338  DropStartedEvent, //
339  DropCompletedEvent> {};
340 
341 } // namespace donut::events
342 
343 #endif
Tagged union value type that holds a value of one of the given types.
Definition: Variant.hpp:291
Definition: Error.hpp:7
Input
Unique identifier for a specific control on a physical input device, such as a certain keyboard key,...
Definition: Input.hpp:323
Application Event base.
Definition: Event.hpp:17
Application is low on memory.
Definition: Event.hpp:135
Application was paused by the OS.
Definition: Event.hpp:141
Application is about to be paused by the OS.
Definition: Event.hpp:138
Application was requested to quit by the user.
Definition: Event.hpp:129
Application is being terminated by the OS.
Definition: Event.hpp:132
Application was unpaused by the OS.
Definition: Event.hpp:147
Application is about to be unpaused by the OS.
Definition: Event.hpp:144
Clipboard Event base.
Definition: Event.hpp:121
Clipboard was updated.
Definition: Event.hpp:266
Controller was added.
Definition: Event.hpp:236
Controller axis Event base.
Definition: Event.hpp:85
i16 axisValue
Current axis value in the range [-32768, 32767].
Definition: Event.hpp:100
ControllerAxis
Controller axis enumeration.
Definition: Event.hpp:89
@ LEFT_STICK_Y
Vertical movement of the left analog stick.
@ RIGHT_STICK_Y
Vertical movement of the right analog stick.
@ RIGHT_STICK_X
Horizontal movement of the right analog stick.
@ LEFT_STICK_X
Horizontal movement of the left analog stick.
ControllerAxis axis
Physical controller axis.
Definition: Event.hpp:99
Controller axis was moved.
Definition: Event.hpp:245
Controller button Event base.
Definition: Event.hpp:104
Input physicalControllerButtonInput
Physical button input identifier.
Definition: Event.hpp:105
Controller button was pressed.
Definition: Event.hpp:248
Controller button was released.
Definition: Event.hpp:251
Controller Event base.
Definition: Event.hpp:80
std::int32_t controllerId
Unique identifier of the controller instance.
Definition: Event.hpp:81
Controller was remapped.
Definition: Event.hpp:242
Controller was removed.
Definition: Event.hpp:239
Drop was completed.
Definition: Event.hpp:282
Drop Event base.
Definition: Event.hpp:124
std::uint32_t windowId
Unique identifier of the window that was dropped onto, if any.
Definition: Event.hpp:125
File was dropped.
Definition: Event.hpp:269
std::string droppedFilepath
Filepath of the dropped file.
Definition: Event.hpp:270
Drop was started.
Definition: Event.hpp:279
Text was dropped.
Definition: Event.hpp:274
std::string droppedText
Dropped text.
Definition: Event.hpp:275
Event base.
Definition: Event.hpp:14
Data structure containing information about an event.
Definition: Event.hpp:339
Input Event base.
Definition: Event.hpp:25
std::uint32_t windowId
Unique identifier of the window that this event belongs to, if any.
Definition: Event.hpp:26
Keyboard key Event base.
Definition: Event.hpp:30
KeyModifier
Key modifier bits.
Definition: Event.hpp:35
@ MODIFIER_SCROLL_LOCK
Scroll lock.
Definition: Event.hpp:48
@ MODIFIER_SHIFT
Left or right shift.
Definition: Event.hpp:51
@ MODIFIER_RSHIFT
Right shift.
Definition: Event.hpp:38
@ MODIFIER_LCTRL
Left control.
Definition: Event.hpp:39
@ MODIFIER_NONE
No modifiers.
Definition: Event.hpp:36
@ MODIFIER_LSUPER
Left super.
Definition: Event.hpp:43
@ MODIFIER_MODE
Mode.
Definition: Event.hpp:47
@ MODIFIER_RALT
Right alt.
Definition: Event.hpp:42
@ MODIFIER_SUPER
Left or right super.
Definition: Event.hpp:53
@ MODIFIER_ALT
Left or right alt.
Definition: Event.hpp:52
@ MODIFIER_CTRL
Left or right control.
Definition: Event.hpp:50
@ MODIFIER_LSHIFT
Left shift.
Definition: Event.hpp:37
@ MODIFIER_RCTRL
Right control.
Definition: Event.hpp:40
@ MODIFIER_NUM_LOCK
Number lock.
Definition: Event.hpp:45
@ MODIFIER_LALT
Left alt.
Definition: Event.hpp:41
@ MODIFIER_RSUPER
Right super.
Definition: Event.hpp:44
@ MODIFIER_CAPS_LOCK
Capital lock.
Definition: Event.hpp:46
Input physicalKeyInput
Physical key input identifier.
Definition: Event.hpp:56
KeyModifiers keyModifiers
Current key modifiers.
Definition: Event.hpp:58
int symbolicKeyCode
Symbolic identifier of the key.
Definition: Event.hpp:57
std::uint16_t KeyModifiers
Bit set of key modifiers.
Definition: Event.hpp:32
Keyboard key was held, causing a repeat press.
Definition: Event.hpp:206
Keyboard key was pressed.
Definition: Event.hpp:203
Keyboard key was released.
Definition: Event.hpp:209
Keyboard keymap was changed.
Definition: Event.hpp:263
Keyboard keymap Event base.
Definition: Event.hpp:118
Mouse button Event base.
Definition: Event.hpp:74
Input physicalMouseButtonInput
Physical button input identifier.
Definition: Event.hpp:75
std::uint8_t clickCount
Number of consecutive clicks within a short time interval.
Definition: Event.hpp:76
Mouse button was pressed.
Definition: Event.hpp:224
Mouse button was released.
Definition: Event.hpp:227
Mouse Event base.
Definition: Event.hpp:67
ivec2 mousePosition
Current mouse position relative to the window.
Definition: Event.hpp:69
std::uint32_t mouseId
Unique identifier of the mouse instance.
Definition: Event.hpp:68
ivec2 relativeMouseMotion
Position offset relative to the previous position.
Definition: Event.hpp:70
Mouse was moved.
Definition: Event.hpp:221
Mouse wheel was scrolled.
Definition: Event.hpp:230
ivec2 scrollTicks
Number of scrolls horizontally/vertically.
Definition: Event.hpp:231
vec2 scrollAmount
Amount scrolled horizontally/vertically, with floating-point precision.
Definition: Event.hpp:232
Text input was edited.
Definition: Event.hpp:212
std::int32_t textCursorOffset
The cursor offset of the start of the selected text.
Definition: Event.hpp:213
std::int32_t textCursorSelectionLength
The length of the current text selection, if any.
Definition: Event.hpp:214
Text input Event base.
Definition: Event.hpp:62
std::string inputText
Input text.
Definition: Event.hpp:63
Text input was submitted.
Definition: Event.hpp:218
Touch Event base.
Definition: Event.hpp:109
vec2 relativeNormalizedFingerMotion
Finger offset relative to the previous position, normalized to the range [-1, 1].
Definition: Event.hpp:113
std::int64_t touchDeviceId
Touch device identifier.
Definition: Event.hpp:110
vec2 normalizedFingerPosition
Current finger position, normalized to the range [0, 1].
Definition: Event.hpp:112
float normalizedFingerPressure
Amount of pressure applied, normalized to the range [0, 1].
Definition: Event.hpp:114
std::int64_t fingerId
Finger identifier.
Definition: Event.hpp:111
Touch was moved.
Definition: Event.hpp:254
Touch was pressed.
Definition: Event.hpp:257
Touch was released.
Definition: Event.hpp:260
Window was requested to close.
Definition: Event.hpp:195
Window was moved to a new display.
Definition: Event.hpp:198
int displayIndex
Current display index.
Definition: Event.hpp:199
Window Event base.
Definition: Event.hpp:20
std::uint32_t windowId
Unique identifier of the window.
Definition: Event.hpp:21
Window was exposed.
Definition: Event.hpp:156
Window was hidden.
Definition: Event.hpp:153
Window gained keyboard focus.
Definition: Event.hpp:189
Window lost keyboard focus.
Definition: Event.hpp:192
Window was maximized.
Definition: Event.hpp:177
Window was minimized.
Definition: Event.hpp:174
Window gained mouse focus.
Definition: Event.hpp:183
Window lost mouse focus.
Definition: Event.hpp:186
Window was moved.
Definition: Event.hpp:159
ivec2 windowPosition
Current window position.
Definition: Event.hpp:160
Window was resized manually.
Definition: Event.hpp:164
ivec2 windowSize
Current window size.
Definition: Event.hpp:165
Window was restored.
Definition: Event.hpp:180
Window was shown.
Definition: Event.hpp:150
Window size was changed.
Definition: Event.hpp:169
ivec2 windowSize
Current window size.
Definition: Event.hpp:170