| 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 Different definitions of input processing. | 
|---|
| 32 | */ | 
|---|
| 33 |  | 
|---|
| 34 | #ifndef _InputHandler_H__ | 
|---|
| 35 | #define _InputHandler_H__ | 
|---|
| 36 |  | 
|---|
| 37 | #include "CorePrereqs.h" | 
|---|
| 38 |  | 
|---|
| 39 | #include <string> | 
|---|
| 40 | #include "ois/OIS.h" | 
|---|
| 41 | #include "OrxonoxClass.h" | 
|---|
| 42 | #include "CommandExecutor.h" | 
|---|
| 43 |  | 
|---|
| 44 | namespace orxonox | 
|---|
| 45 | { | 
|---|
| 46 | namespace KeybindSetting | 
|---|
| 47 | { | 
|---|
| 48 | enum KeybindSetting | 
|---|
| 49 | { | 
|---|
| 50 | None, | 
|---|
| 51 | OnPress, | 
|---|
| 52 | OnRelease, | 
|---|
| 53 | Continuous, | 
|---|
| 54 | }; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | /** | 
|---|
| 58 | @brief Interface class used for key input listeners. | 
|---|
| 59 | */ | 
|---|
| 60 | class _CoreExport KeyHandler : public OIS::KeyListener | 
|---|
| 61 | { | 
|---|
| 62 | public: | 
|---|
| 63 | virtual ~KeyHandler() { } | 
|---|
| 64 | virtual bool keyHeld(const OIS::KeyEvent &arg) = 0; | 
|---|
| 65 | }; | 
|---|
| 66 |  | 
|---|
| 67 | /** | 
|---|
| 68 | @brief Interface class used for mouse input listeners. | 
|---|
| 69 | */ | 
|---|
| 70 | class _CoreExport MouseHandler : public OIS::MouseListener | 
|---|
| 71 | { | 
|---|
| 72 | public: | 
|---|
| 73 | virtual ~MouseHandler() { } | 
|---|
| 74 | virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0; | 
|---|
| 75 | }; | 
|---|
| 76 |  | 
|---|
| 77 | /** | 
|---|
| 78 | @brief Interface class used for joy stick input listeners. | 
|---|
| 79 | */ | 
|---|
| 80 | class _CoreExport JoyStickHandler | 
|---|
| 81 | { | 
|---|
| 82 | public: | 
|---|
| 83 | virtual ~JoyStickHandler() { } | 
|---|
| 84 | virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; | 
|---|
| 85 | virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; | 
|---|
| 86 | virtual bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0; | 
|---|
| 87 | virtual bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis)   = 0; | 
|---|
| 88 | virtual bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} | 
|---|
| 89 | virtual bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} | 
|---|
| 90 | virtual bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;} | 
|---|
| 91 | }; | 
|---|
| 92 |  | 
|---|
| 93 | struct _CoreExport KeyBinding | 
|---|
| 94 | { | 
|---|
| 95 | std::string commandStr; | 
|---|
| 96 | CommandEvaluation evaluation; | 
|---|
| 97 | }; | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 | /** | 
|---|
| 101 | @brief Captures mouse, keyboard and joy stick input while in the actual game mode. | 
|---|
| 102 | Manages the key bindings. | 
|---|
| 103 | */ | 
|---|
| 104 | class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass | 
|---|
| 105 | { | 
|---|
| 106 | public: | 
|---|
| 107 | KeyBinder (); | 
|---|
| 108 | ~KeyBinder(); | 
|---|
| 109 |  | 
|---|
| 110 | bool loadBindings(); | 
|---|
| 111 | void clearBindings(); | 
|---|
| 112 |  | 
|---|
| 113 | void setConfigValues(); | 
|---|
| 114 |  | 
|---|
| 115 | std::string testtest; | 
|---|
| 116 |  | 
|---|
| 117 | private: // functions | 
|---|
| 118 |  | 
|---|
| 119 | bool executeBinding(KeyBinding &binding); | 
|---|
| 120 |  | 
|---|
| 121 | bool keyPressed   (const OIS::KeyEvent   &arg); | 
|---|
| 122 | bool keyReleased  (const OIS::KeyEvent   &arg); | 
|---|
| 123 | bool keyHeld      (const OIS::KeyEvent   &arg); | 
|---|
| 124 |  | 
|---|
| 125 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); | 
|---|
| 126 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); | 
|---|
| 127 | bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id); | 
|---|
| 128 | bool mouseMoved   (const OIS::MouseEvent &arg); | 
|---|
| 129 |  | 
|---|
| 130 | bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button); | 
|---|
| 131 | bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button); | 
|---|
| 132 | bool buttonHeld    (int joyStickID, const OIS::JoyStickEvent &arg, int button); | 
|---|
| 133 | bool axisMoved     (int joyStickID, const OIS::JoyStickEvent &arg, int axis); | 
|---|
| 134 | bool sliderMoved   (int joyStickID, const OIS::JoyStickEvent &arg, int id); | 
|---|
| 135 | bool povMoved      (int joyStickID, const OIS::JoyStickEvent &arg, int id); | 
|---|
| 136 | bool vector3Moved  (int joyStickID, const OIS::JoyStickEvent &arg, int id); | 
|---|
| 137 |  | 
|---|
| 138 | private: // variables | 
|---|
| 139 |  | 
|---|
| 140 | //! denotes the number of different keys there are in OIS. | 
|---|
| 141 | static const int numberOfKeys_s = 0xEE; | 
|---|
| 142 | //! Array of input events for every pressed key | 
|---|
| 143 | KeyBinding bindingsKeyPress_  [numberOfKeys_s]; | 
|---|
| 144 | //! Array of input events for every released key | 
|---|
| 145 | KeyBinding bindingsKeyRelease_[numberOfKeys_s]; | 
|---|
| 146 | //! Array of input events for every held key | 
|---|
| 147 | KeyBinding bindingsKeyHold_   [numberOfKeys_s]; | 
|---|
| 148 | //! Names of the keys as strings | 
|---|
| 149 | std::string keyNames_[numberOfKeys_s]; | 
|---|
| 150 |  | 
|---|
| 151 | //! denotes the number of different mouse buttons there are in OIS. | 
|---|
| 152 | static const int numberOfMouseButtons_s = 8; | 
|---|
| 153 | //! Array of input events for every pressed mouse button | 
|---|
| 154 | std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s]; | 
|---|
| 155 | //! Array of input events for every released mouse button | 
|---|
| 156 | std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s]; | 
|---|
| 157 | //! Array of input events for every held mouse button | 
|---|
| 158 | std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s]; | 
|---|
| 159 | //! Names of the mouse buttons as strings | 
|---|
| 160 | std::string mouseButtonNames_[numberOfMouseButtons_s]; | 
|---|
| 161 |  | 
|---|
| 162 | //! denotes the number of different joy stick buttons there are in OIS. | 
|---|
| 163 | static const int numberOfJoyStickButtons_s = 32; | 
|---|
| 164 | //! Array of input events for every pressed joy stick button | 
|---|
| 165 | std::string bindingsJoyStickButtonPress_  [numberOfJoyStickButtons_s]; | 
|---|
| 166 | //! Array of input events for every released joy stick button | 
|---|
| 167 | std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; | 
|---|
| 168 | //! Array of input events for every held joy stick button | 
|---|
| 169 | std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s]; | 
|---|
| 170 | //! Names of the joy stick buttons as strings | 
|---|
| 171 | std::string joyStickButtonNames_[numberOfJoyStickButtons_s]; | 
|---|
| 172 |  | 
|---|
| 173 | }; | 
|---|
| 174 |  | 
|---|
| 175 |  | 
|---|
| 176 | /** | 
|---|
| 177 | @brief Captures mouse and keyboard input and distributes it to the | 
|---|
| 178 | GUI. | 
|---|
| 179 | */ | 
|---|
| 180 | //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler | 
|---|
| 181 | //{ | 
|---|
| 182 | //public: | 
|---|
| 183 | //  GUIInputHandler (); | 
|---|
| 184 | //  ~GUIInputHandler(); | 
|---|
| 185 |  | 
|---|
| 186 | //private: | 
|---|
| 187 | //  // input events | 
|---|
| 188 | //bool keyPressed   (const OIS::KeyEvent   &arg); | 
|---|
| 189 | //bool keyReleased  (const OIS::KeyEvent   &arg); | 
|---|
| 190 | //bool keyHeld      (const OIS::KeyEvent   &arg); | 
|---|
| 191 |  | 
|---|
| 192 | //  bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); | 
|---|
| 193 | //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); | 
|---|
| 194 | //bool mouseHeld    (const OIS::MouseEvent &arg, OIS::MouseButtonID id); | 
|---|
| 195 | //  bool mouseMoved   (const OIS::MouseEvent &arg); | 
|---|
| 196 |  | 
|---|
| 197 | //bool buttonPressed (const OIS::JoyStickEvent &arg, int button); | 
|---|
| 198 | //bool buttonReleased(const OIS::JoyStickEvent &arg, int button); | 
|---|
| 199 | //bool buttonHeld    (const OIS::JoyStickEvent &arg, int button); | 
|---|
| 200 | //bool axisMoved     (const OIS::JoyStickEvent &arg, int axis); | 
|---|
| 201 | //bool sliderMoved   (const OIS::JoyStickEvent &arg, int id); | 
|---|
| 202 | //bool povMoved      (const OIS::JoyStickEvent &arg, int id); | 
|---|
| 203 | //}; | 
|---|
| 204 |  | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | #endif /* _InputHandler_H__ */ | 
|---|