1 | // Copyright (C) 2012-2014 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of NV Libraries.
|
---|
5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
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/core/common.hh>
|
---|
17 |
|
---|
18 | namespace nv
|
---|
19 | {
|
---|
20 |
|
---|
21 | // Generate the key_code enum
|
---|
22 | enum key_code
|
---|
23 | {
|
---|
24 | # define NV_KEY( id, val ) id = val,
|
---|
25 | # include <nv/detail/key_list.inc>
|
---|
26 | # undef NV_KEY
|
---|
27 | };
|
---|
28 |
|
---|
29 | // Generate the mouse_code enum
|
---|
30 | enum mouse_code
|
---|
31 | {
|
---|
32 | # define NV_MOUSE( id, val ) id = val,
|
---|
33 | # include <nv/detail/mouse_list.inc>
|
---|
34 | # undef NV_MOUSE
|
---|
35 | };
|
---|
36 |
|
---|
37 | // Generate the io_event_code enum
|
---|
38 | enum io_event_code
|
---|
39 | {
|
---|
40 | # define NV_IO_EVENT( id ) id,
|
---|
41 | # include <nv/detail/io_event_list.inc>
|
---|
42 | # undef NV_IO_EVENT
|
---|
43 | };
|
---|
44 |
|
---|
45 | struct key_event
|
---|
46 | {
|
---|
47 | /// Input event ASCII code
|
---|
48 | char8 ascii;
|
---|
49 |
|
---|
50 | /// Input event local code
|
---|
51 | key_code code;
|
---|
52 |
|
---|
53 | /// True if shift key is present
|
---|
54 | bool shift;
|
---|
55 |
|
---|
56 | /// True if control key is present
|
---|
57 | bool control;
|
---|
58 |
|
---|
59 | /// True if alt key is present
|
---|
60 | bool alt;
|
---|
61 |
|
---|
62 | /// True if pressed
|
---|
63 | bool pressed;
|
---|
64 | };
|
---|
65 |
|
---|
66 | struct mouse_button_event
|
---|
67 | {
|
---|
68 | /// X position where mouse was clicked.
|
---|
69 | uint16 x;
|
---|
70 | /// Y position where mouse was clicked.
|
---|
71 | uint16 y;
|
---|
72 | /// Button that was clicked.
|
---|
73 | uint32 button;
|
---|
74 | /// True if pressed
|
---|
75 | bool pressed;
|
---|
76 | /// Mouse button code
|
---|
77 | mouse_code code;
|
---|
78 | };
|
---|
79 |
|
---|
80 | struct mouse_wheel_event
|
---|
81 | {
|
---|
82 | /// amount scrolled horizontally positive to the right
|
---|
83 | sint32 x;
|
---|
84 | /// amount scrolled vertically
|
---|
85 | sint32 y;
|
---|
86 | };
|
---|
87 |
|
---|
88 | struct mouse_move_event
|
---|
89 | {
|
---|
90 | /// X Position the mouse moved to.
|
---|
91 | uint16 x;
|
---|
92 | /// Y Position the mouse moved to.
|
---|
93 | uint16 y;
|
---|
94 | /// Distance in x direction mouse was moved.
|
---|
95 | sint16 rx;
|
---|
96 | /// Distance in y direction mouse was moved.
|
---|
97 | sint16 ry;
|
---|
98 | /// True if pressed
|
---|
99 | bool pressed;
|
---|
100 | /// Mouse button code
|
---|
101 | mouse_code code;
|
---|
102 | };
|
---|
103 |
|
---|
104 | struct joy_button_event
|
---|
105 | {
|
---|
106 | /// Joystick ID
|
---|
107 | sint32 id;
|
---|
108 | /// Button that is affected
|
---|
109 | uint8 button;
|
---|
110 | /// True if pressed
|
---|
111 | bool pressed;
|
---|
112 | };
|
---|
113 |
|
---|
114 | struct joy_axis_event
|
---|
115 | {
|
---|
116 | /// Joystick ID
|
---|
117 | sint32 id;
|
---|
118 | /// Axis ID
|
---|
119 | uint8 axis;
|
---|
120 | /// Value
|
---|
121 | sint16 value;
|
---|
122 | };
|
---|
123 |
|
---|
124 | struct joy_hat_event
|
---|
125 | {
|
---|
126 | /// Joystick ID
|
---|
127 | sint32 id;
|
---|
128 | /// Hat ID
|
---|
129 | uint8 hat;
|
---|
130 | /// Value
|
---|
131 | sint16 value;
|
---|
132 | };
|
---|
133 |
|
---|
134 | struct joy_ball_event
|
---|
135 | {
|
---|
136 | /// Joystick ID
|
---|
137 | sint32 id;
|
---|
138 | /// Ball ID
|
---|
139 | uint8 ball;
|
---|
140 | /// Relative X
|
---|
141 | sint16 rx;
|
---|
142 | /// Relative Y
|
---|
143 | sint16 ry;
|
---|
144 | };
|
---|
145 |
|
---|
146 | struct resize_event
|
---|
147 | {
|
---|
148 | /// New x size of the object.
|
---|
149 | sint32 x;
|
---|
150 | /// New y size of the object.
|
---|
151 | sint32 y;
|
---|
152 | };
|
---|
153 |
|
---|
154 | struct active_event
|
---|
155 | {
|
---|
156 | /// Whether focus was gained or lost.
|
---|
157 | bool gain;
|
---|
158 | };
|
---|
159 |
|
---|
160 | struct system_event
|
---|
161 | {
|
---|
162 | uint8 sys_type;
|
---|
163 | uint32 param1;
|
---|
164 | uint32 param2;
|
---|
165 | };
|
---|
166 |
|
---|
167 | struct io_event
|
---|
168 | {
|
---|
169 | io_event_code type;
|
---|
170 | union
|
---|
171 | {
|
---|
172 | key_event key;
|
---|
173 | mouse_button_event mbutton;
|
---|
174 | mouse_move_event mmove;
|
---|
175 | mouse_wheel_event mwheel;
|
---|
176 | joy_button_event jbutton;
|
---|
177 | joy_axis_event jaxis;
|
---|
178 | joy_hat_event jhat;
|
---|
179 | joy_ball_event jball;
|
---|
180 | resize_event resize;
|
---|
181 | active_event active;
|
---|
182 | system_event system;
|
---|
183 | };
|
---|
184 | };
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Gets the name of the key given the code.
|
---|
188 | *
|
---|
189 | * @param key The code value of the key.
|
---|
190 | * @returns The name of the key.
|
---|
191 | */
|
---|
192 | const char* get_key_name( key_code key );
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Gets the name of the mouse button given the code.
|
---|
196 | *
|
---|
197 | * @param button The code value of the mouse button.
|
---|
198 | * @returns The name of the button.
|
---|
199 | */
|
---|
200 | const char* get_mouse_name( mouse_code button );
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Gets the name of the IO event given the code.
|
---|
204 | *
|
---|
205 | * @param event The code value of the IO event.
|
---|
206 | * @returns The name of the event.
|
---|
207 | */
|
---|
208 | const char* get_io_event_name( io_event_code event );
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Registers all events to the specified database.
|
---|
212 | *
|
---|
213 | * @param db The database to store all event data in.
|
---|
214 | */
|
---|
215 | //void register_io_types( type_database* db );
|
---|
216 | }
|
---|
217 |
|
---|
218 | #endif // NV_CORE_IO_EVENT_HH
|
---|