Changeset 5929 for code/trunk/src/libraries/core/input/KeyDetector.cc
- Timestamp:
- Oct 12, 2009, 8:20:07 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core5 (added) merged: 5768-5769,5772,5775-5780,5783-5785,5791-5792,5795-5807,5809-5814,5816-5832,5836-5839,5842-5853,5855-5899,5904-5922,5924-5928
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/input/KeyDetector.cc
r5781 r5929 29 29 #include "KeyDetector.h" 30 30 31 #include " util/Debug.h"31 #include "core/ConsoleCommand.h" 32 32 #include "core/CoreIncludes.h" 33 #include "core/ScopedSingletonManager.h" 33 34 #include "Button.h" 35 #include "InputManager.h" 36 #include "InputState.h" 34 37 35 38 namespace orxonox 36 39 { 37 /**38 @brief39 Constructor40 */ 40 std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed"; 41 KeyDetector* KeyDetector::singletonPtr_s = 0; 42 ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false); 43 41 44 KeyDetector::KeyDetector() 45 : KeyBinder("") 42 46 { 43 47 RegisterObject(KeyDetector); 48 49 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback, this), callbackCommand_s)); 50 this->assignCommands(); 51 52 inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector); 53 // Create a callback to avoid buttonHeld events after the key has been detected 54 inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance())); 55 inputState_->setHandler(this); 44 56 } 45 57 46 /**47 @brief48 Destructor49 */50 58 KeyDetector::~KeyDetector() 51 59 { 60 inputState_->setHandler(NULL); 61 InputManager::getInstance().destroyState("detector"); 52 62 } 53 63 54 /** 55 @brief 56 Assigns all the buttons 'command' plus the button's name. 57 */ 58 void KeyDetector::setCallbackCommand(const std::string& command) 64 void KeyDetector::assignCommands() 59 65 { 60 callbackCommand_ = command;66 // Assign every button/axis the same command, but with its name as argument 61 67 clearBindings(); 62 68 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 63 69 { 64 it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;70 it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_; 65 71 it->second->parse(); 66 72 } 73 } 74 75 void KeyDetector::callback(const std::string& name) 76 { 77 // Call the registered function 78 if (this->callbackFunction_) 79 (*this->callbackFunction_)(name); 67 80 } 68 81 … … 70 83 { 71 84 KeyBinder::JoyStickQuantityChanged(joyStickList); 72 if (!callbackCommand_.empty()) 73 setCallbackCommand(callbackCommand_); 85 this->assignCommands(); 74 86 } 75 87 }
Note: See TracChangeset
for help on using the changeset viewer.