Changeset 1236 for code/branches/input/src/core
- Timestamp:
- May 6, 2008, 2:32:19 PM (17 years ago)
- Location:
- code/branches/input/src/core
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/CommandExecutor.h
r1214 r1236 89 89 inline std::string getAdditionalParameter() const 90 90 { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; } 91 inline std::string getCommandString() const { return this->processedCommand_; } 91 92 92 93 void setEvaluatedParameter(unsigned int index, MultiTypeMath param); -
code/branches/input/src/core/InputBuffer.cc
r1220 r1236 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 * ... 26 27 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 * Fabian 'x3n' Landau 24 * Co-authors: 25 * Reto Grieder 26 * 27 */ 28 28 29 29 #include "InputBuffer.h" … … 32 32 33 33 #include "util/Clipboard.h" 34 #include "InputManager.h" 34 #include "CoreIncludes.h" 35 #include "ConfigValueIncludes.h" 35 36 36 37 namespace orxonox 37 38 { 38 InputBuffer::InputBuffer() 39 { 40 //this->bActivated_ = false; 41 this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^"; 42 this->keyboard_ = InputManager::getKeyboard(); 43 this->buffer_ = ""; 44 45 //this->keyboard_->setEventCallback(this); 46 } 47 48 InputBuffer::InputBuffer(const std::string allowedChars) 49 { 50 //this->bActivated_ = false; 51 this->allowedChars_ = allowedChars; 52 this->keyboard_ = InputManager::getKeyboard(); 53 this->buffer_ = ""; 54 } 55 /* 56 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput) 57 { 58 struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '}; 59 this->listeners_.insert(this->listeners_.end(), newListener); 60 } 61 62 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput) 63 { 64 struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_}; 65 this->listeners_.insert(this->listeners_.end(), newListener); 66 } 67 */ 68 void InputBuffer::set(const std::string& input) 69 { 70 this->buffer_ = ""; 71 this->append(input); 72 } 73 74 void InputBuffer::append(const std::string& input) 75 { 76 for (unsigned int i = 0; i < input.size(); i++) 77 { 78 if (this->charIsAllowed(input[i])) 79 this->buffer_ += input[i]; 80 81 this->updated(input[i], false); 82 } 83 this->updated(); 84 } 85 86 void InputBuffer::append(const char& input) 87 { 88 if (this->charIsAllowed(input)) 89 this->buffer_ += input; 90 91 this->updated(input, true); 92 } 93 94 void InputBuffer::clear() 95 { 96 this->buffer_ = ""; 97 this->updated(); 98 } 99 100 void InputBuffer::removeLast() 101 { 102 this->buffer_ = this->buffer_.substr(0, this->buffer_.size() - 1); 103 this->updated(); 104 } 105 106 void InputBuffer::updated() 107 { 108 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 109 { 110 if ((*it).bListenToAllChanges_) 111 (*(*it).listener_.*(*it).function_)(); 112 } 113 } 114 115 void InputBuffer::updated(const char& update, bool bSingleInput) 116 { 117 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 118 { 119 if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 120 (*(*it).listener_.*(*it).function_)(); 121 } 122 } 123 124 /*void InputBuffer::activityChanged() const 125 { 126 }*/ 127 128 bool InputBuffer::charIsAllowed(const char& input) 129 { 130 if (this->allowedChars_ == "") 131 return true; 132 else 133 return (this->allowedChars_.find(input) != std::string::npos); 134 } 135 136 bool InputBuffer::keyPressed(const OIS::KeyEvent &e) 137 { 138 /*if (e.key == OIS::KC_NUMPADENTER) 139 { 140 this->setActivated(!this->isActivated()); 141 this->clear(); 142 return true; 143 }*/ 144 145 if (this->keyboard_->isModifierDown(OIS::Keyboard::Ctrl)) 146 { 147 if (e.key == OIS::KC_V) 148 { 149 this->append(fromClipboard()); 150 return true; 151 } 152 else if (e.key == OIS::KC_C) 153 { 154 toClipboard(this->buffer_); 155 return true; 156 } 157 else if (e.key == OIS::KC_X) 158 { 159 toClipboard(this->buffer_); 160 this->clear(); 161 return true; 162 } 163 } 164 else if (this->keyboard_->isModifierDown(OIS::Keyboard::Shift)) 165 { 166 if (e.key == OIS::KC_INSERT) 167 { 168 this->append(fromClipboard()); 169 return true; 170 } 171 else if (e.key == OIS::KC_DELETE) 172 { 173 toClipboard(this->buffer_); 174 this->clear(); 175 return true; 176 } 177 } 178 179 //std::cout << this->keyboard_->getAsString(e.key) << " / " << (char)e.text << std::endl; 180 181 std::string input = this->keyboard_->getAsString(e.key); 182 /*if (input.size() >= 1) 183 this->append(input[0]);*/ 184 185 this->append((char)e.text); 186 return true; 187 } 188 189 bool InputBuffer::keyReleased(const OIS::KeyEvent &e) 190 { 191 return true; 192 } 39 InputBuffer::InputBuffer(const std::string allowedChars) 40 { 41 RegisterObject(InputBuffer); 42 setConfigValues(); 43 allowedChars_ = allowedChars; 44 buffer_ = ""; 45 lastKey_ = KeyCode::Unassigned; 46 timeSinceKeyPressed_ = 0.0; 47 timeSinceKeyRepeated_ = 0.0; 48 keysToRepeat_ = 0; 49 } 50 51 void InputBuffer::setConfigValues() 52 { 53 SetConfigValue(keyRepeatDeleay_, 0.4).description("Key repeat deleay of the input buffer"); 54 SetConfigValue(keyRepeatTime_, 0.022).description("Key repeat time of the input buffer"); 55 if (keyRepeatDeleay_ < 0.0) 56 { 57 ResetConfigValue(keyRepeatDeleay_); 58 } 59 if (keyRepeatTime_ < 0.0) 60 { 61 ResetConfigValue(keyRepeatTime_); 62 } 63 } 64 /* 65 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), bool bOnlySingleInput) 66 { 67 struct InputBufferListenerTuple newListener = {listener, function, true, bOnlySingleInput, ' '}; 68 listeners_.insert(listeners_.end(), newListener); 69 } 70 71 void InputBuffer::registerListener(InputBufferListener* listener, void (InputBufferListener::*function)(), char char_, bool bOnlySingleInput) 72 { 73 struct InputBufferListenerTuple newListener = {listener, function, false, bOnlySingleInput, char_}; 74 listeners_.insert(listeners_.end(), newListener); 75 } 76 */ 77 void InputBuffer::set(const std::string& input) 78 { 79 buffer_ = ""; 80 append(input); 81 } 82 83 void InputBuffer::append(const std::string& input) 84 { 85 for (unsigned int i = 0; i < input.size(); i++) 86 { 87 if (charIsAllowed(input[i])) 88 buffer_ += input[i]; 89 90 updated(input[i], false); 91 } 92 updated(); 93 } 94 95 void InputBuffer::append(const char& input) 96 { 97 if (charIsAllowed(input)) 98 buffer_ += input; 99 100 updated(input, true); 101 } 102 103 void InputBuffer::clear() 104 { 105 buffer_ = ""; 106 updated(); 107 } 108 109 void InputBuffer::removeLast() 110 { 111 buffer_ = buffer_.substr(0, buffer_.size() - 1); 112 updated(); 113 } 114 115 void InputBuffer::updated() 116 { 117 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 118 { 119 if ((*it).bListenToAllChanges_) 120 (*(*it).listener_.*(*it).function_)(); 121 } 122 } 123 124 void InputBuffer::updated(const char& update, bool bSingleInput) 125 { 126 for (std::list<InputBufferListenerTuple>::iterator it = listeners_.begin(); it != listeners_.end(); ++it) 127 { 128 if (((*it).bListenToAllChanges_ || ((*it).char_ == update)) && (!(*it).bOnlySingleInput_ || bSingleInput)) 129 (*(*it).listener_.*(*it).function_)(); 130 } 131 } 132 133 bool InputBuffer::charIsAllowed(const char& input) 134 { 135 if (allowedChars_ == "") 136 return true; 137 else 138 return (allowedChars_.find(input) != std::string::npos); 139 } 140 141 142 void InputBuffer::processKey(const KeyEvent &evt) 143 { 144 if (evt.isModifierDown(KeyboardModifier::Ctrl)) 145 { 146 if (evt.key == KeyCode::V) 147 append(fromClipboard()); 148 else if (evt.key == KeyCode::C) 149 toClipboard(buffer_); 150 else if (evt.key == KeyCode::X) 151 { 152 toClipboard(buffer_); 153 clear(); 154 } 155 } 156 else if (evt.isModifierDown(KeyboardModifier::Shift)) 157 { 158 if (evt.key == KeyCode::Insert) 159 { 160 append(fromClipboard()); 161 } 162 else if (evt.key == KeyCode::Delete) 163 { 164 toClipboard(buffer_); 165 clear(); 166 } 167 } 168 //std::string input = keyboard_->getAsString(e.key); 169 /*if (input.size() >= 1) 170 append(input[0]);*/ 171 172 append((char)evt.text); 173 } 174 175 void InputBuffer::tick(float dt) 176 { 177 timeSinceKeyPressed_ += dt; 178 if (keysToRepeat_ < 10 && timeSinceKeyPressed_ > keyRepeatDeleay_) 179 { 180 // initial time out has gone by, start repeating keys 181 while (timeSinceKeyPressed_ - timeSinceKeyRepeated_ > keyRepeatTime_) 182 { 183 timeSinceKeyRepeated_ += keyRepeatTime_; 184 keysToRepeat_++; 185 } 186 } 187 } 188 189 bool InputBuffer::keyPressed(const KeyEvent &evt) 190 { 191 lastKey_ = evt.key; 192 timeSinceKeyPressed_ = 0.0; 193 timeSinceKeyRepeated_ = keyRepeatDeleay_; 194 keysToRepeat_ = 0; 195 196 processKey(evt); 197 return true; 198 } 199 200 bool InputBuffer::keyHeld(const KeyEvent& evt) 201 { 202 if (evt.key == lastKey_) 203 { 204 while (keysToRepeat_) 205 { 206 processKey(evt); 207 keysToRepeat_--; 208 } 209 } 210 return true; 211 } 212 193 213 } -
code/branches/input/src/core/InputBuffer.h
r1219 r1236 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 */ 28 28 29 29 #ifndef _InputBuffer_H__ … … 35 35 #include <list> 36 36 37 #include " ois/OISKeyboard.h"38 #include " InputHandler.h"37 #include "InputInterfaces.h" 38 #include "Tickable.h" 39 39 40 40 namespace orxonox 41 41 { 42 43 42 class _CoreExport InputBufferListener 43 {}; 44 44 45 class _CoreExport InputBuffer : public KeyHandler 45 class _CoreExport InputBuffer : public KeyHandler, public Tickable 46 { 47 struct InputBufferListenerTuple 46 48 { 47 struct InputBufferListenerTuple 48 { 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 char char_; 54 }; 49 InputBufferListener* listener_; 50 void (InputBufferListener::*function_)(); 51 bool bListenToAllChanges_; 52 bool bOnlySingleInput_; 53 char char_; 54 }; 55 55 56 57 InputBuffer();58 InputBuffer(const std::string allowedChars);56 public: 57 InputBuffer(const std::string allowedChars = 58 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^"); 59 59 60 template <class T> 61 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 62 { 63 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 64 this->listeners_.insert(this->listeners_.end(), newListener); 65 } 66 template <class T> 67 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 68 { 69 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 70 this->listeners_.insert(this->listeners_.end(), newListener); 71 } 60 void setConfigValues(); 72 61 73 74 void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput)75 76 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};77 78 79 80 void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput)81 82 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_};83 84 62 template <class T> 63 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 64 { 65 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 66 this->listeners_.insert(this->listeners_.end(), newListener); 67 } 68 template <class T> 69 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 70 { 71 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, true, bOnlySingleInput, ' '}; 72 this->listeners_.insert(this->listeners_.end(), newListener); 73 } 85 74 86 void set(const std::string& input); 87 void append(const std::string& input); 88 void append(const char& input); 89 void removeLast(); 90 void clear(); 75 template <class T> 76 void registerListener(T* listener, void (T::*function)(), char char_, bool bOnlySingleInput) 77 { 78 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_}; 79 this->listeners_.insert(this->listeners_.end(), newListener); 80 } 81 template <class T> 82 void registerListener(T* listener, void (T::*function)() const, char char_, bool bOnlySingleInput) 83 { 84 struct InputBufferListenerTuple newListener = {listener, (void (InputBufferListener::*)())function, false, bOnlySingleInput, char_}; 85 this->listeners_.insert(this->listeners_.end(), newListener); 86 } 91 87 92 void updated(); 93 void updated(const char& update, bool bSingleInput); 88 void set(const std::string& input); 89 void append(const std::string& input); 90 void append(const char& input); 91 void removeLast(); 92 void clear(); 94 93 95 inline std::string get() const96 { return this->buffer_; }94 void updated(); 95 void updated(const char& update, bool bSingleInput); 97 96 98 /*inline void activate() 99 { this->setActivated(true); } 100 inline void deactivate() 101 { this->setActivated(false); } 102 inline void setActivated(bool bActivated) 103 { if (this->bActivated_ != bActivated) { this->bActivated_ = bActivated; this->activityChanged(); } else { this->bActivated_ = bActivated; } } 104 inline bool isActivated() const 105 { return this->bActivated_; } 97 inline std::string get() const 98 { return this->buffer_; } 106 99 107 void activityChanged() const;*/ 100 private: 101 bool charIsAllowed(const char& input); 108 102 109 private: 110 bool charIsAllowed(const char& input); 103 bool keyPressed (const KeyEvent& evt); 104 bool keyReleased(const KeyEvent& evt) { return true; } 105 bool keyHeld (const KeyEvent& evt); 106 void processKey (const KeyEvent &e); 111 107 112 bool keyPressed(const OIS::KeyEvent &e); 113 bool keyReleased(const OIS::KeyEvent &e); 114 bool keyHeld(const OIS::KeyEvent &e) { return true; } 108 void tick(float dt); 115 109 116 OIS::Keyboard* keyboard_; 117 //bool bActivated_; 118 std::string buffer_; 119 std::list<InputBufferListenerTuple> listeners_; 120 std::string allowedChars_; 121 }; 110 std::string buffer_; 111 std::list<InputBufferListenerTuple> listeners_; 112 std::string allowedChars_; 113 114 KeyCode::Enum lastKey_; 115 float timeSinceKeyPressed_; 116 float timeSinceKeyRepeated_; 117 int keysToRepeat_; 118 119 // configured values 120 float keyRepeatDeleay_; 121 float keyRepeatTime_; 122 }; 122 123 } 123 124 -
code/branches/input/src/core/InputHandler.cc
r1219 r1236 33 33 34 34 #include "InputHandler.h" 35 #include "util/Convert.h" 35 36 #include "Debug.h" 36 37 #include "ConfigValueIncludes.h" 37 38 #include "CoreIncludes.h" 38 #include "util/Convert.h" 39 #include "core/CommandExecutor.h" 39 #include "CommandExecutor.h" 40 40 41 41 namespace orxonox … … 267 267 switch (j) 268 268 { 269 // note: the first element in the struct is the string, so the following pointer270 // arithmetic works.271 269 case 0: 272 270 cont->getValue(&bindingsKeyPress_[i].commandStr); 273 271 break; 274 272 case 1: 275 cont->getValue( bindingsKeyRelease_ + i);273 cont->getValue(&bindingsKeyRelease_[i].commandStr); 276 274 break; 277 275 case 2: 278 cont->getValue( bindingsKeyHold_ + i);276 cont->getValue(&bindingsKeyHold_[i].commandStr); 279 277 } 280 278 } … … 295 293 { 296 294 case 0: 297 cont->getValue( bindingsMouseButtonPress_ + i);295 cont->getValue(&bindingsMouseButtonPress_[i].commandStr); 298 296 break; 299 297 case 1: 300 cont->getValue( bindingsMouseButtonRelease_ + i);298 cont->getValue(&bindingsMouseButtonRelease_[i].commandStr); 301 299 break; 302 300 case 2: 303 cont->getValue( bindingsMouseButtonHold_ + i);301 cont->getValue(&bindingsMouseButtonHold_[i].commandStr); 304 302 } 305 303 } … … 320 318 { 321 319 case 0: 322 cont->getValue( bindingsJoyStickButtonPress_ + i);320 cont->getValue(&bindingsJoyStickButtonPress_[i].commandStr); 323 321 break; 324 322 case 1: 325 cont->getValue( bindingsJoyStickButtonRelease_ + i);323 cont->getValue(&bindingsJoyStickButtonRelease_[i].commandStr); 326 324 break; 327 325 case 2: 328 cont->getValue( bindingsJoyStickButtonHold_ + i);326 cont->getValue(&bindingsJoyStickButtonHold_[i].commandStr); 329 327 } 330 328 } … … 345 343 for (int i = 0; i < numberOfMouseButtons_s; i++) 346 344 { 347 bindingsMouseButtonPress_ [i] = "";348 bindingsMouseButtonRelease_[i] = "";349 bindingsMouseButtonHold_ [i] = "";345 bindingsMouseButtonPress_ [i].commandStr = ""; 346 bindingsMouseButtonRelease_[i].commandStr = ""; 347 bindingsMouseButtonHold_ [i].commandStr = ""; 350 348 } 351 349 for (int i = 0; i < numberOfJoyStickButtons_s; i++) 352 350 { 353 bindingsJoyStickButtonPress_ [i] = "";354 bindingsJoyStickButtonRelease_[i] = "";355 bindingsJoyStickButtonHold_ [i] = "";351 bindingsJoyStickButtonPress_ [i].commandStr = ""; 352 bindingsJoyStickButtonRelease_[i].commandStr = ""; 353 bindingsJoyStickButtonHold_ [i].commandStr = ""; 356 354 } 357 355 } … … 370 368 // evaluate the key bindings 371 369 // TODO: what if binding is invalid? 372 //for (int i = 0; i < numberOfKeys_s; i++)373 //{374 //if (bindingsKeyPress_[i].commandStr != "")375 //{376 //bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr);377 //bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString();378 //}379 //}370 for (int i = 0; i < numberOfKeys_s; i++) 371 { 372 if (bindingsKeyPress_[i].commandStr != "") 373 { 374 bindingsKeyPress_[i].evaluation = CommandExecutor::evaluate(bindingsKeyPress_[i].commandStr); 375 bindingsKeyPress_[i].commandStr = bindingsKeyPress_[i].evaluation.getCommandString(); 376 } 377 } 380 378 381 379 COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl; … … 387 385 if (binding.commandStr != "") 388 386 { 389 //if (binding.commandStr != binding.evaluation.getCommandString())390 //{391 //// key binding has changed, reevaluate the command string.392 //binding.evaluation = CommandExecutor::evaluate(binding.commandStr);393 //binding.commandStr = binding.evaluation.getCommandString();394 //}387 if (binding.commandStr != binding.evaluation.getCommandString()) 388 { 389 // key binding has changed, reevaluate the command string. 390 binding.evaluation = CommandExecutor::evaluate(binding.commandStr); 391 binding.commandStr = binding.evaluation.getCommandString(); 392 } 395 393 COUT(3) << "Executing command: " << binding.commandStr << std::endl; 396 394 CommandExecutor::execute(binding.commandStr); … … 405 403 @param e Event information 406 404 */ 407 bool KeyBinder::keyPressed(const OIS::KeyEvent &e) 408 { 409 COUT(3) << "Key: " << e.key << std::endl; 410 // find the appropriate key binding 411 executeBinding(bindingsKeyPress_[int(e.key)]); 412 405 bool KeyBinder::keyPressed(const KeyEvent& evt) 406 { 407 // find the appropriate key binding 408 executeBinding(bindingsKeyPress_[int(evt.key)]); 409 413 410 return true; 414 411 } … … 418 415 @param e Event information 419 416 */ 420 bool KeyBinder::keyReleased(const OIS::KeyEvent &e)421 { 422 // find the appropriate key binding 423 executeBinding(bindingsKeyRelease_[int(e .key)]);417 bool KeyBinder::keyReleased(const KeyEvent& evt) 418 { 419 // find the appropriate key binding 420 executeBinding(bindingsKeyRelease_[int(evt.key)]); 424 421 425 422 return true; … … 428 425 /** 429 426 @brief Event handler for the keyHeld Event. 430 @param e Eventinformation431 */ 432 bool KeyBinder::keyHeld(const OIS::KeyEvent &e)433 { 434 // find the appropriate key binding 435 executeBinding(bindingsKeyHold_[int(e .key)]);427 @param e Mouse state information 428 */ 429 bool KeyBinder::keyHeld(const KeyEvent& evt) 430 { 431 // find the appropriate key binding 432 executeBinding(bindingsKeyHold_[int(evt.key)]); 436 433 437 434 return true; … … 440 437 /** 441 438 @brief Event handler for the mouseMoved Event. 442 @param e Event information 443 */ 444 bool KeyBinder::mouseMoved(const OIS::MouseEvent &e) 439 @param e Mouse state information 440 */ 441 bool KeyBinder::mouseMoved(const MouseState &evt) 442 { 443 return true; 444 } 445 446 /** 447 @brief Event handler for the mouseWheelTurned Event. 448 @param e Mouse state information 449 */ 450 bool KeyBinder::mouseWheelTurned(const MouseState &evt) 445 451 { 446 452 return true; … … 452 458 @param id The ID of the mouse button 453 459 */ 454 bool KeyBinder::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 455 { 456 // find the appropriate key binding 457 std::string cmdStr = bindingsMouseButtonPress_[int(id)]; 458 if (cmdStr != "") 459 { 460 CommandExecutor::execute(cmdStr); 461 COUT(3) << "Executing command: " << cmdStr << std::endl; 462 } 460 bool KeyBinder::mouseButtonPressed(const MouseState& state, MouseButton::Enum id) 461 { 462 // find the appropriate key binding 463 executeBinding(bindingsMouseButtonPress_[int(id)]); 463 464 464 465 return true; … … 470 471 @param id The ID of the mouse button 471 472 */ 472 bool KeyBinder::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 473 { 474 // find the appropriate key binding 475 std::string cmdStr = bindingsMouseButtonRelease_[int(id)]; 476 if (cmdStr != "") 477 { 478 CommandExecutor::execute(cmdStr); 479 COUT(3) << "Executing command: " << cmdStr << std::endl; 480 } 473 bool KeyBinder::mouseButtonReleased(const MouseState& state, MouseButton::Enum id) 474 { 475 // find the appropriate key binding 476 executeBinding(bindingsMouseButtonRelease_[int(id)]); 481 477 482 478 return true; … … 488 484 @param id The ID of the mouse button 489 485 */ 490 bool KeyBinder::mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) 491 { 492 // find the appropriate key binding 493 std::string cmdStr = bindingsMouseButtonHold_[int(id)]; 494 if (cmdStr != "") 495 { 496 CommandExecutor::execute(cmdStr); 497 COUT(3) << "Executing command: " << cmdStr << std::endl; 498 } 499 500 return true; 501 } 502 503 bool KeyBinder::buttonPressed(int joyStickID, const OIS::JoyStickEvent &arg, int button) 504 { 505 // find the appropriate key binding 506 std::string cmdStr = bindingsJoyStickButtonPress_[button]; 507 if (cmdStr != "") 508 { 509 CommandExecutor::execute(cmdStr); 510 COUT(3) << "Executing command: " << cmdStr << std::endl; 511 } 512 513 return true; 514 } 515 516 bool KeyBinder::buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) 517 { 518 // find the appropriate key binding 519 std::string cmdStr = bindingsJoyStickButtonRelease_[button]; 520 if (cmdStr != "") 521 { 522 CommandExecutor::execute(cmdStr); 523 COUT(3) << "Executing command: " << cmdStr << std::endl; 524 } 525 526 return true; 527 } 528 529 bool KeyBinder::buttonHeld(int joyStickID, const OIS::JoyStickEvent &arg, int button) 530 { 531 // find the appropriate key binding 532 std::string cmdStr = bindingsJoyStickButtonHold_[button]; 533 if (cmdStr != "") 534 { 535 CommandExecutor::execute(cmdStr); 536 COUT(3) << "Executing command: " << cmdStr << std::endl; 537 } 538 539 return true; 540 } 541 542 bool KeyBinder::axisMoved(int joyStickID, const OIS::JoyStickEvent &arg, int axis) 543 { 544 return true; 545 } 546 547 bool KeyBinder::sliderMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 548 { 549 return true; 550 } 551 552 bool KeyBinder::povMoved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 553 { 554 return true; 555 } 556 557 bool KeyBinder::vector3Moved(int joyStickID, const OIS::JoyStickEvent &arg, int id) 486 bool KeyBinder::mouseButtonHeld(const MouseState& state, MouseButton::Enum id) 487 { 488 // find the appropriate key binding 489 executeBinding(bindingsMouseButtonHold_[int(id)]); 490 491 return true; 492 } 493 494 bool KeyBinder::joyStickButtonPressed(const JoyStickState& state, int button) 495 { 496 // find the appropriate key binding 497 executeBinding(bindingsJoyStickButtonPress_[button]); 498 499 return true; 500 } 501 502 bool KeyBinder::joyStickButtonReleased(const JoyStickState& state, int button) 503 { 504 // find the appropriate key binding 505 executeBinding(bindingsJoyStickButtonRelease_[button]); 506 507 return true; 508 } 509 510 bool KeyBinder::joyStickButtonHeld(const JoyStickState& state, int button) 511 { 512 // find the appropriate key binding 513 executeBinding(bindingsJoyStickButtonHold_[button]); 514 515 return true; 516 } 517 518 bool KeyBinder::joyStickAxisMoved(const JoyStickState& state, int axis) 519 { 520 return true; 521 } 522 523 bool KeyBinder::joyStickSliderMoved(const JoyStickState& state, int index) 524 { 525 return true; 526 } 527 528 bool KeyBinder::joyStickPovMoved(const JoyStickState& state, int index) 529 { 530 return true; 531 } 532 533 bool KeyBinder::joyStickVector3Moved(const JoyStickState& state, int index) 558 534 { 559 535 return true; … … 616 592 // @param id The ID of the mouse button 617 593 //*/ 618 //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton IDid)594 //bool GUIInputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButton id) 619 595 //{ 620 596 ////CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id)); … … 627 603 // @param id The ID of the mouse button 628 604 //*/ 629 //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton IDid)605 //bool GUIInputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButton id) 630 606 //{ 631 607 ////CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id)); -
code/branches/input/src/core/InputHandler.h
r1219 r1236 38 38 39 39 #include <string> 40 40 41 #include "ois/OIS.h" 41 42 #include "OrxonoxClass.h" 42 43 #include "CommandExecutor.h" 44 #include "InputInterfaces.h" 43 45 44 46 namespace orxonox … … 54 56 }; 55 57 } 56 57 /**58 @brief Interface class used for key input listeners.59 */60 class _CoreExport KeyHandler : public OIS::KeyListener61 {62 public:63 virtual ~KeyHandler() { }64 virtual bool keyHeld(const OIS::KeyEvent &arg) = 0;65 };66 67 /**68 @brief Interface class used for mouse input listeners.69 */70 class _CoreExport MouseHandler : public OIS::MouseListener71 {72 public:73 virtual ~MouseHandler() { }74 virtual bool mouseHeld(const OIS::MouseEvent &arg, OIS::MouseButtonID id) = 0;75 };76 77 /**78 @brief Interface class used for joy stick input listeners.79 */80 class _CoreExport JoyStickHandler81 {82 public:83 virtual ~JoyStickHandler() { }84 virtual bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;85 virtual bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;86 virtual bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button) = 0;87 virtual bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis) = 0;88 virtual bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}89 virtual bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}90 virtual bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int index) {return true;}91 };92 58 93 59 struct _CoreExport KeyBinding … … 119 85 bool executeBinding(KeyBinding &binding); 120 86 121 bool keyPressed (const OIS::KeyEvent &arg);122 bool keyReleased (const OIS::KeyEvent &arg);123 bool keyHeld (const OIS::KeyEvent &arg);87 bool keyPressed (const KeyEvent& evt); 88 bool keyReleased(const KeyEvent& evt); 89 bool keyHeld (const KeyEvent& evt); 124 90 125 bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 126 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); 127 bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButtonID id); 128 bool mouseMoved (const OIS::MouseEvent &arg); 91 bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id); 92 bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id); 93 bool mouseButtonHeld (const MouseState& state, MouseButton::Enum id); 94 bool mouseMoved (const MouseState& state); 95 bool mouseWheelTurned (const MouseState& state); 129 96 130 bool buttonPressed (int joyStickID, const OIS::JoyStickEvent &arg, int button);131 bool buttonReleased(int joyStickID, const OIS::JoyStickEvent &arg, int button);132 bool buttonHeld (int joyStickID, const OIS::JoyStickEvent &arg, int button);133 bool axisMoved (int joyStickID, const OIS::JoyStickEvent &arg, int axis);134 bool sliderMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id);135 bool povMoved (int joyStickID, const OIS::JoyStickEvent &arg, int id);136 bool vector3Moved (int joyStickID, const OIS::JoyStickEvent &arg, int id);97 bool joyStickButtonPressed (const JoyStickState& state, int button); 98 bool joyStickButtonReleased(const JoyStickState& state, int button); 99 bool joyStickButtonHeld (const JoyStickState& state, int button); 100 bool joyStickAxisMoved (const JoyStickState& state, int axis) ; 101 bool joyStickSliderMoved (const JoyStickState& state, int index) ; 102 bool joyStickPovMoved (const JoyStickState& state, int index) ; 103 bool joyStickVector3Moved (const JoyStickState& state, int index) ; 137 104 138 105 private: // variables … … 152 119 static const int numberOfMouseButtons_s = 8; 153 120 //! Array of input events for every pressed mouse button 154 std::string bindingsMouseButtonPress_ [numberOfMouseButtons_s];121 KeyBinding bindingsMouseButtonPress_ [numberOfMouseButtons_s]; 155 122 //! Array of input events for every released mouse button 156 std::string bindingsMouseButtonRelease_[numberOfMouseButtons_s];123 KeyBinding bindingsMouseButtonRelease_[numberOfMouseButtons_s]; 157 124 //! Array of input events for every held mouse button 158 std::string bindingsMouseButtonHold_ [numberOfMouseButtons_s];125 KeyBinding bindingsMouseButtonHold_ [numberOfMouseButtons_s]; 159 126 //! Names of the mouse buttons as strings 160 127 std::string mouseButtonNames_[numberOfMouseButtons_s]; … … 163 130 static const int numberOfJoyStickButtons_s = 32; 164 131 //! Array of input events for every pressed joy stick button 165 std::string bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s];132 KeyBinding bindingsJoyStickButtonPress_ [numberOfJoyStickButtons_s]; 166 133 //! Array of input events for every released joy stick button 167 std::string bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s];134 KeyBinding bindingsJoyStickButtonRelease_[numberOfJoyStickButtons_s]; 168 135 //! Array of input events for every held joy stick button 169 std::string bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s];136 KeyBinding bindingsJoyStickButtonHold_ [numberOfJoyStickButtons_s]; 170 137 //! Names of the joy stick buttons as strings 171 138 std::string joyStickButtonNames_[numberOfJoyStickButtons_s]; … … 190 157 //bool keyHeld (const OIS::KeyEvent &arg); 191 158 192 // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButton IDid);193 //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButton IDid);194 //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButton IDid);159 // bool mousePressed (const OIS::MouseEvent &arg, OIS::MouseButton id); 160 //bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButton id); 161 //bool mouseHeld (const OIS::MouseEvent &arg, OIS::MouseButton id); 195 162 // bool mouseMoved (const OIS::MouseEvent &arg); 196 163 -
code/branches/input/src/core/InputManager.cc
r1219 r1236 30 30 @file 31 31 @brief Implementation of the InputManager that captures all the input from OIS 32 and redirects it to handlers if necessary.32 and redirects it to handlers. 33 33 */ 34 34 … … 52 52 InputManager::InputManager() : 53 53 inputSystem_(0), keyboard_(0), mouse_(0), 54 state_(IS_UNINIT), stateRequest_(IS_UNINIT) 54 state_(IS_UNINIT), stateRequest_(IS_UNINIT), 55 joySticksSize_(0) 55 56 { 56 57 RegisterObject(InputManager); 57 58 58 this->joySticks_.reserve(5);59 //this->joySticks_.reserve(5); 59 60 //this->activeJoyStickHandlers_.reserve(10); 60 61 this->activeKeyHandlers_.reserve(10); … … 234 235 bool InputManager::_initialiseJoySticks() 235 236 { 236 if (joySticks _.size()> 0)237 if (joySticksSize_ > 0) 237 238 { 238 239 CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; … … 265 266 return false; 266 267 } 268 joySticksSize_ = joySticks_.size(); 267 269 return success; 268 270 } … … 336 338 void InputManager::_destroyJoySticks() 337 339 { 338 if (joySticks _.size()> 0)340 if (joySticksSize_ > 0) 339 341 { 340 342 // note: inputSystem_ can never be 0, or else the code is mistaken 341 for (unsigned int i = 0; i < joySticks _.size(); i++)343 for (unsigned int i = 0; i < joySticksSize_; i++) 342 344 if (joySticks_[i] != 0) 343 345 inputSystem_->destroyInputObject(joySticks_[i]); 344 346 345 347 joySticks_.clear(); 348 joySticksSize_ = 0; 346 349 activeJoyStickHandlers_.clear(); 347 350 joyStickButtonsDown_.clear(); … … 382 385 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 383 386 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 384 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin(); 385 it != joySticks_.end(); it++) 386 activeJoyStickHandlers_[*it].push_back(joyStickHandlers_["keybinder"]); 387 for (unsigned int i = 0; i < joySticksSize_; i++) 388 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 387 389 break; 388 390 … … 393 395 case IS_CONSOLE: 394 396 activeMouseHandlers_.push_back(mouseHandlers_["keybinder"]); 395 for (std::vector<OIS::JoyStick*>::const_iterator it = joySticks_.begin();396 it != joySticks_.end(); it++)397 activeJoyStickHandlers_[ *it].push_back(joyStickHandlers_["keybinder"]);397 activeMouseHandlers_.push_back(mouseHandlers_["SpaceShip"]); 398 for (unsigned int i = 0; i < joySticksSize_; i++) 399 activeJoyStickHandlers_[i].push_back(joyStickHandlers_["keybinder"]); 398 400 399 401 activeKeyHandlers_.push_back(keyHandlers_["buffer"]); … … 415 417 416 418 // call all the handlers for the held key events 417 for (std::list<OIS::KeyCode>::const_iterator itKey = keysDown_.begin(); 418 itKey != keysDown_.end(); itKey++) 419 { 420 OIS::KeyEvent keyArg(keyboard_, *itKey, 0); 421 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 422 activeKeyHandlers_[i]->keyHeld(keyArg); 423 } 419 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 420 for (unsigned int iHandler = 0; iHandler < activeKeyHandlers_.size(); iHandler++) 421 activeKeyHandlers_[iHandler]->keyHeld(KeyEvent(keysDown_[iKey], keyboardModifiers_)); 424 422 425 423 // call all the handlers for the held mouse button events 426 for (std::list<OIS::MouseButtonID>::const_iterator itMouseButton = mouseButtonsDown_.begin(); 427 itMouseButton != mouseButtonsDown_.end(); itMouseButton++) 428 { 429 OIS::MouseEvent mouseButtonArg(mouse_, mouse_->getMouseState()); 430 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 431 activeMouseHandlers_[i]->mouseHeld(mouseButtonArg, *itMouseButton); 432 } 424 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 425 for (unsigned int iHandler = 0; iHandler < activeMouseHandlers_.size(); iHandler++) 426 activeMouseHandlers_[iHandler]->mouseButtonHeld(mouse_->getMouseState(), mouseButtonsDown_[iButton]); 433 427 434 428 // call all the handlers for the held joy stick button events 435 for (std::map< OIS::JoyStick*, std::list <int> >::const_iterator itJoyStick = joyStickButtonsDown_.begin(); 436 itJoyStick != joyStickButtonsDown_.end(); itJoyStick++) 437 { 438 OIS::JoyStick* joyStick = (*itJoyStick).first; 439 for (std::list<int>::const_iterator itJoyStickButton = (*itJoyStick).second.begin(); 440 itJoyStickButton != (*itJoyStick).second.end(); itJoyStickButton++) 441 { 442 OIS::JoyStickEvent joyStickButtonArg(joyStick, joyStick->getJoyStickState()); 443 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 444 activeJoyStickHandlers_[joyStick][i]->buttonHeld(i, joyStickButtonArg, *itJoyStickButton); 445 } 446 } 447 } 448 429 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 430 for (unsigned int iButton = 0; iButton < joyStickButtonsDown_.size(); iButton++) 431 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 432 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonHeld( 433 JoyStickState(joySticks_[iJoyStick]->getJoyStickState(), iJoyStick), joyStickButtonsDown_[iJoyStick][iButton]); 434 } 449 435 450 436 // ###### Key Events ###### … … 457 443 { 458 444 // check whether the key already is in the list (can happen when focus was lost) 459 for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++) 460 { 461 if (*it == e.key) 462 { 463 keysDown_.erase(it); 464 break; 465 } 466 } 467 keysDown_.push_back(e.key); 445 unsigned int iKey = 0; 446 while (iKey < keysDown_.size() && keysDown_[iKey].key != e.key) 447 iKey++; 448 if (iKey == keysDown_.size()) 449 keysDown_.push_back(Key(e)); 450 451 // update modifiers 452 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 453 keyboardModifiers_ |= KeyboardModifier::Alt; // alt key 454 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 455 keyboardModifiers_ |= KeyboardModifier::Ctrl; // ctrl key 456 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 457 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 468 458 469 459 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 470 activeKeyHandlers_[i]->keyPressed( e);460 activeKeyHandlers_[i]->keyPressed(KeyEvent(e, keyboardModifiers_)); 471 461 472 462 return true; … … 480 470 { 481 471 // remove the key from the keysDown_ list 482 for ( std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)483 { 484 if ( *it== e.key)485 { 486 keysDown_.erase( it);472 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 473 { 474 if (keysDown_[iKey].key == e.key) 475 { 476 keysDown_.erase(keysDown_.begin() + iKey); 487 477 break; 488 478 } 489 479 } 490 480 481 // update modifiers 482 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 483 keyboardModifiers_ &= ~KeyboardModifier::Alt; // alt key 484 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 485 keyboardModifiers_ &= ~KeyboardModifier::Ctrl; // ctrl key 486 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 487 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 488 491 489 for (unsigned int i = 0; i < activeKeyHandlers_.size(); i++) 492 activeKeyHandlers_[i]->keyReleased( e);490 activeKeyHandlers_[i]->keyReleased(KeyEvent(e, keyboardModifiers_)); 493 491 494 492 return true; … … 504 502 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 505 503 { 506 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 507 activeMouseHandlers_[i]->mouseMoved(e); 504 // check for actual moved event 505 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 506 { 507 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 508 activeMouseHandlers_[i]->mouseMoved(e.state); 509 } 510 511 // check for mouse wheel turned event 512 if (e.state.Z.rel != 0) 513 { 514 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 515 activeMouseHandlers_[i]->mouseWheelTurned(e.state); 516 } 508 517 509 518 return true; … … 518 527 { 519 528 // check whether the button already is in the list (can happen when focus was lost) 520 for (std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++) 521 { 522 if (*it == id) 523 { 524 mouseButtonsDown_.erase(it); 525 break; 526 } 527 } 528 mouseButtonsDown_.push_back(id); 529 unsigned int iButton = 0; 530 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != id) 531 iButton++; 532 if (iButton == mouseButtonsDown_.size()) 533 mouseButtonsDown_.push_back((MouseButton::Enum)id); 529 534 530 535 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 531 activeMouseHandlers_[i]->mouse Pressed(e,id);536 activeMouseHandlers_[i]->mouseButtonPressed(e.state, (MouseButton::Enum)id); 532 537 533 538 return true; … … 542 547 { 543 548 // remove the button from the keysDown_ list 544 for ( std::list<OIS::MouseButtonID>::iterator it = mouseButtonsDown_.begin(); it != mouseButtonsDown_.end(); it++)545 { 546 if ( *it== id)547 { 548 mouseButtonsDown_.erase( it);549 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 550 { 551 if (mouseButtonsDown_[iButton] == id) 552 { 553 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); 549 554 break; 550 555 } … … 552 557 553 558 for (unsigned int i = 0; i < activeMouseHandlers_.size(); i++) 554 activeMouseHandlers_[i]->mouse Released(e,id);559 activeMouseHandlers_[i]->mouseButtonReleased(e.state, (MouseButton::Enum)id); 555 560 556 561 return true; … … 562 567 bool InputManager::buttonPressed(const OIS::JoyStickEvent &arg, int button) 563 568 { 569 // use the device to identify which one called the method 564 570 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 571 unsigned int iJoyStick = 0; 572 while (joySticks_[iJoyStick] != joyStick) 573 iJoyStick++; 565 574 566 575 // check whether the button already is in the list (can happen when focus was lost) 567 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 568 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 569 { 570 if (*it == button) 571 { 572 buttonsDownList.erase(it); 576 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick]; 577 unsigned int iButton = 0; 578 while (iButton < buttonsDown.size() && buttonsDown[iButton] != button) 579 iButton++; 580 if (iButton == buttonsDown.size()) 581 buttonsDown.push_back(button); 582 583 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 584 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonPressed(JoyStickState(arg.state, iJoyStick), button); 585 586 return true; 587 } 588 589 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button) 590 { 591 // use the device to identify which one called the method 592 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 593 unsigned int iJoyStick = 0; 594 while (joySticks_[iJoyStick] != joyStick) 595 iJoyStick++; 596 597 // remove the button from the joyStickButtonsDown_ list 598 std::vector<int> buttonsDown = joyStickButtonsDown_[iJoyStick]; 599 for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++) 600 { 601 if (buttonsDown[iButton] == button) 602 { 603 buttonsDown.erase(buttonsDown.begin() + iButton); 573 604 break; 574 605 } 575 606 } 576 joyStickButtonsDown_[joyStick].push_back(button); 577 578 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++)579 activeJoyStickHandlers_[joyStick][i]->buttonPressed(i, arg, button); 580 581 return true;582 } 583 584 bool InputManager::buttonReleased(const OIS::JoyStickEvent &arg, int button)585 {607 608 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 609 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickButtonReleased(JoyStickState(arg.state, iJoyStick), button); 610 611 return true; 612 } 613 614 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 615 { 616 // use the device to identify which one called the method 586 617 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 587 588 // remove the button from the joyStickButtonsDown_ list 589 std::list<int>& buttonsDownList = joyStickButtonsDown_[joyStick]; 590 for (std::list<int>::iterator it = buttonsDownList.begin(); it != buttonsDownList.end(); it++) 591 { 592 if (*it == button) 593 { 594 buttonsDownList.erase(it); 595 break; 596 } 597 } 598 599 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 600 activeJoyStickHandlers_[joyStick][i]->buttonReleased(i, arg, button); 601 602 return true; 603 } 604 605 bool InputManager::axisMoved(const OIS::JoyStickEvent &arg, int axis) 606 { 618 unsigned int iJoyStick = 0; 619 while (joySticks_[iJoyStick] != joyStick) 620 iJoyStick++; 621 622 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 623 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickAxisMoved(JoyStickState(arg.state, iJoyStick), axis); 624 625 return true; 626 } 627 628 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 629 { 630 // use the device to identify which one called the method 607 631 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 608 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 609 activeJoyStickHandlers_[joyStick][i]->axisMoved(i, arg, axis); 610 611 return true; 612 } 613 614 bool InputManager::sliderMoved(const OIS::JoyStickEvent &arg, int id) 615 { 632 unsigned int iJoyStick = 0; 633 while (joySticks_[iJoyStick] != joyStick) 634 iJoyStick++; 635 636 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 637 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickSliderMoved(JoyStickState(arg.state, iJoyStick), id); 638 639 return true; 640 } 641 642 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 643 { 644 // use the device to identify which one called the method 616 645 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 617 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 618 activeJoyStickHandlers_[joyStick][i]->sliderMoved(i, arg, id); 619 620 return true; 621 } 622 623 bool InputManager::povMoved(const OIS::JoyStickEvent &arg, int id) 624 { 646 unsigned int iJoyStick = 0; 647 while (joySticks_[iJoyStick] != joyStick) 648 iJoyStick++; 649 650 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 651 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickPovMoved(JoyStickState(arg.state, iJoyStick), id); 652 653 return true; 654 } 655 656 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 657 { 658 // use the device to identify which one called the method 625 659 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 626 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 627 activeJoyStickHandlers_[joyStick][i]->povMoved(i, arg, id); 628 629 return true; 630 } 631 632 bool InputManager::vector3Moved(const OIS::JoyStickEvent &arg, int id) 633 { 634 OIS::JoyStick* joyStick = (OIS::JoyStick*)arg.device; 635 for (unsigned int i = 0; i < activeJoyStickHandlers_[joyStick].size(); i++) 636 activeJoyStickHandlers_[joyStick][i]->vector3Moved(i, arg, id); 660 unsigned int iJoyStick = 0; 661 while (joySticks_[iJoyStick] != joyStick) 662 iJoyStick++; 663 664 for (unsigned int iHandler = 0; iHandler < activeJoyStickHandlers_[iJoyStick].size(); iHandler++) 665 activeJoyStickHandlers_[iJoyStick][iHandler]->joyStickVector3Moved(JoyStickState(arg.state, iJoyStick), id); 637 666 638 667 return true; … … 685 714 int InputManager::numberOfJoySticks() 686 715 { 687 return _getSingleton().joySticks_.size(); 716 return _getSingleton().joySticksSize_; 717 } 718 719 bool InputManager::isKeyDown(KeyCode::Enum key) 720 { 721 if (_getSingleton().keyboard_) 722 return _getSingleton().keyboard_->isKeyDown((OIS::KeyCode)key); 723 else 724 return false; 725 } 726 727 bool InputManager::isModifierDown(KeyboardModifier::Enum modifier) 728 { 729 if (_getSingleton().keyboard_) 730 return isModifierDown(modifier); 731 else 732 return false; 733 } 734 735 const MouseState InputManager::getMouseState() 736 { 737 if (_getSingleton().mouse_) 738 return _getSingleton().mouse_->getMouseState(); 739 else 740 return MouseState(); 741 } 742 743 const JoyStickState InputManager::getJoyStickState(unsigned int ID) 744 { 745 if (ID < _getSingleton().joySticksSize_) 746 return JoyStickState(_getSingleton().joySticks_[ID]->getJoyStickState(), ID); 747 else 748 return JoyStickState(); 688 749 } 689 750 … … 1061 1122 @return False if name or id was not found, true otherwise. 1062 1123 */ 1063 bool InputManager::enableJoyStickHandler(const std::string& name, constint ID)1124 bool InputManager::enableJoyStickHandler(const std::string& name, unsigned int ID) 1064 1125 { 1065 1126 // get handler pointer from the map with all stored handlers … … 1069 1130 1070 1131 // check for existence of the ID 1071 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1072 return false; 1073 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1132 if (ID >= _getSingleton().joySticksSize_) 1133 return false; 1074 1134 1075 1135 // see whether the handler already is in the list 1076 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1077 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1136 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1137 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1078 1138 { 1079 1139 if ((*it) == (*handlerIt).second) … … 1083 1143 } 1084 1144 } 1085 _getSingleton().activeJoyStickHandlers_[ joyStick].push_back((*handlerIt).second);1145 _getSingleton().activeJoyStickHandlers_[ID].push_back((*handlerIt).second); 1086 1146 _getSingleton().stateRequest_ = IS_CUSTOM; 1087 1147 return true; … … 1093 1153 @return False if name or id was not found, true otherwise. 1094 1154 */ 1095 bool InputManager::disableJoyStickHandler(const std::string &name, int ID)1155 bool InputManager::disableJoyStickHandler(const std::string &name, unsigned int ID) 1096 1156 { 1097 1157 // get handler pointer from the map with all stored handlers … … 1101 1161 1102 1162 // check for existence of the ID 1103 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1104 return false; 1105 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1163 if (ID >= _getSingleton().joySticksSize_) 1164 return false; 1106 1165 1107 1166 // look for the handler in the list 1108 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1109 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1167 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1168 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1110 1169 { 1111 1170 if ((*it) == (*handlerIt).second) 1112 1171 { 1113 _getSingleton().activeJoyStickHandlers_[ joyStick].erase(it);1172 _getSingleton().activeJoyStickHandlers_[ID].erase(it); 1114 1173 _getSingleton().stateRequest_ = IS_CUSTOM; 1115 1174 return true; … … 1124 1183 @return False if key handler is not active or doesn't exist, true otherwise. 1125 1184 */ 1126 bool InputManager::isJoyStickHandlerActive(const std::string& name, constint ID)1185 bool InputManager::isJoyStickHandlerActive(const std::string& name, unsigned int ID) 1127 1186 { 1128 1187 // get handler pointer from the map with all stored handlers … … 1132 1191 1133 1192 // check for existence of the ID 1134 if ((unsigned int)ID >= _getSingleton().joySticks_.size()) 1135 return false; 1136 OIS::JoyStick* joyStick = _getSingleton().joySticks_[ID]; 1193 if (ID >= _getSingleton().joySticksSize_) 1194 return false; 1137 1195 1138 1196 // see whether the handler already is in the list 1139 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ joyStick].begin();1140 it != _getSingleton().activeJoyStickHandlers_[ joyStick].end(); it++)1197 for (std::vector<JoyStickHandler*>::iterator it = _getSingleton().activeJoyStickHandlers_[ID].begin(); 1198 it != _getSingleton().activeJoyStickHandlers_[ID].end(); it++) 1141 1199 { 1142 1200 if ((*it) == (*handlerIt).second) -
code/branches/input/src/core/InputManager.h
r1219 r1236 43 43 #include "ois/OIS.h" 44 44 #include "Tickable.h" 45 #include "InputInterfaces.h" 45 46 46 47 namespace orxonox 47 48 { 48 class Mouse : public OIS::Mouse49 {50 };51 52 49 /** 53 50 @brief Captures and distributes mouse and keyboard input. … … 86 83 static void destroyJoySticks(); 87 84 85 static bool isModifierDown(KeyboardModifier::Enum modifier); 86 static bool isKeyDown(KeyCode::Enum key); 87 static const MouseState getMouseState(); 88 static const JoyStickState getJoyStickState(unsigned int ID); 89 88 90 static void setWindowExtents(const int width, const int height); 89 91 … … 108 110 static bool removeJoyStickHandler (const std::string& name); 109 111 static JoyStickHandler* getJoyStickHandler(const std::string& name); 110 static bool enableJoyStickHandler (const std::string& name, const int id); 111 static bool disableJoyStickHandler (const std::string& name, const int id); 112 static bool isJoyStickHandlerActive (const std::string& name, const int id); 113 114 // Temporary solutions. Will be removed soon! 115 static OIS::Mouse* getMouse() { return _getSingleton().mouse_ ; } 116 static OIS::Keyboard* getKeyboard() { return _getSingleton().keyboard_; } 112 static bool enableJoyStickHandler (const std::string& name, unsigned int id); 113 static bool disableJoyStickHandler (const std::string& name, unsigned int id); 114 static bool isJoyStickHandlerActive (const std::string& name, unsigned int id); 117 115 118 116 private: // functions … … 132 130 void _destroyMouse(); 133 131 void _destroyJoySticks(); 134 135 //void _setNumberOfJoysticks(int size);136 132 137 133 void tick(float dt); … … 158 154 OIS::Mouse* mouse_; //!< OIS keyboard 159 155 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 156 unsigned int joySticksSize_; 160 157 161 158 InputState state_; 162 159 InputState stateRequest_; 160 unsigned int keyboardModifiers_; 163 161 164 162 std::map<std::string, KeyHandler*> keyHandlers_; … … 168 166 std::vector<KeyHandler*> activeKeyHandlers_; 169 167 std::vector<MouseHandler*> activeMouseHandlers_; 170 std:: map< OIS::JoyStick*,std::vector<JoyStickHandler*> > activeJoyStickHandlers_;168 std::vector<std::vector<JoyStickHandler*> > activeJoyStickHandlers_; 171 169 172 std:: list<OIS::KeyCode>keysDown_;173 std:: list<OIS::MouseButtonID>mouseButtonsDown_;174 std:: map< OIS::JoyStick*, std::list<int> >joyStickButtonsDown_;170 std::vector<Key> keysDown_; 171 std::vector<MouseButton::Enum> mouseButtonsDown_; 172 std::vector<std::vector<int> > joyStickButtonsDown_; 175 173 176 174 }; 175 177 176 } 178 177
Note: See TracChangeset
for help on using the changeset viewer.