Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/InputInterfaces.h @ 1505

Last change on this file since 1505 was 1505, checked in by rgrieder, 16 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

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