[918] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[918] | 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 | */ |
---|
[973] | 28 | |
---|
[918] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Implementation of a little Input handler that distributes everything |
---|
| 32 | coming from OIS. |
---|
| 33 | */ |
---|
[973] | 34 | |
---|
| 35 | #ifndef _InputManager_H__ |
---|
| 36 | #define _InputManager_H__ |
---|
| 37 | |
---|
[1062] | 38 | #include "CorePrereqs.h" |
---|
| 39 | |
---|
[1182] | 40 | #include <map> |
---|
| 41 | #include <list> |
---|
[973] | 42 | |
---|
[1195] | 43 | #include "ois/OIS.h" |
---|
[1062] | 44 | #include "Tickable.h" |
---|
[1203] | 45 | //#include "InputEvent.h" |
---|
| 46 | #include "InputHandler.h" |
---|
[973] | 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
[1203] | 50 | class Mouse : public OIS::Mouse |
---|
| 51 | { |
---|
| 52 | }; |
---|
| 53 | |
---|
[973] | 54 | /** |
---|
| 55 | @brief Captures and distributes mouse and keyboard input. |
---|
| 56 | It resolves the key bindings to InputEvents which can be heard by |
---|
| 57 | implementing the InputEventListener interface. |
---|
| 58 | */ |
---|
| 59 | class _CoreExport InputManager |
---|
[1182] | 60 | : public Tickable, |
---|
| 61 | public OIS::MouseListener, public OIS::KeyListener, public OIS::JoyStickListener |
---|
[973] | 62 | { |
---|
[1193] | 63 | public: // enumerations |
---|
[1182] | 64 | /** |
---|
[1193] | 65 | @brief Designates the way input is handled and redirected. |
---|
[1182] | 66 | */ |
---|
| 67 | enum InputState |
---|
| 68 | { |
---|
[1193] | 69 | IS_UNINIT, //!< InputManager has not yet been initialised. |
---|
| 70 | IS_NONE, //!< Input is discarded. |
---|
| 71 | IS_NORMAL, //!< Normal play state. Key and button bindings are active. |
---|
| 72 | IS_GUI, //!< All OIS input events are passed to CEGUI. |
---|
| 73 | IS_CONSOLE, //!< Keyboard input is redirected to the InputBuffer. |
---|
| 74 | IS_CUSTOM //!< Any possible configuration. |
---|
[1182] | 75 | }; |
---|
| 76 | |
---|
[1203] | 77 | public: // static functions |
---|
[1193] | 78 | static bool initialise(size_t windowHnd, int windowWidth, int windowHeight, |
---|
| 79 | bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false); |
---|
[1203] | 80 | static bool initialiseKeyboard(); |
---|
| 81 | static bool initialiseMouse(); |
---|
| 82 | static bool initialiseJoySticks(); |
---|
| 83 | |
---|
[1182] | 84 | static void destroy(); |
---|
[1203] | 85 | static void destroyKeyboard(); |
---|
| 86 | static void destroyMouse(); |
---|
| 87 | static void destroyJoySticks(); |
---|
[1066] | 88 | |
---|
[1182] | 89 | static void setWindowExtents(int width, int height); |
---|
[1193] | 90 | |
---|
[1182] | 91 | static void setInputState(const InputState state); |
---|
| 92 | static InputState getInputState(); |
---|
[1193] | 93 | static void setKeyBindingState (bool bActive); |
---|
| 94 | static void setMouseButtonBindingState (bool bActive); |
---|
| 95 | static void setJoyStickButtonBindingState(bool bActive); |
---|
[1182] | 96 | |
---|
[1203] | 97 | static bool addKeyListener(KeyHandler* listener, const std::string& name); |
---|
[1193] | 98 | static bool removeKeyListener (const std::string& name); |
---|
| 99 | static bool enableKeyListener (const std::string& name); |
---|
| 100 | static bool disableKeyListener (const std::string& name); |
---|
| 101 | static bool isKeyListenerActive(const std::string& name); |
---|
[1203] | 102 | static KeyHandler* getKeyListener(const std::string& name); |
---|
[1182] | 103 | |
---|
[1203] | 104 | static bool addMouseListener(MouseHandler* listener, const std::string& name); |
---|
[1193] | 105 | static bool removeMouseListener (const std::string& name); |
---|
| 106 | static bool enableMouseListener (const std::string& name); |
---|
| 107 | static bool disableMouseListener (const std::string& name); |
---|
| 108 | static bool isMouseListenerActive(const std::string& name); |
---|
[1203] | 109 | static MouseHandler* getMouseListener(const std::string& name); |
---|
[1182] | 110 | |
---|
[1203] | 111 | static bool addJoyStickListener(JoyStickHandler* listener, const std::string& name); |
---|
[1193] | 112 | static bool removeJoyStickListener (const std::string& name); |
---|
[1203] | 113 | static bool enableJoyStickListener (const std::string& name, const int id); |
---|
| 114 | static bool disableJoyStickListener (const std::string& name, const int id); |
---|
[1193] | 115 | static bool isJoyStickListenerActive(const std::string& name); |
---|
[1203] | 116 | static JoyStickHandler* getJoyStickListener(const std::string& name); |
---|
[1182] | 117 | |
---|
[973] | 118 | // Temporary solutions. Will be removed soon! |
---|
[1182] | 119 | static OIS::Mouse* getMouse() { return _getSingleton().mouse_ ; } |
---|
| 120 | static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; } |
---|
[973] | 121 | |
---|
[1193] | 122 | private: // functions |
---|
[973] | 123 | // don't mess with a Singleton |
---|
| 124 | InputManager (); |
---|
| 125 | InputManager (const InputManager&); |
---|
| 126 | ~InputManager(); |
---|
| 127 | |
---|
[1193] | 128 | // Intenal methods |
---|
| 129 | bool _initialise(size_t, int, int, bool, bool, bool); |
---|
[1203] | 130 | bool _initialiseKeyboard(); |
---|
| 131 | bool _initialiseMouse(); |
---|
| 132 | bool _initialiseJoySticks(); |
---|
| 133 | |
---|
[1182] | 134 | void _destroy(); |
---|
[1203] | 135 | void _destroyKeyboard(); |
---|
| 136 | void _destroyMouse(); |
---|
| 137 | void _destroyJoySticks(); |
---|
[973] | 138 | |
---|
[1203] | 139 | //void _setNumberOfJoysticks(int size); |
---|
| 140 | |
---|
[1193] | 141 | void tick(float dt); |
---|
| 142 | |
---|
[1182] | 143 | // input events |
---|
| 144 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 145 | bool mouseReleased (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 146 | bool mouseMoved (const OIS::MouseEvent &arg); |
---|
| 147 | bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 148 | bool keyReleased (const OIS::KeyEvent &arg); |
---|
| 149 | bool buttonPressed (const OIS::JoyStickEvent &arg, int button); |
---|
| 150 | bool buttonReleased(const OIS::JoyStickEvent &arg, int button); |
---|
| 151 | bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
| 152 | bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
| 153 | bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
[973] | 154 | |
---|
[1182] | 155 | static InputManager& _getSingleton(); |
---|
| 156 | static InputManager* _getSingletonPtr() { return &_getSingleton(); } |
---|
| 157 | |
---|
[1193] | 158 | private: // variables |
---|
[1203] | 159 | OIS::InputManager* inputSystem_; //!< OIS input manager |
---|
| 160 | OIS::Keyboard* keyboard_; //!< OIS mouse |
---|
| 161 | OIS::Mouse* mouse_; //!< OIS keyboard |
---|
| 162 | std::map<int, OIS::JoyStick*> joySticks_; //!< OIS joy sticks |
---|
[1182] | 163 | |
---|
| 164 | InputState state_; |
---|
| 165 | InputState stateRequest_; |
---|
| 166 | |
---|
[1203] | 167 | std::map<std::string, KeyHandler*> listenersKey_; |
---|
| 168 | std::map<std::string, MouseHandler*> listenersMouse_; |
---|
| 169 | std::map<std::string, JoyStickHandler*> listenersJoySticks_; |
---|
[1182] | 170 | |
---|
[1203] | 171 | std::list<KeyHandler*> listenersKeyActive_; |
---|
| 172 | std::list<MouseHandler*> listenersMouseActive_; |
---|
| 173 | std::map< int, std::list<JoyStickHandler*> > listenersJoySticksActive_; |
---|
[1182] | 174 | |
---|
[1193] | 175 | std::list<OIS::KeyCode> keysDown_; |
---|
| 176 | std::list<OIS::MouseButtonID> mouseButtonsDown_; |
---|
[1203] | 177 | std::map< int, std::list<int> > joySticksButtonsDown_; |
---|
[1182] | 178 | |
---|
[973] | 179 | }; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | #endif /* _InputManager_H__ */ |
---|