[971] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[971] | 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 | |
---|
[971] | 29 | /** |
---|
| 30 | @file |
---|
[1022] | 31 | @brief Different definitions of input processing. |
---|
[971] | 32 | */ |
---|
[973] | 33 | |
---|
| 34 | #ifndef _InputHandler_H__ |
---|
| 35 | #define _InputHandler_H__ |
---|
| 36 | |
---|
[1062] | 37 | #include "CorePrereqs.h" |
---|
| 38 | |
---|
[1022] | 39 | #include <string> |
---|
[1118] | 40 | #include <list> |
---|
[973] | 41 | #include <OIS/OIS.h> |
---|
| 42 | |
---|
[1022] | 43 | #include "InputEvent.h" |
---|
[973] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
[1112] | 47 | namespace KeybindSetting |
---|
| 48 | { |
---|
| 49 | enum KeybindSetting |
---|
| 50 | { |
---|
[1118] | 51 | None, |
---|
| 52 | OnPress, |
---|
| 53 | OnRelease, |
---|
| 54 | Continuous, |
---|
[1112] | 55 | }; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | class _CoreExport BaseInputHandler |
---|
| 59 | : public OIS::KeyListener, public OIS::MouseListener |
---|
| 60 | { |
---|
[1118] | 61 | virtual void tick(float dt) = 0; |
---|
[1112] | 62 | }; |
---|
| 63 | |
---|
[973] | 64 | /** |
---|
[1022] | 65 | @brief Captures mouse and keyboard input while in the actual game mode. |
---|
| 66 | Manages the key bindings. |
---|
[973] | 67 | */ |
---|
[1112] | 68 | class _CoreExport InputHandlerGame : public BaseInputHandler |
---|
[973] | 69 | { |
---|
| 70 | public: |
---|
[1022] | 71 | InputHandlerGame (); |
---|
| 72 | ~InputHandlerGame(); |
---|
[973] | 73 | |
---|
[1022] | 74 | bool loadBindings(); |
---|
| 75 | |
---|
[973] | 76 | private: |
---|
| 77 | // input events |
---|
| 78 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 79 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 80 | bool mouseMoved (const OIS::MouseEvent &arg); |
---|
| 81 | bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 82 | bool keyReleased (const OIS::KeyEvent &arg); |
---|
[1022] | 83 | |
---|
[1118] | 84 | void tick(float dt); |
---|
| 85 | |
---|
[1022] | 86 | // temporary hack |
---|
| 87 | void callListeners(InputEvent &evt); |
---|
| 88 | |
---|
[1118] | 89 | //! Stores all the keys that are down |
---|
| 90 | std::list<OIS::KeyCode> keysDown_; |
---|
| 91 | |
---|
[1022] | 92 | /** denotes the maximum number of different keys there are in OIS. |
---|
| 93 | 256 should be ok since the highest number in the enum is 237. */ |
---|
| 94 | static const int numberOfKeys_s = 256; |
---|
| 95 | //! Array of input events for every pressed key |
---|
[1112] | 96 | std::string bindingsKeyPress_[numberOfKeys_s]; |
---|
[1022] | 97 | //! Array of input events for every released key |
---|
[1112] | 98 | std::string bindingsKeyRelease_[numberOfKeys_s]; |
---|
| 99 | //! Array of input events for every holding key |
---|
| 100 | std::string bindingsKeyHold_[numberOfKeys_s]; |
---|
[1022] | 101 | |
---|
| 102 | /** denotes the maximum number of different buttons there are in OIS. |
---|
| 103 | 16 should be ok since the highest number in the enum is 7. */ |
---|
| 104 | static const int numberOfButtons_s = 16; |
---|
| 105 | //! Array of input events for every pressed key |
---|
| 106 | std::string bindingsButtonPressed_[numberOfButtons_s]; |
---|
| 107 | //! Array of input events for every released key |
---|
| 108 | std::string bindingsButtonReleased_[numberOfButtons_s]; |
---|
| 109 | |
---|
[973] | 110 | }; |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | /** |
---|
[1022] | 114 | @brief Captures mouse and keyboard input and distributes it to the |
---|
| 115 | GUI. |
---|
[973] | 116 | */ |
---|
[1112] | 117 | class _CoreExport InputHandlerGUI : public BaseInputHandler |
---|
[973] | 118 | { |
---|
| 119 | public: |
---|
[1022] | 120 | InputHandlerGUI (); |
---|
| 121 | ~InputHandlerGUI(); |
---|
[973] | 122 | |
---|
[1118] | 123 | void tick(float dt); |
---|
| 124 | |
---|
[973] | 125 | private: |
---|
| 126 | // input events |
---|
| 127 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 128 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
| 129 | bool mouseMoved (const OIS::MouseEvent &arg); |
---|
| 130 | bool keyPressed (const OIS::KeyEvent &arg); |
---|
| 131 | bool keyReleased (const OIS::KeyEvent &arg); |
---|
| 132 | }; |
---|
| 133 | |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | #endif /* _InputHandler_H__ */ |
---|