1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Reto Grieder |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file |
---|
31 | @brief |
---|
32 | Declarations of various interface classes for the input management. |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _InputInterfaces_H__ |
---|
36 | #define _InputInterfaces_H__ |
---|
37 | |
---|
38 | #include "core/CorePrereqs.h" |
---|
39 | |
---|
40 | #include "ois/OISKeyboard.h" |
---|
41 | #include "ois/OISMouse.h" |
---|
42 | #include "ois/OISJoyStick.h" |
---|
43 | #include "util/Math.h" |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | namespace KeyCode |
---|
48 | { |
---|
49 | // note: KeyCode comments were directly copied from OISKeyboard.h |
---|
50 | enum Enum |
---|
51 | { |
---|
52 | Unassigned = OIS::KC_UNASSIGNED, |
---|
53 | Escape = OIS::KC_ESCAPE, |
---|
54 | NumRow1 = OIS::KC_1, |
---|
55 | NumRow2 = OIS::KC_2, |
---|
56 | NumRow3 = OIS::KC_3, |
---|
57 | NumRow4 = OIS::KC_4, |
---|
58 | NumRow5 = OIS::KC_5, |
---|
59 | NumRow6 = OIS::KC_6, |
---|
60 | NumRow7 = OIS::KC_7, |
---|
61 | NumRow8 = OIS::KC_8, |
---|
62 | NumRow9 = OIS::KC_9, |
---|
63 | NumRow0 = OIS::KC_0, |
---|
64 | Minus = OIS::KC_MINUS, // - on main keyboard |
---|
65 | Equals = OIS::KC_EQUALS, |
---|
66 | Back = OIS::KC_BACK, // backspace |
---|
67 | Tab = OIS::KC_TAB, |
---|
68 | Q = OIS::KC_Q, |
---|
69 | W = OIS::KC_W, |
---|
70 | E = OIS::KC_E, |
---|
71 | R = OIS::KC_R, |
---|
72 | T = OIS::KC_T, |
---|
73 | Y = OIS::KC_Y, |
---|
74 | U = OIS::KC_U, |
---|
75 | I = OIS::KC_I, |
---|
76 | O = OIS::KC_O, |
---|
77 | P = OIS::KC_P, |
---|
78 | LeftBracket = OIS::KC_LBRACKET, |
---|
79 | RightBracket = OIS::KC_RBRACKET, |
---|
80 | Return = OIS::KC_RETURN, // Enter on main keyboard |
---|
81 | LeftControl = OIS::KC_LCONTROL, |
---|
82 | A = OIS::KC_A, |
---|
83 | S = OIS::KC_S, |
---|
84 | D = OIS::KC_D, |
---|
85 | F = OIS::KC_F, |
---|
86 | G = OIS::KC_G, |
---|
87 | H = OIS::KC_H, |
---|
88 | J = OIS::KC_J, |
---|
89 | K = OIS::KC_K, |
---|
90 | L = OIS::KC_L, |
---|
91 | Semicolon = OIS::KC_SEMICOLON, |
---|
92 | Apostrophe = OIS::KC_APOSTROPHE, |
---|
93 | Grave = OIS::KC_GRAVE, // accent |
---|
94 | LeftShift = OIS::KC_LSHIFT, |
---|
95 | Backslash = OIS::KC_BACKSLASH, |
---|
96 | Z = OIS::KC_Z, |
---|
97 | X = OIS::KC_X, |
---|
98 | C = OIS::KC_C, |
---|
99 | V = OIS::KC_V, |
---|
100 | B = OIS::KC_B, |
---|
101 | N = OIS::KC_N, |
---|
102 | M = OIS::KC_M, |
---|
103 | Comma = OIS::KC_COMMA, |
---|
104 | Period = OIS::KC_PERIOD, // . on main keyboard |
---|
105 | Slash = OIS::KC_SLASH, // / on main keyboard |
---|
106 | RightShift = OIS::KC_RSHIFT, |
---|
107 | Multiply = OIS::KC_MULTIPLY, // * on numeric keypad |
---|
108 | LeftAlt = OIS::KC_LMENU, // left Alt |
---|
109 | Space = OIS::KC_SPACE, |
---|
110 | CapsLock = OIS::KC_CAPITAL, |
---|
111 | F1 = OIS::KC_F1, |
---|
112 | F2 = OIS::KC_F2, |
---|
113 | F3 = OIS::KC_F3, |
---|
114 | F4 = OIS::KC_F4, |
---|
115 | F5 = OIS::KC_F5, |
---|
116 | F6 = OIS::KC_F6, |
---|
117 | F7 = OIS::KC_F7, |
---|
118 | F8 = OIS::KC_F8, |
---|
119 | F9 = OIS::KC_F9, |
---|
120 | F10 = OIS::KC_F10, |
---|
121 | Numlock = OIS::KC_NUMLOCK, |
---|
122 | Scrolllock = OIS::KC_SCROLL, // Scroll Lock |
---|
123 | Numpad7 = OIS::KC_NUMPAD7, |
---|
124 | Numpad8 = OIS::KC_NUMPAD8, |
---|
125 | Numpad9 = OIS::KC_NUMPAD9, |
---|
126 | NumpadSubtract= OIS::KC_SUBTRACT, // - on numeric keypad |
---|
127 | Numpad4 = OIS::KC_NUMPAD4, |
---|
128 | Numpad5 = OIS::KC_NUMPAD5, |
---|
129 | Numpad6 = OIS::KC_NUMPAD6, |
---|
130 | NumpadAdd = OIS::KC_ADD, // + on numeric keypad |
---|
131 | Numpad1 = OIS::KC_NUMPAD1, |
---|
132 | Numpad2 = OIS::KC_NUMPAD2, |
---|
133 | Numpad3 = OIS::KC_NUMPAD3, |
---|
134 | Numpad0 = OIS::KC_NUMPAD0, |
---|
135 | NumpadPeriod = OIS::KC_DECIMAL, // . on numeric keypad |
---|
136 | LessThan = OIS::KC_OEM_102, // < > | on UK/Germany keyboards |
---|
137 | F11 = OIS::KC_F11, |
---|
138 | F12 = OIS::KC_F12, |
---|
139 | F13 = OIS::KC_F13, // (NEC PC98) |
---|
140 | F14 = OIS::KC_F14, // (NEC PC98) |
---|
141 | F15 = OIS::KC_F15, // (NEC PC98) |
---|
142 | Kana = OIS::KC_KANA, // (Japanese keyboard) |
---|
143 | ABNT_C1 = OIS::KC_ABNT_C1, // / ? on Portugese (Brazilian) keyboards |
---|
144 | Convert = OIS::KC_CONVERT, // (Japanese keyboard) |
---|
145 | NoConvert = OIS::KC_NOCONVERT, // (Japanese keyboard) |
---|
146 | Yen = OIS::KC_YEN, // (Japanese keyboard) |
---|
147 | ABNT_C2 = OIS::KC_ABNT_C2, // Numpad . on Portugese (Brazilian) keyboards |
---|
148 | NumpadEquals = OIS::KC_NUMPADEQUALS, // = on numeric keypad (NEC PC98) |
---|
149 | PreviousTrack = OIS::KC_PREVTRACK, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard) |
---|
150 | AT = OIS::KC_AT, // (NEC PC98) |
---|
151 | Colon = OIS::KC_COLON, // (NEC PC98) |
---|
152 | Underline = OIS::KC_UNDERLINE, // (NEC PC98) |
---|
153 | Kanji = OIS::KC_KANJI, // (Japanese keyboard) |
---|
154 | Stop = OIS::KC_STOP, // (NEC PC98) |
---|
155 | AX = OIS::KC_AX, // (Japan AX) |
---|
156 | Unlabeled = OIS::KC_UNLABELED, // (J3100) |
---|
157 | NextTrack = OIS::KC_NEXTTRACK, // Next Track |
---|
158 | NumpadEnter = OIS::KC_NUMPADENTER, // Enter on numeric keypad |
---|
159 | RightControl = OIS::KC_RCONTROL, |
---|
160 | Mute = OIS::KC_MUTE, // Mute |
---|
161 | Calculator = OIS::KC_CALCULATOR, // Calculator |
---|
162 | PlayPause = OIS::KC_PLAYPAUSE, // Play / Pause |
---|
163 | MediaStop = OIS::KC_MEDIASTOP, // Media Stop |
---|
164 | VolumeDown = OIS::KC_VOLUMEDOWN, // Volume - |
---|
165 | VolumeUp = OIS::KC_VOLUMEUP, // Volume + |
---|
166 | WebHome = OIS::KC_WEBHOME, // Web home |
---|
167 | NumpadComma = OIS::KC_NUMPADCOMMA, // , on numeric keypad (NEC PC98) |
---|
168 | Divide = OIS::KC_DIVIDE, // / on numeric keypad |
---|
169 | SYSRQ = OIS::KC_SYSRQ, |
---|
170 | RightAlt = OIS::KC_RMENU, // right Alt |
---|
171 | Pause = OIS::KC_PAUSE, // Pause |
---|
172 | Home = OIS::KC_HOME, // Home on arrow keypad |
---|
173 | Up = OIS::KC_UP, // UpArrow on arrow keypad |
---|
174 | PageUp = OIS::KC_PGUP, // PgUp on arrow keypad |
---|
175 | Left = OIS::KC_LEFT, // LeftArrow on arrow keypad |
---|
176 | Right = OIS::KC_RIGHT, // RightArrow on arrow keypad |
---|
177 | End = OIS::KC_END, // End on arrow keypad |
---|
178 | Down = OIS::KC_DOWN, // DownArrow on arrow keypad |
---|
179 | PageDown = OIS::KC_PGDOWN, // PgDn on arrow keypad |
---|
180 | Insert = OIS::KC_INSERT, // Insert on arrow keypad |
---|
181 | Delete = OIS::KC_DELETE, // Delete on arrow keypad |
---|
182 | LeftWindows = OIS::KC_LWIN, // Left Windows key |
---|
183 | RightWindows = OIS::KC_RWIN, // Right Windows key |
---|
184 | Apps = OIS::KC_APPS, // AppMenu key |
---|
185 | Power = OIS::KC_POWER, // System Power |
---|
186 | Sleep = OIS::KC_SLEEP, // System Sleep |
---|
187 | Wake = OIS::KC_WAKE, // System Wake |
---|
188 | WebSearch = OIS::KC_WEBSEARCH, // Web Search |
---|
189 | WebFavorites = OIS::KC_WEBFAVORITES, // Web Favorites |
---|
190 | WebRefresh = OIS::KC_WEBREFRESH, // Web Refresh |
---|
191 | WebStop = OIS::KC_WEBSTOP, // Web Stop |
---|
192 | WebForward = OIS::KC_WEBFORWARD, // Web Forward |
---|
193 | WebBack = OIS::KC_WEBBACK, // Web Back |
---|
194 | MyComputer = OIS::KC_MYCOMPUTER, // My Computer |
---|
195 | Mail = OIS::KC_MAIL, // Mail |
---|
196 | MediaSelect = OIS::KC_MEDIASELECT // Media Select |
---|
197 | }; |
---|
198 | } |
---|
199 | |
---|
200 | namespace MouseButton |
---|
201 | { |
---|
202 | enum Enum |
---|
203 | { |
---|
204 | Left = OIS::MB_Left, |
---|
205 | Right = OIS::MB_Right, |
---|
206 | Middle = OIS::MB_Middle, |
---|
207 | Button3 = OIS::MB_Button3, |
---|
208 | Button4 = OIS::MB_Button4, |
---|
209 | Button5 = OIS::MB_Button5, |
---|
210 | Button6 = OIS::MB_Button6, |
---|
211 | Button7 = OIS::MB_Button7 |
---|
212 | }; |
---|
213 | } |
---|
214 | |
---|
215 | namespace JoyStickButton |
---|
216 | { |
---|
217 | enum Enum |
---|
218 | { |
---|
219 | Button0 = 0, Button1 = 1, Button2 = 2, Button3 = 3, |
---|
220 | Button4 = 4, Button5 = 5, Button6 = 6, Button7 = 7, |
---|
221 | Button8 = 8, Button9 = 9, Button10 = 10, Button11 = 11, |
---|
222 | Button12 = 12, Button13 = 13, Button14 = 14, Button15 = 15, |
---|
223 | Button16 = 16, Button17 = 17, Button18 = 18, Button19 = 19, |
---|
224 | Button20 = 20, Button21 = 21, Button22 = 22, Button23 = 23, |
---|
225 | Button24 = 24, Button25 = 25, Button26 = 26, Button27 = 27, |
---|
226 | Button28 = 28, Button29 = 29, Button30 = 30, Button31 = 31, |
---|
227 | |
---|
228 | POV0North = 32, POV0South = 33, POV0East = 34, POV0West = 35, |
---|
229 | POV0NorthEast = 36, POV0SouthEast = 37, POV0NorthWest = 38, POV0SouthWest = 39, |
---|
230 | |
---|
231 | POV1North = 40, POV1South = 41, POV1East = 42, POV1West = 43, |
---|
232 | POV1NorthEast = 44, POV1SouthEast = 45, POV1NorthWest = 46, POV1SouthWest = 47, |
---|
233 | |
---|
234 | POV2North = 48, POV2South = 49, POV2East = 50, POV2West = 51, |
---|
235 | POV2NorthEast = 52, POV2SouthEast = 53, POV2NorthWest = 54, POV2SouthWest = 55, |
---|
236 | |
---|
237 | POV3North = 56, POV3South = 57, POV3East = 58, POV3West = 59, |
---|
238 | POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63, |
---|
239 | }; |
---|
240 | } |
---|
241 | |
---|
242 | namespace KeyboardModifier |
---|
243 | { |
---|
244 | enum Enum |
---|
245 | { |
---|
246 | Shift = 0x0000001, |
---|
247 | Ctrl = 0x0000010, |
---|
248 | Alt = 0x0000100 |
---|
249 | }; |
---|
250 | } |
---|
251 | |
---|
252 | namespace InputDevice |
---|
253 | { |
---|
254 | enum Enum |
---|
255 | { |
---|
256 | Keyboard, |
---|
257 | Mouse, |
---|
258 | JoyStick0, |
---|
259 | JoyStick1, |
---|
260 | JoyStick2, |
---|
261 | JoyStick3, |
---|
262 | // note: No problem if there are more joy sticks. This enum is just for convenience. |
---|
263 | }; |
---|
264 | } |
---|
265 | |
---|
266 | struct _CoreExport Key |
---|
267 | { |
---|
268 | Key(const OIS::KeyEvent& evt) : key((KeyCode::Enum)evt.key), text(evt.text) { } |
---|
269 | KeyCode::Enum key; |
---|
270 | unsigned int text; |
---|
271 | }; |
---|
272 | |
---|
273 | class _CoreExport KeyEvent |
---|
274 | { |
---|
275 | public: |
---|
276 | KeyEvent(KeyCode::Enum key, unsigned int text) : key(key), text(text) { } |
---|
277 | KeyEvent(const OIS::KeyEvent& evt, unsigned int mod) |
---|
278 | : key((KeyCode::Enum)evt.key), text(evt.text), modifiers(mod) { } |
---|
279 | KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { } |
---|
280 | bool isModifierDown(KeyboardModifier::Enum modifier) const |
---|
281 | { return (KeyboardModifier::Enum)modifier&modifiers; } |
---|
282 | |
---|
283 | const KeyCode::Enum key; |
---|
284 | unsigned int text; |
---|
285 | unsigned int modifiers; |
---|
286 | }; |
---|
287 | |
---|
288 | |
---|
289 | class _CoreExport InputHandler |
---|
290 | { |
---|
291 | public: |
---|
292 | virtual ~InputHandler() { } |
---|
293 | virtual void tickInput(float dt) = 0; |
---|
294 | }; |
---|
295 | |
---|
296 | /** |
---|
297 | @brief |
---|
298 | Interface class used for key input listeners. |
---|
299 | */ |
---|
300 | class _CoreExport KeyHandler : virtual public InputHandler |
---|
301 | { |
---|
302 | public: |
---|
303 | virtual ~KeyHandler() { } |
---|
304 | virtual void keyPressed (const KeyEvent& evt) = 0; |
---|
305 | virtual void keyReleased(const KeyEvent& evt) = 0; |
---|
306 | virtual void keyHeld (const KeyEvent& evt) = 0; |
---|
307 | virtual void tickKey (float dt) = 0; |
---|
308 | }; |
---|
309 | |
---|
310 | /** |
---|
311 | @brief |
---|
312 | Interface class used for mouse input listeners. |
---|
313 | */ |
---|
314 | class _CoreExport MouseHandler : virtual public InputHandler |
---|
315 | { |
---|
316 | public: |
---|
317 | virtual ~MouseHandler() { } |
---|
318 | virtual void mouseButtonPressed (MouseButton::Enum id) = 0; |
---|
319 | virtual void mouseButtonReleased(MouseButton::Enum id) = 0; |
---|
320 | virtual void mouseButtonHeld (MouseButton::Enum id) = 0; |
---|
321 | virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; |
---|
322 | virtual void mouseScrolled (int abs, int rel) = 0; |
---|
323 | virtual void tickMouse (float dt) = 0; |
---|
324 | }; |
---|
325 | |
---|
326 | |
---|
327 | /** |
---|
328 | @brief |
---|
329 | Interface class used for joy stick input listeners. |
---|
330 | */ |
---|
331 | class _CoreExport JoyStickHandler : virtual public InputHandler |
---|
332 | { |
---|
333 | public: |
---|
334 | virtual ~JoyStickHandler() { } |
---|
335 | virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0; |
---|
336 | virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0; |
---|
337 | virtual void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton::Enum id) = 0; |
---|
338 | virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; |
---|
339 | virtual void tickJoyStick (float dt, unsigned int joyStick) = 0; |
---|
340 | }; |
---|
341 | |
---|
342 | class _CoreExport EmptyHandler : public KeyHandler, public MouseHandler, public JoyStickHandler |
---|
343 | { |
---|
344 | friend class InputManager; |
---|
345 | private: |
---|
346 | EmptyHandler() { } |
---|
347 | EmptyHandler(EmptyHandler&); |
---|
348 | virtual ~EmptyHandler() { } |
---|
349 | |
---|
350 | void tickInput(float dt) { } |
---|
351 | void tickJoyStick(float dt, unsigned int joyStick) { } |
---|
352 | void tickMouse(float dt) { } |
---|
353 | void tickKey(float dt) { } |
---|
354 | |
---|
355 | void keyPressed (const KeyEvent& evt) { } |
---|
356 | void keyReleased(const KeyEvent& evt) { } |
---|
357 | void keyHeld (const KeyEvent& evt) { } |
---|
358 | |
---|
359 | void mouseButtonPressed (MouseButton::Enum id) { } |
---|
360 | void mouseButtonReleased(MouseButton::Enum id) { } |
---|
361 | void mouseButtonHeld (MouseButton::Enum id) { } |
---|
362 | void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { } |
---|
363 | void mouseScrolled (int abs, int rel) { } |
---|
364 | |
---|
365 | void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) { } |
---|
366 | void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) { } |
---|
367 | void joyStickButtonHeld (unsigned int joyStickID, JoyStickButton::Enum id) { } |
---|
368 | void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) { } |
---|
369 | }; |
---|
370 | |
---|
371 | } |
---|
372 | |
---|
373 | #endif /* _InputInterfaces_H__ */ |
---|