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