1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/*************************************************************************/
/* input_event.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef INPUT_EVENT_H
#define INPUT_EVENT_H
#include "typedefs.h"
#include "os/copymem.h"
#include "ustring.h"
#include "math_2d.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
/**
* Input Event classes. These are used in the main loop.
* The events are pretty obvious.
*/
enum {
BUTTON_LEFT=1,
BUTTON_RIGHT=2,
BUTTON_MIDDLE=3,
BUTTON_WHEEL_UP=4,
BUTTON_WHEEL_DOWN=5,
BUTTON_WHEEL_LEFT=6,
BUTTON_WHEEL_RIGHT=7,
BUTTON_MASK_LEFT=(1<<(BUTTON_LEFT-1)),
BUTTON_MASK_RIGHT=(1<<(BUTTON_RIGHT-1)),
BUTTON_MASK_MIDDLE=(1<<(BUTTON_MIDDLE-1)),
};
enum {
JOY_BUTTON_0 = 0,
JOY_BUTTON_1 = 1,
JOY_BUTTON_2 = 2,
JOY_BUTTON_3 = 3,
JOY_BUTTON_4 = 4,
JOY_BUTTON_5 = 5,
JOY_BUTTON_6 = 6,
JOY_BUTTON_7 = 7,
JOY_BUTTON_8 = 8,
JOY_BUTTON_9 = 9,
JOY_BUTTON_10 = 10,
JOY_BUTTON_11 = 11,
JOY_BUTTON_12 = 12,
JOY_BUTTON_13 = 13,
JOY_BUTTON_14 = 14,
JOY_BUTTON_15 = 15,
JOY_BUTTON_MAX = 16,
JOY_L = JOY_BUTTON_4,
JOY_R = JOY_BUTTON_5,
JOY_L2 = JOY_BUTTON_6,
JOY_R2 = JOY_BUTTON_7,
JOY_L3 = JOY_BUTTON_8,
JOY_R3 = JOY_BUTTON_9,
JOY_SELECT = JOY_BUTTON_10,
JOY_START = JOY_BUTTON_11,
JOY_DPAD_UP = JOY_BUTTON_12,
JOY_DPAD_DOWN = JOY_BUTTON_13,
JOY_DPAD_LEFT = JOY_BUTTON_14,
JOY_DPAD_RIGHT = JOY_BUTTON_15,
// a little history about game controllers (who copied who)
JOY_SNES_B = JOY_BUTTON_0,
JOY_SNES_A = JOY_BUTTON_1,
JOY_SNES_Y = JOY_BUTTON_2,
JOY_SNES_X = JOY_BUTTON_3,
JOY_SONY_CIRCLE=JOY_SNES_A,
JOY_SONY_X=JOY_SNES_B,
JOY_SONY_SQUARE=JOY_SNES_Y,
JOY_SONY_TRIANGLE=JOY_SNES_X,
JOY_SEGA_B=JOY_SNES_A,
JOY_SEGA_A=JOY_SNES_B,
JOY_SEGA_X=JOY_SNES_Y,
JOY_SEGA_Y=JOY_SNES_X,
JOY_XBOX_B=JOY_SEGA_B,
JOY_XBOX_A=JOY_SEGA_A,
JOY_XBOX_X=JOY_SEGA_X,
JOY_XBOX_Y=JOY_SEGA_Y,
JOY_DS_A = JOY_SNES_A,
JOY_DS_B = JOY_SNES_B,
JOY_DS_X = JOY_SNES_X,
JOY_DS_Y = JOY_SNES_Y,
JOY_WII_C = JOY_BUTTON_5,
JOY_WII_Z = JOY_BUTTON_6,
JOY_WII_MINUS = JOY_BUTTON_9,
JOY_WII_PLUS = JOY_BUTTON_10,
// end of history
JOY_AXIS_0=0,
JOY_AXIS_1=1,
JOY_AXIS_2=2,
JOY_AXIS_3=3,
JOY_AXIS_4=4,
JOY_AXIS_5=5,
JOY_AXIS_6=6,
JOY_AXIS_7=7,
JOY_AXIS_MAX=8,
JOY_ANALOG_0_X = JOY_AXIS_0,
JOY_ANALOG_0_Y = JOY_AXIS_1,
JOY_ANALOG_1_X = JOY_AXIS_2,
JOY_ANALOG_1_Y = JOY_AXIS_3,
JOY_ANALOG_2_X = JOY_AXIS_4,
JOY_ANALOG_2_Y = JOY_AXIS_5,
JOY_ANALOG_L2 = JOY_AXIS_6,
JOY_ANALOG_R2 = JOY_AXIS_7,
};
/**
* Input Modifier Status
* for keyboard/mouse events.
*/
struct InputModifierState {
bool shift;
bool alt;
#ifdef APPLE_STYLE_KEYS
union {
bool command;
bool meta; //< windows/mac key
};
bool control;
#else
union {
bool command; //< windows/mac key
bool control;
};
bool meta; //< windows/mac key
#endif
bool operator==(const InputModifierState& rvalue) const {
return ( (shift==rvalue.shift) && (alt==rvalue.alt) && (control==rvalue.control) && (meta==rvalue.meta));
}
};
struct InputEventKey {
InputModifierState mod;
bool pressed; /// otherwise release
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
uint32_t unicode; ///unicode
uint32_t get_scancode_with_modifiers() const;
bool echo; /// true if this is an echo key
};
struct InputEventMouse {
InputModifierState mod;
int button_mask;
int x,y;
int global_x,global_y;
int pointer_index;
};
struct InputEventMouseButton : public InputEventMouse {
int button_index;
bool pressed; //otherwise released
bool doubleclick; //last even less than doubleclick time
};
struct InputEventMouseMotion : public InputEventMouse {
int relative_x,relative_y;
float speed_x,speed_y;
};
struct InputEventJoystickMotion {
int axis; ///< Joystick axis
float axis_value; ///< -1 to 1
};
struct InputEventJoystickButton {
int button_index;
bool pressed;
float pressure; //0 to 1
};
struct InputEventScreenTouch {
int index;
int x,y;
bool pressed;
};
struct InputEventScreenDrag {
int index;
int x,y;
int relative_x,relative_y;
float speed_x,speed_y;
};
struct InputEventAction {
int action;
bool pressed;
};
struct InputEvent {
enum Type {
NONE,
KEY,
MOUSE_MOTION,
MOUSE_BUTTON,
JOYSTICK_MOTION,
JOYSTICK_BUTTON,
SCREEN_TOUCH,
SCREEN_DRAG,
ACTION,
TYPE_MAX
};
uint32_t ID;
int type;
int device;
union {
InputEventMouseMotion mouse_motion;
InputEventMouseButton mouse_button;
InputEventJoystickMotion joy_motion;
InputEventJoystickButton joy_button;
InputEventKey key;
InputEventScreenTouch screen_touch;
InputEventScreenDrag screen_drag;
InputEventAction action;
};
bool is_pressed() const;
bool is_action(const String& p_action) const;
bool is_action_pressed(const String& p_action) const;
bool is_action_released(const String& p_action) const;
bool is_echo() const;
void set_as_action(const String& p_action, bool p_pressed);
InputEvent xform_by(const Matrix32& p_xform) const;
bool operator==(const InputEvent &p_event) const;
operator String() const;
InputEvent() { zeromem(this,sizeof(InputEvent)); }
};
#endif
|