nomlib
Loading...
Searching...
No Matches
Event.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_SYSTEM_EVENT_HPP
30#define NOMLIB_SYSTEM_EVENT_HPP
31
32#include <functional>
33
34#include "nomlib/config.hpp"
35#include "nomlib/system/Joystick.hpp"
36
37namespace nom {
38
39const uint8 MAX_TEXT_INPUT_LENGTH = 32;
40const uint8 MAX_TEXT_EDITING_LENGTH = 32;
41
43enum InputState: uint8
44{
45 RELEASED = 0,
46 PRESSED,
47};
48
50enum MouseButton: uint8
51{
52 LEFT_MOUSE_BUTTON = 1,
53 MIDDLE_MOUSE_BUTTON,
54 RIGHT_MOUSE_BUTTON,
55 X1_MOUSE_BUTTON,
56 X2_MOUSE_BUTTON,
57};
58
59typedef int64 TouchID;
60typedef int64 FingerID;
61
64const uint32 TOUCH_MOUSE_ID = nom::NOM_UINT32_MAX;
65
68{
70 void* data1;
71
73 void* data2;
74};
75
78{
80 enum EventType: uint8
81 {
82 NONE = 0,
83 SHOWN,
84 HIDDEN,
85 EXPOSED,
86 MOVED,
87 RESIZED,
88 SIZE_CHANGED,
89 MINIMIZED,
90 MAXIMIZED,
91 RESTORED,
92 MOUSE_FOCUS_GAINED,
93 MOUSE_FOCUS_LOST,
94 KEYBOARD_FOCUS_GAINED,
95 KEYBOARD_FOCUS_LOST,
96 CLOSE,
97 };
98
102 uint8 event;
103
106 int32 data1;
107
110 int32 data2;
111
113 uint32 window_id;
114};
115
118{
120 int32 sym;
121
124 uint16 mod;
125
127 uint16 scan_code;
128
132 uint8 state;
133
135 uint8 repeat;
136
138 uint32 window_id;
139};
140
143{
149 uint32 id;
150
152 int32 x;
153
155 int32 y;
156
158 int32 x_rel;
159
161 int32 y_rel;
162
168 uint8 state;
169
171 uint32 window_id;
172};
173
176{
184 uint32 id;
185
187 int32 x;
188
190 int32 y;
191
195 uint8 button;
196
200 uint8 state;
201
205 uint8 clicks;
206
208 uint32 window_id;
209};
210
213{
219 uint32 id;
220
222 int32 x;
223
225 int32 y;
226
228 uint32 window_id;
229};
230
233{
235 JoystickID id;
236
240 uint8 axis;
241
245 int16 value;
246};
247
250{
252 JoystickID id;
253
255 uint8 button;
256
260 uint8 state;
261};
262
265{
267 JoystickID id;
268
272 uint8 hat;
273
277 uint8 value;
278};
279
282{
286 JoystickID id;
287};
288
292{
294 JoystickID id;
295
299 int8 axis;
300
304 int16 value;
305};
306
309{
311 JoystickID id;
312
316 int8 button;
317
321 uint8 state;
322};
323
327{
333 JoystickID id;
334};
335
338{
340 FingerID id;
341
343 float x;
344
346 float y;
347
349 float pressure;
350};
351
356{
358 TouchID id;
359
362
364 float x;
365
367 float y;
368
370 float dx;
371
373 float dy;
374
376 float pressure;
377};
378
384{
386 TouchID id;
387
389 float x;
390
392 float y;
393
395 float dTheta;
396
398 float dDist;
399
402};
403
406{
408 const char* file_path;
409};
410
413{
415 char text[MAX_TEXT_INPUT_LENGTH];
416
418 uint32 window_id;
419};
420
425{
427 char text[MAX_TEXT_EDITING_LENGTH];
428
430 int32 start;
431
433 int32 length;
434
436 uint32 window_id;
437};
438
441{
443 int32 code;
444
446 void* data1;
447
449 void* data2;
450
452 uint32 window_id;
453};
454
456struct Event
457{
458 enum EventType: uint32
459 {
460 FIRST_EVENT = 0,
461 QUIT_EVENT,
462 WINDOW_EVENT,
463 SYSWMEVENT,
464 KEY_PRESS,
465 KEY_RELEASE,
466 MOUSE_MOTION,
467 MOUSE_BUTTON_CLICK,
468 MOUSE_BUTTON_RELEASE,
469 MOUSE_WHEEL,
470 JOYSTICK_AXIS_MOTION,
471 JOYSTICK_BALL_MOTION,
472 JOYSTICK_HAT_MOTION,
473 JOYSTICK_BUTTON_PRESS,
474 JOYSTICK_BUTTON_RELEASE,
475
478
481
482 GAME_CONTROLLER_AXIS_MOTION,
483
484 GAME_CONTROLLER_BUTTON_PRESS,
485 GAME_CONTROLLER_BUTTON_RELEASE,
486
489
492
495
496 FINGER_MOTION,
497
498 FINGER_PRESS,
499
500 FINGER_RELEASE,
501
502 MULTI_FINGER_GESTURE,
503 DROP_FILE,
504 TEXT_INPUT,
505 TEXT_EDITING,
506 RENDER_TARGETS_RESET,
507
508// NOTE: Not available until the release of SDL 2.0.4
509#if 0
510 RENDER_DEVICE_RESET,
511#endif
512 USER_EVENT,
513 };
514
518 uint32 type;
519
521 uint32 timestamp;
522
523 union
524 {
525 QuitEvent quit;
526 WindowEvent window;
527 KeyboardEvent key;
528 MouseMotionEvent motion;
529 MouseButtonEvent mouse;
530 MouseWheelEvent wheel;
531 JoystickButtonEvent jbutton;
532 JoystickAxisEvent jaxis;
533 JoystickHatEvent jhat;
534 JoystickDeviceEvent jdevice;
538 FingerTouchEvent touch;
539 GestureEvent gesture;
540 DragDropEvent drop;
541 TextInputEvent text;
542 TextEditingEvent edit;
543 UserEvent user;
544 };
545};
546
547typedef std::function<void(const Event&)> event_callback;
548typedef std::function<void(const Event&, void* data)> event_filter;
549
550} // namespace nom
551
552#endif // include guard defined
A structure containing information on a Drag 'N' Drop event.
Definition Event.hpp:406
const char * file_path
The path of the file dropped onto the nom::Window.
Definition Event.hpp:408
Event handling types.
Definition Event.hpp:457
uint32 type
The event type.
Definition Event.hpp:518
uint32 timestamp
The recorded time at the moment of the event.
Definition Event.hpp:521
@ JOYSTICK_REMOVED
The instance ID of the joystick removal event.
Definition Event.hpp:480
@ JOYSTICK_ADDED
The device index of the joystick connection event.
Definition Event.hpp:477
@ GAME_CONTROLLER_REMOVED
The instance ID of the game controller removal event.
Definition Event.hpp:491
@ GAME_CONTROLLER_REMAPPED
The instance ID of the game controller remapping event.
Definition Event.hpp:494
@ GAME_CONTROLLER_ADDED
The device index of the game controller connection event.
Definition Event.hpp:488
A structure containing information on a finger (touch) event.
Definition Event.hpp:338
FingerID id
The finger index identifier.
Definition Event.hpp:340
float pressure
The quantity of the pressure applied; normalized 0..1.
Definition Event.hpp:349
float y
The Y coordinate of the event; normalized 0..1.
Definition Event.hpp:346
float x
The X coordinate of the event; normalized 0..1.
Definition Event.hpp:343
A structure containing information on a finger touch event.
Definition Event.hpp:356
FingerEvent finger
The finger index identifier.
Definition Event.hpp:361
float dy
The distance moved in the Y axis; normalized 0..1.
Definition Event.hpp:373
float pressure
The quantity of the pressure applied; normalized 0..1.
Definition Event.hpp:376
TouchID id
The touch device index identifier.
Definition Event.hpp:358
float x
The X coordinate of the event; normalized 0..1.
Definition Event.hpp:364
float y
The Y coordinate of the event; normalized 0..1.
Definition Event.hpp:367
float dx
The distance moved in the X axis; normalized 0..1.
Definition Event.hpp:370
A structure containing information on a game controller axis motion event.
Definition Event.hpp:292
int16 value
The axis value.
Definition Event.hpp:304
JoystickID id
The joystick instance identifier.
Definition Event.hpp:294
int8 axis
Index of the axis on the device.
Definition Event.hpp:299
A structure containing information on a game controller button event.
Definition Event.hpp:309
int8 button
The index of the button.
Definition Event.hpp:316
uint8 state
The state of the button.
Definition Event.hpp:321
JoystickID id
The joystick instance identifier.
Definition Event.hpp:311
Internal representation of a game controller device connection event.
Definition Event.hpp:327
JoystickID id
The joystick instance identifier.
Definition Event.hpp:333
A structure containing information on a multi-finger gesture (touch) event.
Definition Event.hpp:384
float y
The Y coordinate of the event.
Definition Event.hpp:392
float x
The X coordinate of the event.
Definition Event.hpp:389
float dTheta
...???
Definition Event.hpp:395
float dDist
...???
Definition Event.hpp:398
uint16 num_fingers
The number of fingers used in the gesture event.
Definition Event.hpp:401
TouchID id
The touch device index identifier.
Definition Event.hpp:386
A structure containing information on a joystick axis motion event.
Definition Event.hpp:233
uint8 axis
Index of the axis on the device.
Definition Event.hpp:240
JoystickID id
The joystick instance identifier.
Definition Event.hpp:235
int16 value
The current position of the axis.
Definition Event.hpp:245
A structure containing information on a joystick button event.
Definition Event.hpp:250
JoystickID id
The joystick instance identifier.
Definition Event.hpp:252
uint8 button
The index of the button.
Definition Event.hpp:255
uint8 state
The state of the button.
Definition Event.hpp:260
Internal representation of a joystick device connection event.
Definition Event.hpp:282
JoystickID id
The joystick instance identifier.
Definition Event.hpp:286
Internal representation of a joystick hat position.
Definition Event.hpp:265
uint8 value
The hat position value.
Definition Event.hpp:277
uint8 hat
The index of the joystick hat.
Definition Event.hpp:272
JoystickID id
The joystick instance identifier.
Definition Event.hpp:267
A structure containing information on a keyboard event.
Definition Event.hpp:118
uint16 mod
An enumeration of key modifier masks; see also: the SDL2 wiki documentation page for SDL_Keymod.
Definition Event.hpp:124
int32 sym
The virtual key code.
Definition Event.hpp:120
uint8 repeat
Non-zero if this is a repeating key press event.
Definition Event.hpp:135
uint8 state
The state of the key press event.
Definition Event.hpp:132
uint16 scan_code
The physical key code.
Definition Event.hpp:127
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:138
A structure containing information on a mouse button event.
Definition Event.hpp:176
int32 y
The Y coordinate, relative to the nom::Window instance.
Definition Event.hpp:190
int32 x
The X coordinate, relative to the nom::Window instance.
Definition Event.hpp:187
uint8 state
The state of the button.
Definition Event.hpp:200
uint32 id
The mouse instance identifier, or SDL_TOUCH_MOUSEID.
Definition Event.hpp:184
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:208
uint8 button
The button's event type.
Definition Event.hpp:195
uint8 clicks
Value containing how many mouse buttons were clicked.
Definition Event.hpp:205
A structure containing information on a mouse event.
Definition Event.hpp:143
uint8 state
The state of the button.
Definition Event.hpp:168
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:171
int32 x
The X coordinate, relative to the nom::Window instance.
Definition Event.hpp:152
int32 x_rel
The relative motion in the X coordinate direction.
Definition Event.hpp:158
int32 y_rel
The relative motion in the Y coordinate direction.
Definition Event.hpp:161
uint32 id
The mouse instance identifier, or SDL_TOUCH_MOUSEID.
Definition Event.hpp:149
int32 y
The Y coordinate, relative to the nom::Window instance.
Definition Event.hpp:155
A structure containing information on a mouse wheel event.
Definition Event.hpp:213
int32 x
X axis value; relative to the direction of the wheel.
Definition Event.hpp:222
int32 y
Y axis value, relative to the direction of the wheel.
Definition Event.hpp:225
uint32 id
The mouse instance identifier, or SDL_TOUCH_MOUSEID.
Definition Event.hpp:219
uint32 window_id
The identifier of the window at the moment of event.
Definition Event.hpp:228
Representation of a program termination request.
Definition Event.hpp:68
void * data1
User-defined data.
Definition Event.hpp:70
void * data2
User-defined data.
Definition Event.hpp:73
A structure containing information on a text editing event.
Definition Event.hpp:425
int32 length
The number of characters to edit from the start point.
Definition Event.hpp:433
int32 start
The location to begin editing from.
Definition Event.hpp:430
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:436
char text[MAX_TEXT_EDITING_LENGTH]
The text being edited.
Definition Event.hpp:427
A structure containing information on a text input event.
Definition Event.hpp:413
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:418
char text[MAX_TEXT_INPUT_LENGTH]
The text input.
Definition Event.hpp:415
A structure containing information on an user event.
Definition Event.hpp:441
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:452
void * data2
User defined data pointer.
Definition Event.hpp:449
int32 code
User defined event code.
Definition Event.hpp:443
void * data1
User defined data pointer.
Definition Event.hpp:446
A structure containing information on a window event.
Definition Event.hpp:78
uint8 event
The window's event type.
Definition Event.hpp:102
EventType
Window event types.
Definition Event.hpp:81
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:113
int32 data2
Event dependent data; typically the Y coordinate position or height data of an event.
Definition Event.hpp:110
int32 data1
Event dependent data; typically the X coordinate position or width data of an event.
Definition Event.hpp:106