Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/input/InputInterfaces.h @ 1630

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

converted input system to 4 spaces/tab

  • Property svn:eol-style set to native
File size: 13.5 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
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 "src/ois/OISKeyboard.h"
41#include "src/ois/OISMouse.h"
42#include "src/ois/OISJoyStick.h"
43#include "util/Math.h"
44
45namespace 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 KeyboardModifier
216    {
217        enum Enum
218        {
219            Shift = 0x0000001,
220            Ctrl  = 0x0000010,
221            Alt   = 0x0000100
222        };
223    }
224
225    struct _CoreExport Key
226    {
227        Key(const OIS::KeyEvent& evt) : key((KeyCode::Enum)evt.key), text(evt.text) { }
228        KeyCode::Enum key;
229        unsigned int text;
230    };
231
232    class _CoreExport KeyEvent
233    {
234    public:
235        KeyEvent(KeyCode::Enum key, unsigned int text) : key(key), text(text) { }
236        KeyEvent(const OIS::KeyEvent& evt, unsigned int mod)
237            : key((KeyCode::Enum)evt.key), text(evt.text), modifiers(mod) { }
238        KeyEvent(const Key& key, unsigned int mod) : key(key.key), text(key.text), modifiers(mod) { }
239        bool isModifierDown(KeyboardModifier::Enum modifier) const
240            { return (KeyboardModifier::Enum)modifier&modifiers; }
241
242        const KeyCode::Enum key;
243        unsigned int text;
244        unsigned int modifiers;
245    };
246
247    //typedef OIS::MouseState MouseState;
248
249    /*class _CoreExport JoyStickState
250    {
251    public:
252        JoyStickState(const OIS::JoyStickState& state, int ID) : OIS::JoyStickState(state), mJoyStickID(ID) { }
253        JoyStickState() { clear(); }
254        int mJoyStickID;
255        JoyStickState() { clear(); }
256
257        std::vector<bool> mButtons;
258        int axes[16];
259        std::vector<Vector3> mVectors;
260    };*/
261
262    /**
263    @brief
264        Helper struct to determine which handlers of an object (can implement
265        multiple handlers) are active.
266    */
267    struct HandlerState
268    {
269        HandlerState() : key(false), mouse(false), joyStick(false) { }
270        bool key;
271        bool mouse;
272        bool joyStick;
273    };
274
275    class _CoreExport InputTickable
276    {
277    public:
278        virtual ~InputTickable() { }
279        virtual void tickInput(float dt, const HandlerState& state) = 0;
280    };
281
282    /**
283    @brief
284        Interface class used for key input listeners.
285    */
286    class _CoreExport KeyHandler : virtual public InputTickable
287    {
288    public:
289        virtual ~KeyHandler() { }
290        virtual void keyPressed (const KeyEvent& evt) = 0;
291        virtual void keyReleased(const KeyEvent& evt) = 0;
292        virtual void keyHeld    (const KeyEvent& evt) = 0;
293        //virtual void tickKey    (float dt) { }
294    };
295
296    /**
297    @brief
298        Interface class used for mouse input listeners.
299    */
300    class _CoreExport MouseHandler : virtual public InputTickable
301    {
302    public:
303        virtual ~MouseHandler() { }
304        virtual void mouseButtonPressed (MouseButton::Enum id) = 0;
305        virtual void mouseButtonReleased(MouseButton::Enum id) = 0;
306        virtual void mouseButtonHeld    (MouseButton::Enum id) = 0;
307        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
308        virtual void mouseScrolled      (int abs, int rel)     = 0;
309        //virtual void tickMouse          (float dt) { }
310    };
311
312
313    /**
314    @brief
315        Interface class used for joy stick input listeners.
316    */
317    class _CoreExport JoyStickHandler : virtual public InputTickable
318    {
319    public:
320        virtual ~JoyStickHandler() { }
321        virtual void joyStickButtonPressed (int joyStickID, int button) = 0;
322        virtual void joyStickButtonReleased(int joyStickID, int button) = 0;
323        virtual void joyStickButtonHeld    (int joyStickID, int button) = 0;
324        virtual void joyStickAxisMoved     (int joyStickID, int axis, float value) = 0;
325        //virtual bool joyStickVector3Moved  (int joyStickID, int index /*, fill list*/) {return true;}
326        //virtual void tickJoyStick          (float dt) { }
327    };
328
329}
330
331#endif /* _InputInterfaces_H__ */
Note: See TracBrowser for help on using the repository browser.