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 | Declarations of various interface classes for the input management. |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _InputHandler_H__ |
---|
36 | #define _InputHandler_H__ |
---|
37 | |
---|
38 | #include "InputPrereqs.h" |
---|
39 | #include "util/Math.h" |
---|
40 | |
---|
41 | namespace orxonox |
---|
42 | { |
---|
43 | namespace ButtonEvent |
---|
44 | { |
---|
45 | //! Helper enum to deploy events with the help of templates |
---|
46 | enum Value |
---|
47 | { |
---|
48 | Press, |
---|
49 | Release, |
---|
50 | Hold |
---|
51 | }; |
---|
52 | |
---|
53 | //! Enables function overloading with integer values |
---|
54 | template <ButtonEvent::Value Event> |
---|
55 | struct EnumToType { }; |
---|
56 | typedef EnumToType<Press> TPress; |
---|
57 | typedef EnumToType<Release> TRelease; |
---|
58 | typedef EnumToType<Hold> THold; |
---|
59 | } |
---|
60 | |
---|
61 | namespace KeyboardModifier |
---|
62 | { |
---|
63 | //! Keyboard modifiers (shift, ctrl and alt) |
---|
64 | enum Enum |
---|
65 | { |
---|
66 | Shift = 0x0000001, |
---|
67 | Ctrl = 0x0000010, |
---|
68 | Alt = 0x0000100 |
---|
69 | }; |
---|
70 | } |
---|
71 | |
---|
72 | //! Event argument for key events |
---|
73 | class _CoreExport KeyEvent |
---|
74 | { |
---|
75 | public: |
---|
76 | KeyEvent(const OIS::KeyEvent& evt) |
---|
77 | : key_(static_cast<KeyCode::ByEnum>(evt.key)) |
---|
78 | , text_(evt.text) |
---|
79 | , modifiers_(0) |
---|
80 | { } |
---|
81 | bool operator==(const KeyEvent& rhs) const |
---|
82 | { return rhs.key_ == key_; } |
---|
83 | bool operator!=(const KeyEvent& rhs) const |
---|
84 | { return rhs.key_ != key_; } |
---|
85 | void setModifiers(int modifiers) |
---|
86 | { modifiers_ = modifiers; } |
---|
87 | |
---|
88 | bool isModifierDown(KeyboardModifier::Enum modifier) const |
---|
89 | { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); } |
---|
90 | KeyCode::ByEnum getKeyCode() const |
---|
91 | { return key_; } |
---|
92 | unsigned int getText() const { return text_; } |
---|
93 | |
---|
94 | private: |
---|
95 | KeyCode::ByEnum key_; |
---|
96 | unsigned int text_; |
---|
97 | int modifiers_; |
---|
98 | }; |
---|
99 | |
---|
100 | /** |
---|
101 | @brief |
---|
102 | */ |
---|
103 | class _CoreExport InputHandler |
---|
104 | { |
---|
105 | public: |
---|
106 | virtual ~InputHandler() { } |
---|
107 | |
---|
108 | template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::TPress) |
---|
109 | { this->buttonPressed(button); } |
---|
110 | template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::TRelease) |
---|
111 | { this->buttonReleased(button); } |
---|
112 | template<class T> void buttonEvent(unsigned int device, const T& button, ButtonEvent::THold) |
---|
113 | { this->buttonHeld(button); } |
---|
114 | void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::TPress) |
---|
115 | { this->buttonPressed(device - InputDeviceEnumerator::FirstJoyStick, button); } |
---|
116 | void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::TRelease) |
---|
117 | { this->buttonReleased(device - InputDeviceEnumerator::FirstJoyStick, button); } |
---|
118 | void buttonEvent(unsigned int device, JoyStickButtonCode::ByEnum button, ButtonEvent::THold) |
---|
119 | { this->buttonHeld(device - InputDeviceEnumerator::FirstJoyStick, button); } |
---|
120 | |
---|
121 | virtual void buttonPressed (const KeyEvent& evt) { } |
---|
122 | virtual void buttonReleased(const KeyEvent& evt) { } |
---|
123 | virtual void buttonHeld (const KeyEvent& evt) { } |
---|
124 | |
---|
125 | virtual void buttonPressed (MouseButtonCode::ByEnum button) { } |
---|
126 | virtual void buttonReleased(MouseButtonCode::ByEnum button) { } |
---|
127 | virtual void buttonHeld (MouseButtonCode::ByEnum button) { } |
---|
128 | virtual void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) { } |
---|
129 | virtual void mouseScrolled (int abs, int rel) { } |
---|
130 | |
---|
131 | virtual void buttonPressed (unsigned int joyStick, JoyStickButtonCode::ByEnum button) { } |
---|
132 | virtual void buttonReleased(unsigned int joyStick, JoyStickButtonCode::ByEnum button) { } |
---|
133 | virtual void buttonHeld (unsigned int joyStick, JoyStickButtonCode::ByEnum button) { } |
---|
134 | virtual void axisMoved (unsigned int joyStick, unsigned int axis, float value){ } |
---|
135 | |
---|
136 | virtual void keyboardUpdated(float dt) { } |
---|
137 | virtual void mouseUpdated (float dt) { } |
---|
138 | virtual void joyStickUpdated(unsigned int joyStick, float dt) { } |
---|
139 | |
---|
140 | virtual void allDevicesUpdated(float dt) { } |
---|
141 | |
---|
142 | static InputHandler EMPTY; |
---|
143 | }; |
---|
144 | } |
---|
145 | |
---|
146 | #endif /* _InputHandler_H__ */ |
---|