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 "export.hpp"
35#include "nomlib/config.hpp"
36#include "nomlib/system/Joystick.hpp"
37
38namespace nom {
39
40const uint8 MAX_TEXT_INPUT_LENGTH = 32;
41const uint8 MAX_TEXT_EDITING_LENGTH = 32;
42
44enum InputState: uint8
45{
46 RELEASED = 0,
47 PRESSED,
48};
49
51enum MouseButton: uint8
52{
53 LEFT_MOUSE_BUTTON = 1,
54 MIDDLE_MOUSE_BUTTON,
55 RIGHT_MOUSE_BUTTON,
56 X1_MOUSE_BUTTON,
57 X2_MOUSE_BUTTON,
58};
59
60typedef int64 TouchID;
61typedef int64 FingerID;
62
65const uint32 TOUCH_MOUSE_ID = nom::NOM_UINT32_MAX;
66
69{
71 void* data1;
72
74 void* data2;
75};
76
79{
81 enum EventType: uint8
82 {
83 NONE = 0,
84 SHOWN,
85 HIDDEN,
86 EXPOSED,
87 MOVED,
88 RESIZED,
89 SIZE_CHANGED,
90 MINIMIZED,
91 MAXIMIZED,
92 RESTORED,
93 MOUSE_FOCUS_GAINED,
94 MOUSE_FOCUS_LOST,
95 KEYBOARD_FOCUS_GAINED,
96 KEYBOARD_FOCUS_LOST,
97 CLOSE,
98 };
99
103 uint8 event;
104
107 int32 data1;
108
111 int32 data2;
112
114 uint32 window_id;
115};
116
119{
121 int32 sym;
122
125 uint16 mod;
126
128 uint16 scan_code;
129
133 uint8 state;
134
136 uint8 repeat;
137
139 uint32 window_id;
140};
141
144{
150 uint32 id;
151
153 int32 x;
154
156 int32 y;
157
159 int32 x_rel;
160
162 int32 y_rel;
163
169 uint8 state;
170
172 uint32 window_id;
173};
174
177{
185 uint32 id;
186
188 int32 x;
189
191 int32 y;
192
196 uint8 button;
197
201 uint8 state;
202
206 uint8 clicks;
207
209 uint32 window_id;
210};
211
214{
220 uint32 id;
221
223 int32 x;
224
226 int32 y;
227
229 uint32 window_id;
230};
231
234{
236 JoystickID id;
237
241 uint8 axis;
242
246 int16 value;
247};
248
251{
253 JoystickID id;
254
256 uint8 button;
257
261 uint8 state;
262};
263
266{
268 JoystickID id;
269
273 uint8 hat;
274
278 uint8 value;
279};
280
283{
287 JoystickID id;
288};
289
293{
295 JoystickID id;
296
300 int8 axis;
301
305 int16 value;
306};
307
310{
312 JoystickID id;
313
317 int8 button;
318
322 uint8 state;
323};
324
328{
334 JoystickID id;
335};
336
339{
341 FingerID id;
342
344 float x;
345
347 float y;
348
350 float pressure;
351};
352
357{
359 TouchID id;
360
363
365 float x;
366
368 float y;
369
371 float dx;
372
374 float dy;
375
377 float pressure;
378};
379
385{
387 TouchID id;
388
390 float x;
391
393 float y;
394
396 float dTheta;
397
399 float dDist;
400
403};
404
407{
409 const char* file_path;
410};
411
414{
416 char text[MAX_TEXT_INPUT_LENGTH];
417
419 uint32 window_id;
420};
421
426{
428 char text[MAX_TEXT_EDITING_LENGTH];
429
431 int32 start;
432
434 int32 length;
435
437 uint32 window_id;
438};
439
442{
444 int32 code;
445
447 void* data1;
448
450 void* data2;
451
453 uint32 window_id;
454};
455
457struct Event
458{
459 enum EventType: uint32
460 {
461 FIRST_EVENT = 0,
462 QUIT_EVENT,
463 WINDOW_EVENT,
464 SYSWMEVENT,
465 KEY_PRESS,
466 KEY_RELEASE,
467 MOUSE_MOTION,
468 MOUSE_BUTTON_CLICK,
469 MOUSE_BUTTON_RELEASE,
470 MOUSE_WHEEL,
471 JOYSTICK_AXIS_MOTION,
472 JOYSTICK_BALL_MOTION,
473 JOYSTICK_HAT_MOTION,
474 JOYSTICK_BUTTON_PRESS,
475 JOYSTICK_BUTTON_RELEASE,
476
479
482
483 GAME_CONTROLLER_AXIS_MOTION,
484
485 GAME_CONTROLLER_BUTTON_PRESS,
486 GAME_CONTROLLER_BUTTON_RELEASE,
487
490
493
496
497 FINGER_MOTION,
498
499 FINGER_PRESS,
500
501 FINGER_RELEASE,
502
503 MULTI_FINGER_GESTURE,
504 DROP_FILE,
505 TEXT_INPUT,
506 TEXT_EDITING,
507 RENDER_TARGETS_RESET,
508 // NOTE: Not available until the release of SDL 2.0.4
509 RENDER_DEVICE_RESET,
510
511 USER_EVENT,
512 };
513
517 uint32 type;
518
520 uint32 timestamp;
521
522 union
523 {
524 QuitEvent quit;
525 WindowEvent window;
526 KeyboardEvent key;
527 MouseMotionEvent motion;
528 MouseButtonEvent mouse;
529 MouseWheelEvent wheel;
530 JoystickButtonEvent jbutton;
531 JoystickAxisEvent jaxis;
532 JoystickHatEvent jhat;
533 JoystickDeviceEvent jdevice;
537 FingerTouchEvent touch;
538 GestureEvent gesture;
539 DragDropEvent drop;
540 TextInputEvent text;
541 TextEditingEvent edit;
542 UserEvent user;
543 };
544};
545
546typedef std::function<void(const Event&)> event_callback;
547typedef std::function<void(const Event&, void* data)> event_filter;
548
549} // namespace nom
550
551#endif // include guard defined
A structure containing information on a Drag 'N' Drop event.
Definition Event.hpp:407
const char * file_path
The path of the file dropped onto the nom::Window.
Definition Event.hpp:409
Event handling types.
Definition Event.hpp:458
uint32 type
The event type.
Definition Event.hpp:517
uint32 timestamp
The recorded time at the moment of the event.
Definition Event.hpp:520
@ JOYSTICK_REMOVED
The instance ID of the joystick removal event.
Definition Event.hpp:481
@ JOYSTICK_ADDED
The device index of the joystick connection event.
Definition Event.hpp:478
@ GAME_CONTROLLER_REMOVED
The instance ID of the game controller removal event.
Definition Event.hpp:492
@ GAME_CONTROLLER_REMAPPED
The instance ID of the game controller remapping event.
Definition Event.hpp:495
@ GAME_CONTROLLER_ADDED
The device index of the game controller connection event.
Definition Event.hpp:489
A structure containing information on a finger (touch) event.
Definition Event.hpp:339
FingerID id
The finger index identifier.
Definition Event.hpp:341
float pressure
The quantity of the pressure applied; normalized 0..1.
Definition Event.hpp:350
float y
The Y coordinate of the event; normalized 0..1.
Definition Event.hpp:347
float x
The X coordinate of the event; normalized 0..1.
Definition Event.hpp:344
A structure containing information on a finger touch event.
Definition Event.hpp:357
FingerEvent finger
The finger index identifier.
Definition Event.hpp:362
float dy
The distance moved in the Y axis; normalized 0..1.
Definition Event.hpp:374
float pressure
The quantity of the pressure applied; normalized 0..1.
Definition Event.hpp:377
TouchID id
The touch device index identifier.
Definition Event.hpp:359
float x
The X coordinate of the event; normalized 0..1.
Definition Event.hpp:365
float y
The Y coordinate of the event; normalized 0..1.
Definition Event.hpp:368
float dx
The distance moved in the X axis; normalized 0..1.
Definition Event.hpp:371
A structure containing information on a game controller axis motion event.
Definition Event.hpp:293
int16 value
The axis value.
Definition Event.hpp:305
JoystickID id
The joystick instance identifier.
Definition Event.hpp:295
int8 axis
Index of the axis on the device.
Definition Event.hpp:300
A structure containing information on a game controller button event.
Definition Event.hpp:310
int8 button
The index of the button.
Definition Event.hpp:317
uint8 state
The state of the button.
Definition Event.hpp:322
JoystickID id
The joystick instance identifier.
Definition Event.hpp:312
Internal representation of a game controller device connection event.
Definition Event.hpp:328
JoystickID id
The joystick instance identifier.
Definition Event.hpp:334
A structure containing information on a multi-finger gesture (touch) event.
Definition Event.hpp:385
float y
The Y coordinate of the event.
Definition Event.hpp:393
float x
The X coordinate of the event.
Definition Event.hpp:390
float dTheta
...???
Definition Event.hpp:396
float dDist
...???
Definition Event.hpp:399
uint16 num_fingers
The number of fingers used in the gesture event.
Definition Event.hpp:402
TouchID id
The touch device index identifier.
Definition Event.hpp:387
A structure containing information on a joystick axis motion event.
Definition Event.hpp:234
uint8 axis
Index of the axis on the device.
Definition Event.hpp:241
JoystickID id
The joystick instance identifier.
Definition Event.hpp:236
int16 value
The current position of the axis.
Definition Event.hpp:246
A structure containing information on a joystick button event.
Definition Event.hpp:251
JoystickID id
The joystick instance identifier.
Definition Event.hpp:253
uint8 button
The index of the button.
Definition Event.hpp:256
uint8 state
The state of the button.
Definition Event.hpp:261
Internal representation of a joystick device connection event.
Definition Event.hpp:283
JoystickID id
The joystick instance identifier.
Definition Event.hpp:287
Internal representation of a joystick hat position.
Definition Event.hpp:266
uint8 value
The hat position value.
Definition Event.hpp:278
uint8 hat
The index of the joystick hat.
Definition Event.hpp:273
JoystickID id
The joystick instance identifier.
Definition Event.hpp:268
A structure containing information on a keyboard event.
Definition Event.hpp:119
uint16 mod
An enumeration of key modifier masks; see also: the SDL2 wiki documentation page for SDL_Keymod.
Definition Event.hpp:125
int32 sym
The virtual key code.
Definition Event.hpp:121
uint8 repeat
Non-zero if this is a repeating key press event.
Definition Event.hpp:136
uint8 state
The state of the key press event.
Definition Event.hpp:133
uint16 scan_code
The physical key code.
Definition Event.hpp:128
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:139
A structure containing information on a mouse button event.
Definition Event.hpp:177
int32 y
The Y coordinate, relative to the nom::Window instance.
Definition Event.hpp:191
int32 x
The X coordinate, relative to the nom::Window instance.
Definition Event.hpp:188
uint8 state
The state of the button.
Definition Event.hpp:201
uint32 id
The mouse instance identifier, or SDL_TOUCH_MOUSEID.
Definition Event.hpp:185
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:209
uint8 button
The button's event type.
Definition Event.hpp:196
uint8 clicks
Value containing how many mouse buttons were clicked.
Definition Event.hpp:206
A structure containing information on a mouse event.
Definition Event.hpp:144
uint8 state
The state of the button.
Definition Event.hpp:169
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:172
int32 x
The X coordinate, relative to the nom::Window instance.
Definition Event.hpp:153
int32 x_rel
The relative motion in the X coordinate direction.
Definition Event.hpp:159
int32 y_rel
The relative motion in the Y coordinate direction.
Definition Event.hpp:162
uint32 id
The mouse instance identifier, or SDL_TOUCH_MOUSEID.
Definition Event.hpp:150
int32 y
The Y coordinate, relative to the nom::Window instance.
Definition Event.hpp:156
A structure containing information on a mouse wheel event.
Definition Event.hpp:214
int32 x
X axis value; relative to the direction of the wheel.
Definition Event.hpp:223
int32 y
Y axis value, relative to the direction of the wheel.
Definition Event.hpp:226
uint32 id
The mouse instance identifier, or SDL_TOUCH_MOUSEID.
Definition Event.hpp:220
uint32 window_id
The identifier of the window at the moment of event.
Definition Event.hpp:229
Representation of a program termination request.
Definition Event.hpp:69
void * data1
User-defined data.
Definition Event.hpp:71
void * data2
User-defined data.
Definition Event.hpp:74
A structure containing information on a text editing event.
Definition Event.hpp:426
int32 length
The number of characters to edit from the start point.
Definition Event.hpp:434
int32 start
The location to begin editing from.
Definition Event.hpp:431
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:437
char text[MAX_TEXT_EDITING_LENGTH]
The text being edited.
Definition Event.hpp:428
A structure containing information on a text input event.
Definition Event.hpp:414
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:419
char text[MAX_TEXT_INPUT_LENGTH]
The text input.
Definition Event.hpp:416
A structure containing information on an user event.
Definition Event.hpp:442
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:453
void * data2
User defined data pointer.
Definition Event.hpp:450
int32 code
User defined event code.
Definition Event.hpp:444
void * data1
User defined data pointer.
Definition Event.hpp:447
A structure containing information on a window event.
Definition Event.hpp:79
uint8 event
The window's event type.
Definition Event.hpp:103
EventType
Window event types.
Definition Event.hpp:82
uint32 window_id
The identifier of the window at the moment of the event.
Definition Event.hpp:114
int32 data2
Event dependent data; typically the Y coordinate position or height data of an event.
Definition Event.hpp:111
int32 data1
Event dependent data; typically the X coordinate position or width data of an event.
Definition Event.hpp:107