1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of Nova libraries.
|
---|
5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @file io_event.hh
|
---|
9 | * @author Kornel Kisielewicz
|
---|
10 | * @brief
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef NV_CORE_IO_EVENT_HH
|
---|
14 | #define NV_CORE_IO_EVENT_HH
|
---|
15 |
|
---|
16 | #include <nv/common.hh>
|
---|
17 | #include <nv/core/types.hh>
|
---|
18 |
|
---|
19 | namespace nv
|
---|
20 | {
|
---|
21 |
|
---|
22 | // Generate the key_code enum
|
---|
23 | enum key_code
|
---|
24 | {
|
---|
25 | # define NV_KEY( id, val ) id = val,
|
---|
26 | # include <nv/detail/key_list.inc>
|
---|
27 | # undef NV_KEY
|
---|
28 | };
|
---|
29 |
|
---|
30 | // Generate the mouse_code enum
|
---|
31 | enum mouse_code
|
---|
32 | {
|
---|
33 | # define NV_MOUSE( id, val ) id = val,
|
---|
34 | # include <nv/detail/mouse_list.inc>
|
---|
35 | # undef NV_MOUSE
|
---|
36 | };
|
---|
37 |
|
---|
38 | // Generate the io_event_code enum
|
---|
39 | enum io_event_code
|
---|
40 | {
|
---|
41 | # define NV_IO_EVENT( id ) id,
|
---|
42 | # include <nv/detail/io_event_list.inc>
|
---|
43 | # undef NV_IO_EVENT
|
---|
44 | };
|
---|
45 |
|
---|
46 | struct key_event
|
---|
47 | {
|
---|
48 | /// Associated window ID
|
---|
49 | uint32 window_id;
|
---|
50 |
|
---|
51 | /// Input event ASCII code
|
---|
52 | uchar8 ascii;
|
---|
53 |
|
---|
54 | /// Input event local code
|
---|
55 | key_code code;
|
---|
56 |
|
---|
57 | /// True if shift key is present
|
---|
58 | bool shift;
|
---|
59 |
|
---|
60 | /// True if control key is present
|
---|
61 | bool control;
|
---|
62 |
|
---|
63 | /// True if alt key is present
|
---|
64 | bool alt;
|
---|
65 |
|
---|
66 | /// True if pressed
|
---|
67 | bool pressed;
|
---|
68 |
|
---|
69 | /// native scan code
|
---|
70 | int native;
|
---|
71 | };
|
---|
72 |
|
---|
73 | struct mouse_button_event
|
---|
74 | {
|
---|
75 | /// Associated window ID
|
---|
76 | uint32 window_id;
|
---|
77 |
|
---|
78 | /// X position where mouse was clicked.
|
---|
79 | uint16 x;
|
---|
80 | /// Y position where mouse was clicked.
|
---|
81 | uint16 y;
|
---|
82 | /// Button that was clicked.
|
---|
83 | uint32 button;
|
---|
84 | /// True if pressed
|
---|
85 | bool pressed;
|
---|
86 | /// Mouse button code
|
---|
87 | mouse_code code;
|
---|
88 | };
|
---|
89 |
|
---|
90 | struct mouse_wheel_event
|
---|
91 | {
|
---|
92 | /// Associated window ID
|
---|
93 | uint32 window_id;
|
---|
94 | /// amount scrolled horizontally positive to the right
|
---|
95 | sint32 x;
|
---|
96 | /// amount scrolled vertically
|
---|
97 | sint32 y;
|
---|
98 | };
|
---|
99 |
|
---|
100 | struct mouse_move_event
|
---|
101 | {
|
---|
102 | /// Associated window ID
|
---|
103 | uint32 window_id;
|
---|
104 | /// X Position the mouse moved to.
|
---|
105 | uint16 x;
|
---|
106 | /// Y Position the mouse moved to.
|
---|
107 | uint16 y;
|
---|
108 | /// Distance in x direction mouse was moved.
|
---|
109 | sint16 rx;
|
---|
110 | /// Distance in y direction mouse was moved.
|
---|
111 | sint16 ry;
|
---|
112 | /// True if pressed
|
---|
113 | bool pressed;
|
---|
114 | /// Mouse button code
|
---|
115 | mouse_code code;
|
---|
116 | };
|
---|
117 |
|
---|
118 | struct pad_button_event
|
---|
119 | {
|
---|
120 | /// Pad ID
|
---|
121 | sint32 id;
|
---|
122 | /// Button that is affected
|
---|
123 | uint8 button;
|
---|
124 | /// True if pressed
|
---|
125 | bool pressed;
|
---|
126 | };
|
---|
127 |
|
---|
128 | struct pad_axis_event
|
---|
129 | {
|
---|
130 | /// Pad ID
|
---|
131 | sint32 id;
|
---|
132 | /// Axis ID
|
---|
133 | uint8 axis;
|
---|
134 | /// Value
|
---|
135 | sint16 value;
|
---|
136 | };
|
---|
137 |
|
---|
138 | struct joy_button_event
|
---|
139 | {
|
---|
140 | /// Joystick ID
|
---|
141 | sint32 id;
|
---|
142 | /// Button that is affected
|
---|
143 | uint8 button;
|
---|
144 | /// True if pressed
|
---|
145 | bool pressed;
|
---|
146 | };
|
---|
147 |
|
---|
148 | struct joy_axis_event
|
---|
149 | {
|
---|
150 | /// Joystick ID
|
---|
151 | sint32 id;
|
---|
152 | /// Axis ID
|
---|
153 | uint8 axis;
|
---|
154 | /// Value
|
---|
155 | sint16 value;
|
---|
156 | };
|
---|
157 |
|
---|
158 | struct joy_hat_event
|
---|
159 | {
|
---|
160 | /// Joystick ID
|
---|
161 | sint32 id;
|
---|
162 | /// Hat ID
|
---|
163 | uint8 hat;
|
---|
164 | /// Value
|
---|
165 | sint16 value;
|
---|
166 | };
|
---|
167 |
|
---|
168 | struct joy_ball_event
|
---|
169 | {
|
---|
170 | /// Joystick ID
|
---|
171 | sint32 id;
|
---|
172 | /// Ball ID
|
---|
173 | uint8 ball;
|
---|
174 | /// Relative X
|
---|
175 | sint16 rx;
|
---|
176 | /// Relative Y
|
---|
177 | sint16 ry;
|
---|
178 | };
|
---|
179 |
|
---|
180 | struct resize_event
|
---|
181 | {
|
---|
182 | /// New x size of the object.
|
---|
183 | sint32 x;
|
---|
184 | /// New y size of the object.
|
---|
185 | sint32 y;
|
---|
186 | };
|
---|
187 |
|
---|
188 | struct active_event
|
---|
189 | {
|
---|
190 | /// Whether focus was gained or lost.
|
---|
191 | bool gain;
|
---|
192 | };
|
---|
193 |
|
---|
194 | struct system_event
|
---|
195 | {
|
---|
196 | uint8 sys_type;
|
---|
197 | uint32 param1;
|
---|
198 | uint32 param2;
|
---|
199 | };
|
---|
200 |
|
---|
201 | struct io_event
|
---|
202 | {
|
---|
203 | io_event_code type;
|
---|
204 | union
|
---|
205 | {
|
---|
206 | key_event key;
|
---|
207 | mouse_button_event mbutton;
|
---|
208 | mouse_move_event mmove;
|
---|
209 | mouse_wheel_event mwheel;
|
---|
210 | pad_button_event pbutton;
|
---|
211 | pad_axis_event paxis;
|
---|
212 | joy_button_event jbutton;
|
---|
213 | joy_axis_event jaxis;
|
---|
214 | joy_hat_event jhat;
|
---|
215 | joy_ball_event jball;
|
---|
216 | resize_event resize;
|
---|
217 | active_event active;
|
---|
218 | system_event system;
|
---|
219 | };
|
---|
220 | };
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Gets the name of the key given the code.
|
---|
224 | *
|
---|
225 | * @param key The code value of the key.
|
---|
226 | * @returns The name of the key.
|
---|
227 | */
|
---|
228 | const char* get_key_name( key_code key );
|
---|
229 |
|
---|
230 | /**
|
---|
231 | * Gets the name of the mouse button given the code.
|
---|
232 | *
|
---|
233 | * @param button The code value of the mouse button.
|
---|
234 | * @returns The name of the button.
|
---|
235 | */
|
---|
236 | const char* get_mouse_name( mouse_code button );
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Gets the name of the IO event given the code.
|
---|
240 | *
|
---|
241 | * @param event The code value of the IO event.
|
---|
242 | * @returns The name of the event.
|
---|
243 | */
|
---|
244 | const char* get_io_event_name( io_event_code event );
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Registers all events to the specified database.
|
---|
248 | *
|
---|
249 | * @param db The database to store all event data in.
|
---|
250 | */
|
---|
251 | void register_io_types( type_database* db );
|
---|
252 |
|
---|
253 | void log_event( const io_event& e );
|
---|
254 | }
|
---|
255 |
|
---|
256 | NV_RTTI_DECLARE( nv::key_code )
|
---|
257 | NV_RTTI_DECLARE( nv::mouse_code )
|
---|
258 | NV_RTTI_DECLARE( nv::io_event_code )
|
---|
259 | NV_RTTI_DECLARE( nv::key_event )
|
---|
260 | NV_RTTI_DECLARE( nv::mouse_button_event )
|
---|
261 | NV_RTTI_DECLARE( nv::mouse_wheel_event )
|
---|
262 | NV_RTTI_DECLARE( nv::mouse_move_event )
|
---|
263 | NV_RTTI_DECLARE( nv::pad_button_event )
|
---|
264 | NV_RTTI_DECLARE( nv::pad_axis_event )
|
---|
265 | NV_RTTI_DECLARE( nv::joy_button_event )
|
---|
266 | NV_RTTI_DECLARE( nv::joy_axis_event )
|
---|
267 | NV_RTTI_DECLARE( nv::joy_hat_event )
|
---|
268 | NV_RTTI_DECLARE( nv::joy_ball_event )
|
---|
269 | NV_RTTI_DECLARE( nv::resize_event )
|
---|
270 | NV_RTTI_DECLARE( nv::active_event )
|
---|
271 | NV_RTTI_DECLARE( nv::system_event )
|
---|
272 | NV_RTTI_DECLARE( nv::io_event )
|
---|
273 |
|
---|
274 |
|
---|
275 | #endif // NV_CORE_IO_EVENT_HH
|
---|