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 Declarations of various interface classes for the input management. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef _InputInterfaces_H__ |
---|
35 | #define _InputInterfaces_H__ |
---|
36 | |
---|
37 | #include "core/CorePrereqs.h" |
---|
38 | |
---|
39 | #include "src/ois/OISKeyboard.h" |
---|
40 | #include "src/ois/OISMouse.h" |
---|
41 | #include "src/ois/OISJoyStick.h" |
---|
42 | #include "util/Math.h" |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | namespace KeyCode |
---|
47 | { |
---|
48 | // note: KeyCode comments were directly taken from OISKeyboard.h |
---|
49 | enum Enum |
---|
50 | { |
---|
51 | Unassigned = OIS::KC_UNASSIGNED, |
---|
52 | Escape = OIS::KC_ESCAPE, |
---|
53 | NumRow1 = OIS::KC_1, |
---|
54 | NumRow2 = OIS::KC_2, |
---|
55 | NumRow3 = OIS::KC_3, |
---|
56 | NumRow4 = OIS::KC_4, |
---|
57 | NumRow5 = OIS::KC_5, |
---|
58 | NumRow6 = OIS::KC_6, |
---|
59 | NumRow7 = OIS::KC_7, |
---|
60 | NumRow8 = OIS::KC_8, |
---|
61 | NumRow9 = OIS::KC_9, |
---|
62 | NumRow0 = OIS::KC_0, |
---|
63 | Minus = OIS::KC_MINUS, // - on main keyboard |
---|
64 | Equals = OIS::KC_EQUALS, |
---|
65 | Back = OIS::KC_BACK, // backspace |
---|
66 | Tab = OIS::KC_TAB, |
---|
67 | Q = OIS::KC_Q, |
---|
68 | W = OIS::KC_W, |
---|
69 | E = OIS::KC_E, |
---|
70 | R = OIS::KC_R, |
---|
71 | T = OIS::KC_T, |
---|
72 | Y = OIS::KC_Y, |
---|
73 | U = OIS::KC_U, |
---|
74 | I = OIS::KC_I, |
---|
75 | O = OIS::KC_O, |
---|
76 | P = OIS::KC_P, |
---|
77 | LeftBracket = OIS::KC_LBRACKET, |
---|
78 | RightBracket = OIS::KC_RBRACKET, |
---|
79 | Return = OIS::KC_RETURN, // Enter on main keyboard |
---|
80 | LeftControl = OIS::KC_LCONTROL, |
---|
81 | A = OIS::KC_A, |
---|
82 | S = OIS::KC_S, |
---|
83 | D = OIS::KC_D, |
---|
84 | F = OIS::KC_F, |
---|
85 | G = OIS::KC_G, |
---|
86 | H = OIS::KC_H, |
---|
87 | J = OIS::KC_J, |
---|
88 | K = OIS::KC_K, |
---|
89 | L = OIS::KC_L, |
---|
90 | Semicolon = OIS::KC_SEMICOLON, |
---|
91 | Apostrophe = OIS::KC_APOSTROPHE, |
---|
92 | Grave = OIS::KC_GRAVE, // accent |
---|
93 | LeftShift = OIS::KC_LSHIFT, |
---|
94 | Backslash = OIS::KC_BACKSLASH, |
---|
95 | Z = OIS::KC_Z, |
---|
96 | X = OIS::KC_X, |
---|
97 | C = OIS::KC_C, |
---|
98 | V = OIS::KC_V, |
---|
99 | B = OIS::KC_B, |
---|
100 | N = OIS::KC_N, |
---|
101 | M = OIS::KC_M, |
---|
102 | Comma = OIS::KC_COMMA, |
---|
103 | Period = OIS::KC_PERIOD, // . on main keyboard |
---|
104 | Slash = OIS::KC_SLASH, // / on main keyboard |
---|
105 | RightShift = OIS::KC_RSHIFT, |
---|
106 | Multiply = OIS::KC_MULTIPLY, // * on numeric keypad |
---|
107 | LeftAlt = OIS::KC_LMENU, // left Alt |
---|
108 | Space = OIS::KC_SPACE, |
---|
109 | CapsLock = OIS::KC_CAPITAL, |
---|
110 | F1 = OIS::KC_F1, |
---|
111 | F2 = OIS::KC_F2, |
---|
112 | F3 = OIS::KC_F3, |
---|
113 | F4 = OIS::KC_F4, |
---|
114 | F5 = OIS::KC_F5, |
---|
115 | F6 = OIS::KC_F6, |
---|
116 | F7 = OIS::KC_F7, |
---|
117 | F8 = OIS::KC_F8, |
---|
118 | F9 = OIS::KC_F9, |
---|
119 | F10 = OIS::KC_F10, |
---|
120 | Numlock = OIS::KC_NUMLOCK, |
---|
121 | Scrolllock = OIS::KC_SCROLL, // Scroll Lock |
---|
122 | Numpad7 = OIS::KC_NUMPAD7, |
---|
123 | Numpad8 = OIS::KC_NUMPAD8, |
---|
124 | Numpad9 = OIS::KC_NUMPAD9, |
---|
125 | NumpadSubtract= OIS::KC_SUBTRACT, // - on numeric keypad |
---|
126 | Numpad4 = OIS::KC_NUMPAD4, |
---|
127 | Numpad5 = OIS::KC_NUMPAD5, |
---|
128 | Numpad6 = OIS::KC_NUMPAD6, |
---|
129 | NumpadAdd = OIS::KC_ADD, // + on numeric keypad |
---|
130 | Numpad1 = OIS::KC_NUMPAD1, |
---|
131 | Numpad2 = OIS::KC_NUMPAD2, |
---|
132 | Numpad3 = OIS::KC_NUMPAD3, |
---|
133 | Numpad0 = OIS::KC_NUMPAD0, |
---|
134 | NumpadPeriod = OIS::KC_DECIMAL, // . on numeric keypad |
---|
135 | LessThan = OIS::KC_OEM_102, // < > | on UK/Germany keyboards |
---|
136 | F11 = OIS::KC_F11, |
---|
137 | F12 = OIS::KC_F12, |
---|
138 | F13 = OIS::KC_F13, // (NEC PC98) |
---|
139 | F14 = OIS::KC_F14, // (NEC PC98) |
---|
140 | F15 = OIS::KC_F15, // (NEC PC98) |
---|
141 | Kana = OIS::KC_KANA, // (Japanese keyboard) |
---|
142 | ABNT_C1 = OIS::KC_ABNT_C1, // / ? on Portugese (Brazilian) keyboards |
---|
143 | Convert = OIS::KC_CONVERT, // (Japanese keyboard) |
---|
144 | NoConvert = OIS::KC_NOCONVERT, // (Japanese keyboard) |
---|
145 | Yen = OIS::KC_YEN, // (Japanese keyboard) |
---|
146 | ABNT_C2 = OIS::KC_ABNT_C2, // Numpad . on Portugese (Brazilian) keyboards |
---|
147 | NumpadEquals = OIS::KC_NUMPADEQUALS, // = on numeric keypad (NEC PC98) |
---|
148 | PreviousTrack = OIS::KC_PREVTRACK, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard) |
---|
149 | AT = OIS::KC_AT, // (NEC PC98) |
---|
150 | Colon = OIS::KC_COLON, // (NEC PC98) |
---|
151 | Underline = OIS::KC_UNDERLINE, // (NEC PC98) |
---|
152 | Kanji = OIS::KC_KANJI, // (Japanese keyboard) |
---|
153 | Stop = OIS::KC_STOP, // (NEC PC98) |
---|
154 | AX = OIS::KC_AX, // (Japan AX) |
---|
155 | Unlabeled = OIS::KC_UNLABELED, // (J3100) |
---|
156 | NextTrack = OIS::KC_NEXTTRACK, // Next Track |
---|
157 | NumpadEnter = OIS::KC_NUMPADENTER, // Enter on numeric keypad |
---|
158 | RightControl = OIS::KC_RCONTROL, |
---|
159 | Mute = OIS::KC_MUTE, // Mute |
---|
160 | Calculator = OIS::KC_CALCULATOR, // Calculator |
---|
161 | PlayPause = OIS::KC_PLAYPAUSE, // Play / Pause |
---|
162 | MediaStop = OIS::KC_MEDIASTOP, // Media Stop |
---|
163 | VolumeDown = OIS::KC_VOLUMEDOWN, // Volume - |
---|
164 | VolumeUp = OIS::KC_VOLUMEUP, // Volume + |
---|
165 | WebHome = OIS::KC_WEBHOME, // Web home |
---|
166 | NumpadComma = OIS::KC_NUMPADCOMMA, // , on numeric keypad (NEC PC98) |
---|
167 | Divide = OIS::KC_DIVIDE, // / on numeric keypad |
---|
168 | SYSRQ = OIS::KC_SYSRQ, |
---|
169 | RightAlt = OIS::KC_RMENU, // right Alt |
---|
170 | Pause = OIS::KC_PAUSE, // Pause |
---|
171 | Home = OIS::KC_HOME, // Home on arrow keypad |
---|
172 | Up = OIS::KC_UP, // UpArrow on arrow keypad |
---|
173 | PageUp = OIS::KC_PGUP, // PgUp on arrow keypad |
---|
174 | Left = OIS::KC_LEFT, // LeftArrow on arrow keypad |
---|
175 | Right = OIS::KC_RIGHT, // RightArrow on arrow keypad |
---|
176 | End = OIS::KC_END, // End on arrow keypad |
---|
177 | Down = OIS::KC_DOWN, // DownArrow on arrow keypad |
---|
178 | PageDown = OIS::KC_PGDOWN, // PgDn on arrow keypad |
---|
179 | Insert = OIS::KC_INSERT, // Insert on arrow keypad |
---|
180 | Delete = OIS::KC_DELETE, // Delete on arrow keypad |
---|
181 | LeftWindows = OIS::KC_LWIN, // Left Windows key |
---|
182 | RightWindows = OIS::KC_RWIN, // Right Windows key |
---|
183 | Apps = OIS::KC_APPS, // AppMenu key |
---|
184 | Power = OIS::KC_POWER, // System Power |
---|
185 | Sleep = OIS::KC_SLEEP, // System Sleep |
---|
186 | Wake = OIS::KC_WAKE, // System Wake |
---|
187 | WebSearch = OIS::KC_WEBSEARCH, // Web Search |
---|
188 | WebFavorites = OIS::KC_WEBFAVORITES, // Web Favorites |
---|
189 | WebRefresh = OIS::KC_WEBREFRESH, // Web Refresh |
---|
190 | WebStop = OIS::KC_WEBSTOP, // Web Stop |
---|
191 | WebForward = OIS::KC_WEBFORWARD, // Web Forward |
---|
192 | WebBack = OIS::KC_WEBBACK, // Web Back |
---|
193 | MyComputer = OIS::KC_MYCOMPUTER, // My Computer |
---|
194 | Mail = OIS::KC_MAIL, // Mail |
---|
195 | MediaSelect = OIS::KC_MEDIASELECT // Media Select |
---|
196 | }; |
---|
197 | } |
---|
198 | |
---|
199 | namespace MouseButton |
---|
200 | { |
---|
201 | enum Enum |
---|
202 | { |
---|
203 | Left = OIS::MB_Left, |
---|
204 | Right = OIS::MB_Right, |
---|
205 | Middle = OIS::MB_Middle, |
---|
206 | Button3 = OIS::MB_Button3, |
---|
207 | Button4 = OIS::MB_Button4, |
---|
208 | Button5 = OIS::MB_Button5, |
---|
209 | Button6 = OIS::MB_Button6, |
---|
210 | Button7 = OIS::MB_Button7 |
---|
211 | }; |
---|
212 | } |
---|
213 | |
---|
214 | namespace KeyboardModifier |
---|
215 | { |
---|
216 | enum Enum |
---|
217 | { |
---|
218 | Shift = 0x0000001, |
---|
219 | Ctrl = 0x0000010, |
---|
220 | Alt = 0x0000100 |
---|
221 | }; |
---|
222 | } |
---|
223 | |
---|
224 | struct _CoreExport Key |
---|
225 | { |
---|
226 | Key(const OIS::KeyEvent& evt) : key((KeyCode::Enum)evt.key), text(evt.text) { } |
---|
227 | KeyCode::Enum key; |
---|
228 | unsigned int text; |
---|
229 | }; |
---|
230 | |
---|
231 | class _CoreExport KeyEvent |
---|
232 | { |
---|
233 | public: |
---|
234 | KeyEvent(KeyCode::Enum key, unsigned int text) : key(key), text(text) { } |
---|
235 | KeyEvent(const OIS::KeyEvent& evt, unsigned int mod) : key((KeyCode::Enum)evt.key), text(evt.text), modifiers(mod) { } |
---|
236 | KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { } |
---|
237 | bool isModifierDown(KeyboardModifier::Enum modifier) const { return (KeyboardModifier::Enum)modifier&modifiers; } |
---|
238 | |
---|
239 | const KeyCode::Enum key; |
---|
240 | unsigned int text; |
---|
241 | unsigned int modifiers; |
---|
242 | }; |
---|
243 | |
---|
244 | //typedef OIS::MouseState MouseState; |
---|
245 | |
---|
246 | /*class _CoreExport JoyStickState |
---|
247 | { |
---|
248 | public: |
---|
249 | JoyStickState(const OIS::JoyStickState& state, int ID) : OIS::JoyStickState(state), mJoyStickID(ID) { } |
---|
250 | JoyStickState() { clear(); } |
---|
251 | int mJoyStickID; |
---|
252 | JoyStickState() { clear(); } |
---|
253 | |
---|
254 | std::vector<bool> mButtons; |
---|
255 | int axes[16]; |
---|
256 | std::vector<Vector3> mVectors; |
---|
257 | };*/ |
---|
258 | |
---|
259 | /** |
---|
260 | * Helper struct to determine which handlers of an object (can implement |
---|
261 | * multiple handlers) are active. |
---|
262 | */ |
---|
263 | struct HandlerState |
---|
264 | { |
---|
265 | HandlerState() : key(false), mouse(false), joyStick(false) { } |
---|
266 | bool key; |
---|
267 | bool mouse; |
---|
268 | bool joyStick; |
---|
269 | }; |
---|
270 | |
---|
271 | class _CoreExport InputTickable |
---|
272 | { |
---|
273 | public: |
---|
274 | virtual ~InputTickable() { } |
---|
275 | virtual void tickInput(float dt, const HandlerState& state) = 0; |
---|
276 | }; |
---|
277 | |
---|
278 | /** |
---|
279 | @brief Interface class used for key input listeners. |
---|
280 | */ |
---|
281 | class _CoreExport KeyHandler : virtual public InputTickable |
---|
282 | { |
---|
283 | public: |
---|
284 | virtual ~KeyHandler() { } |
---|
285 | virtual void keyPressed (const KeyEvent& evt) = 0; |
---|
286 | virtual void keyReleased(const KeyEvent& evt) = 0; |
---|
287 | virtual void keyHeld (const KeyEvent& evt) = 0; |
---|
288 | //virtual void tickKey (float dt) { } |
---|
289 | }; |
---|
290 | |
---|
291 | /** |
---|
292 | @brief Interface class used for mouse input listeners. |
---|
293 | */ |
---|
294 | class _CoreExport MouseHandler : virtual public InputTickable |
---|
295 | { |
---|
296 | public: |
---|
297 | virtual ~MouseHandler() { } |
---|
298 | virtual void mouseButtonPressed (MouseButton::Enum id) = 0; |
---|
299 | virtual void mouseButtonReleased(MouseButton::Enum id) = 0; |
---|
300 | virtual void mouseButtonHeld (MouseButton::Enum id) = 0; |
---|
301 | virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; |
---|
302 | virtual void mouseScrolled (int abs, int rel) = 0; |
---|
303 | //virtual void tickMouse (float dt) { } |
---|
304 | }; |
---|
305 | |
---|
306 | |
---|
307 | /** |
---|
308 | @brief Interface class used for joy stick input listeners. |
---|
309 | */ |
---|
310 | class _CoreExport JoyStickHandler : virtual public InputTickable |
---|
311 | { |
---|
312 | public: |
---|
313 | virtual ~JoyStickHandler() { } |
---|
314 | virtual void joyStickButtonPressed (int joyStickID, int button) = 0; |
---|
315 | virtual void joyStickButtonReleased(int joyStickID, int button) = 0; |
---|
316 | virtual void joyStickButtonHeld (int joyStickID, int button) = 0; |
---|
317 | virtual void joyStickAxisMoved (int joyStickID, int axis, float value) = 0; |
---|
318 | //virtual bool joyStickVector3Moved (int joyStickID, int index /*, fill list*/) {return true;} |
---|
319 | //virtual void tickJoyStick (float dt) { } |
---|
320 | }; |
---|
321 | |
---|
322 | } |
---|
323 | |
---|
324 | #endif /* _InputInterfaces_H__ */ |
---|