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 | */ |
---|
33 | |
---|
34 | #ifndef _InputState_H__ |
---|
35 | #define _InputState_H__ |
---|
36 | |
---|
37 | #include "core/CorePrereqs.h" |
---|
38 | |
---|
39 | #include <string> |
---|
40 | #include <vector> |
---|
41 | #include "InputInterfaces.h" |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | class _CoreExport InputState |
---|
46 | { |
---|
47 | friend class InputManager; |
---|
48 | |
---|
49 | public: |
---|
50 | const std::string& getName() const { return name_; } |
---|
51 | int getPriority() const { return priority_; } |
---|
52 | |
---|
53 | bool isInputDeviceEnabled(unsigned int device) |
---|
54 | { |
---|
55 | if (device < bInputDeviceEnabled_.size()) |
---|
56 | return bInputDeviceEnabled_[device]; |
---|
57 | else |
---|
58 | return false; |
---|
59 | } |
---|
60 | |
---|
61 | bool handlersChanged() { return this->bHandlersChanged_; } |
---|
62 | void resetHandlersChanged() { bHandlersChanged_ = false; } |
---|
63 | |
---|
64 | virtual void onEnter() = 0; |
---|
65 | virtual void onLeave() = 0; |
---|
66 | |
---|
67 | virtual void registerOnEnter(Executor* executor) { executorOnEnter_ = executor; } |
---|
68 | virtual void unRegisterOnEnter() { executorOnEnter_ = 0; } |
---|
69 | virtual void registerOnLeave(Executor* executor) { executorOnLeave_ = executor; } |
---|
70 | virtual void unRegisterOnLeave() { executorOnLeave_ = 0; } |
---|
71 | |
---|
72 | virtual void updateInput(float dt, unsigned int device) = 0; |
---|
73 | virtual void updateInput(float dt) = 0; |
---|
74 | |
---|
75 | virtual void keyPressed (const KeyEvent& evt) = 0; |
---|
76 | virtual void keyReleased(const KeyEvent& evt) = 0; |
---|
77 | virtual void keyHeld (const KeyEvent& evt) = 0; |
---|
78 | |
---|
79 | virtual void mouseButtonPressed (MouseButtonCode::ByEnum id) = 0; |
---|
80 | virtual void mouseButtonReleased(MouseButtonCode::ByEnum id) = 0; |
---|
81 | virtual void mouseButtonHeld (MouseButtonCode::ByEnum id) = 0; |
---|
82 | virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0; |
---|
83 | virtual void mouseScrolled (int abs, int rel) = 0; |
---|
84 | |
---|
85 | virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; |
---|
86 | virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; |
---|
87 | virtual void joyStickButtonHeld (unsigned int joyStickID, JoyStickButtonCode::ByEnum id) = 0; |
---|
88 | virtual void joyStickAxisMoved (unsigned int joyStickID, unsigned int axis, float value) = 0; |
---|
89 | |
---|
90 | protected: |
---|
91 | InputState() |
---|
92 | : bHandlersChanged_(false) |
---|
93 | , executorOnEnter_(0) |
---|
94 | , executorOnLeave_(0) |
---|
95 | , priority_(0) |
---|
96 | , bAlwaysGetsInput_(false) |
---|
97 | , bTransparent_(false) |
---|
98 | { } |
---|
99 | virtual ~InputState() { } |
---|
100 | |
---|
101 | virtual void numberOfJoySticksChanged(unsigned int n) = 0; |
---|
102 | void setInputDeviceEnabled(unsigned int device, bool bEnabled) |
---|
103 | { |
---|
104 | if (device < bInputDeviceEnabled_.size()) |
---|
105 | bInputDeviceEnabled_[device] = bEnabled; |
---|
106 | } |
---|
107 | |
---|
108 | bool bHandlersChanged_; |
---|
109 | Executor* executorOnEnter_; |
---|
110 | Executor* executorOnLeave_; |
---|
111 | |
---|
112 | private: |
---|
113 | void setNumOfJoySticks(unsigned int n) |
---|
114 | { |
---|
115 | bInputDeviceEnabled_.resize(n + 2); |
---|
116 | numberOfJoySticksChanged(n); |
---|
117 | } |
---|
118 | void setName(const std::string& name) { name_ = name; } |
---|
119 | void setPriority(int priority) { priority_ = priority; } |
---|
120 | |
---|
121 | std::string name_; |
---|
122 | int priority_; |
---|
123 | std::vector<bool> bInputDeviceEnabled_; |
---|
124 | bool bAlwaysGetsInput_; |
---|
125 | bool bTransparent_; |
---|
126 | }; |
---|
127 | } |
---|
128 | |
---|
129 | #endif /* _InputState_H__ */ |
---|