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 | |
---|
42 | namespace orxonox |
---|
43 | { |
---|
44 | namespace KeybindSetting |
---|
45 | { |
---|
46 | enum KeybindSetting |
---|
47 | { |
---|
48 | None, |
---|
49 | OnPress, |
---|
50 | OnRelease, |
---|
51 | Continuous, |
---|
52 | }; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | @brief Interface class used for key input listeners. |
---|
57 | */ |
---|
58 | class _CoreExport KeyHandler : public OIS::KeyListener |
---|
59 | { |
---|
60 | public: |
---|
61 | virtual bool keyHeld(const OIS::KeyEvent &arg) = 0; |
---|
62 | }; |
---|
63 | |
---|
64 | /** |
---|
65 | @brief Interface class used for mouse input listeners. |
---|
66 | */ |
---|
67 | class _CoreExport MouseHandler : public OIS::MouseListener |
---|
68 | { |
---|
69 | public: |
---|
70 | virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0; |
---|
71 | }; |
---|
72 | |
---|
73 | /** |
---|
74 | @brief Interface class used for joy stick input listeners. |
---|
75 | */ |
---|
76 | class _CoreExport JoyStickHandler : public OIS::JoyStickListener |
---|
77 | { |
---|
78 | public: |
---|
79 | virtual bool buttonHeld(const OIS::JoyStickEvent &arg, int button) = 0; |
---|
80 | }; |
---|
81 | |
---|
82 | |
---|
83 | /** |
---|
84 | @brief Captures mouse, keyboard and joy stick input while in the actual game mode. |
---|
85 | Manages the key bindings. |
---|
86 | */ |
---|
87 | class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler |
---|
88 | { |
---|
89 | public: |
---|
90 | KeyBinder (); |
---|
91 | ~KeyBinder(); |
---|
92 | |
---|
93 | bool loadBindings(); |
---|
94 | void clearBindings(); |
---|
95 | |
---|
96 | private: // functions |
---|
97 | bool keyPressed (const OIS::KeyEvent &arg); |
---|
98 | bool keyReleased (const OIS::KeyEvent &arg); |
---|
99 | bool keyHeld (const OIS::KeyEvent &arg); |
---|
100 | |
---|
101 | bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
102 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
103 | bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
104 | bool mouseMoved (const OIS::MouseEvent &arg); |
---|
105 | |
---|
106 | bool buttonPressed (const OIS::JoyStickEvent &arg, int button); |
---|
107 | bool buttonReleased(const OIS::JoyStickEvent &arg, int button); |
---|
108 | bool buttonHeld (const OIS::JoyStickEvent &arg, int button); |
---|
109 | bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
110 | bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
111 | bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
112 | |
---|
113 | private: // variables |
---|
114 | /** denotes the maximum number of different keys there are in OIS. |
---|
115 | 256 should be ok since the highest number in the OIS enum is 237. */ |
---|
116 | static const int numberOfKeys_s = 256; |
---|
117 | //! Array of input events for every pressed key |
---|
118 | std::string bindingsKeyPress_ [numberOfKeys_s]; |
---|
119 | //! Array of input events for every released key |
---|
120 | std::string bindingsKeyRelease_[numberOfKeys_s]; |
---|
121 | //!Array of input events for every held key |
---|
122 | std::string bindingsKeyHold_ [numberOfKeys_s]; |
---|
123 | |
---|
124 | /** denotes the maximum number of different buttons there are in OIS. |
---|
125 | 16 should be ok since the highest number in the OIS enum is 7. */ |
---|
126 | static const int numberOfMouseButtons_s = 16; |
---|
127 | //! Array of input events for every pressed mouse button |
---|
128 | std::string bindingsMouseButtonPress_ [numberOfMouseButtons_s]; |
---|
129 | //! Array of input events for every released mouse button |
---|
130 | std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s]; |
---|
131 | //! Array of input events for every held mouse button |
---|
132 | std::string bindingsMouseButtonHold_ [numberOfMouseButtons_s]; |
---|
133 | |
---|
134 | /** denotes the maximum number of different buttons there are in OIS. |
---|
135 | 32 should be ok. */ |
---|
136 | static const int numberOfJoyStickButtons_s = 32; |
---|
137 | //! Array of input events for every pressed joy stick button |
---|
138 | std::string bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; |
---|
139 | //! Array of input events for every released joy stick button |
---|
140 | std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; |
---|
141 | //! Array of input events for every held joy stick button |
---|
142 | std::string bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; |
---|
143 | |
---|
144 | }; |
---|
145 | |
---|
146 | |
---|
147 | /** |
---|
148 | @brief Captures mouse and keyboard input and distributes it to the |
---|
149 | GUI. |
---|
150 | */ |
---|
151 | //class _CoreExport GUIInputHandler : public KeyHandler, public MouseHandler, public JoyStickHandler |
---|
152 | //{ |
---|
153 | //public: |
---|
154 | // GUIInputHandler (); |
---|
155 | // ~GUIInputHandler(); |
---|
156 | |
---|
157 | //private: |
---|
158 | // // input events |
---|
159 | //bool keyPressed (const OIS::KeyEvent &arg); |
---|
160 | //bool keyReleased (const OIS::KeyEvent &arg); |
---|
161 | //bool keyHeld (const OIS::KeyEvent &arg); |
---|
162 | |
---|
163 | // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
164 | //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
165 | //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonID id); |
---|
166 | // bool mouseMoved (const OIS::MouseEvent &arg); |
---|
167 | |
---|
168 | //bool buttonPressed (const OIS::JoyStickEvent &arg, int button); |
---|
169 | //bool buttonReleased(const OIS::JoyStickEvent &arg, int button); |
---|
170 | //bool buttonHeld (const OIS::JoyStickEvent &arg, int button); |
---|
171 | //bool axisMoved (const OIS::JoyStickEvent &arg, int axis); |
---|
172 | //bool sliderMoved (const OIS::JoyStickEvent &arg, int id); |
---|
173 | //bool povMoved (const OIS::JoyStickEvent &arg, int id); |
---|
174 | //}; |
---|
175 | |
---|
176 | } |
---|
177 | |
---|
178 | #endif /* _InputHandler_H__ */ |
---|