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 | #include "InputState.h" |
---|
30 | #include "core/Functor.h" |
---|
31 | |
---|
32 | namespace orxonox |
---|
33 | { |
---|
34 | InputState::InputState() |
---|
35 | : priority_(0) |
---|
36 | , bAlwaysGetsInput_(false) |
---|
37 | , bTransparent_(false) |
---|
38 | , bExpired_(true) |
---|
39 | , handlers_(2) |
---|
40 | , joyStickHandlerAll_(0) |
---|
41 | , enterFunctor_(0) |
---|
42 | , leaveFunctor_(0) |
---|
43 | { |
---|
44 | } |
---|
45 | |
---|
46 | bool InputState::isInputDeviceEnabled(unsigned int device) |
---|
47 | { |
---|
48 | if (device < handlers_.size()) |
---|
49 | return handlers_[device] != NULL; |
---|
50 | else |
---|
51 | return false; |
---|
52 | } |
---|
53 | |
---|
54 | void InputState::JoyStickQuantityChanged(unsigned int n) |
---|
55 | { |
---|
56 | unsigned int oldSize = handlers_.size(); |
---|
57 | handlers_.resize(InputDeviceEnumerator::FirstJoyStick + n, NULL); |
---|
58 | |
---|
59 | for (unsigned int i = oldSize; i < handlers_.size(); ++i) |
---|
60 | handlers_[i] = joyStickHandlerAll_; |
---|
61 | |
---|
62 | bExpired_ = true; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | @brief |
---|
67 | Adds a joy stick handler. |
---|
68 | @param handler |
---|
69 | Pointer to the handler object. |
---|
70 | @param joyStickID |
---|
71 | ID of the joy stick |
---|
72 | @return |
---|
73 | True if added, false otherwise. |
---|
74 | */ |
---|
75 | bool InputState::setJoyStickHandler(InputHandler* handler, unsigned int joyStick) |
---|
76 | { |
---|
77 | unsigned device = joyStick + firstJoyStickIndex_s; |
---|
78 | if (joyStick >= handlers_.size() - device) |
---|
79 | return false; |
---|
80 | |
---|
81 | handlers_[device] = handler; |
---|
82 | bExpired_ = true; |
---|
83 | return true; |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | @brief |
---|
88 | Adds a joy stick handler. |
---|
89 | @param handler |
---|
90 | Pointer to the handler object. |
---|
91 | @return |
---|
92 | True if added, false if handler already existed. |
---|
93 | */ |
---|
94 | bool InputState::setJoyStickHandler(InputHandler* handler) |
---|
95 | { |
---|
96 | joyStickHandlerAll_ = handler; |
---|
97 | for (unsigned int i = firstJoyStickIndex_s; i < handlers_.size(); ++i) |
---|
98 | handlers_[i] = handler; |
---|
99 | bExpired_ = true; |
---|
100 | return true; |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | @brief |
---|
105 | Adds a handler of any kind. dynamic_cast determines to which list it is added. |
---|
106 | @param handler |
---|
107 | Pointer to the handler object. |
---|
108 | @return |
---|
109 | True if added, false if handler already existed. |
---|
110 | */ |
---|
111 | bool InputState::setHandler(InputHandler* handler) |
---|
112 | { |
---|
113 | setKeyHandler(handler); |
---|
114 | setMouseHandler(handler); |
---|
115 | return setJoyStickHandler(handler); |
---|
116 | } |
---|
117 | |
---|
118 | void InputState::entered() |
---|
119 | { |
---|
120 | if (enterFunctor_) |
---|
121 | (*enterFunctor_)(); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | void InputState::left() |
---|
126 | { |
---|
127 | if (leaveFunctor_) |
---|
128 | (*leaveFunctor_)(); |
---|
129 | } |
---|
130 | } |
---|