Changeset 5864 for code/branches/core5/src/libraries/core/input
- Timestamp:
- Oct 3, 2009, 5:36:10 PM (15 years ago)
- Location:
- code/branches/core5/src/libraries/core/input
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/input/KeyDetector.cc
r5738 r5864 29 29 #include "KeyDetector.h" 30 30 31 #include " util/Debug.h"31 #include "core/ConsoleCommand.h" 32 32 #include "core/CoreIncludes.h" 33 33 #include "Button.h" … … 35 35 namespace orxonox 36 36 { 37 /** 38 @brief 39 Constructor 40 */ 37 std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed"; 38 KeyDetector* KeyDetector::singletonPtr_s = 0; 39 41 40 KeyDetector::KeyDetector() 41 : KeyBinder("") 42 42 { 43 43 RegisterObject(KeyDetector); 44 45 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback, this), callbackCommand_s)); 46 this->assignCommands(); 44 47 } 45 48 46 /** 47 @brief 48 Destructor 49 */ 50 KeyDetector::~KeyDetector() 49 void KeyDetector::assignCommands() 51 50 { 52 } 53 54 /** 55 @brief 56 Assigns all the buttons 'command' plus the button's name. 57 */ 58 void KeyDetector::setCallbackCommand(const std::string& command) 59 { 60 callbackCommand_ = command; 51 // Assign every button/axis the same command, but with its name as argument 61 52 clearBindings(); 62 53 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 63 54 { 64 it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;55 it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_; 65 56 it->second->parse(); 66 57 } 58 } 59 60 void KeyDetector::callback(const std::string& name) 61 { 62 // Call the registered function 63 if (this->callbackFunction_) 64 (*this->callbackFunction_)(name); 67 65 } 68 66 … … 70 68 { 71 69 KeyBinder::JoyStickQuantityChanged(joyStickList); 72 if (!callbackCommand_.empty()) 73 setCallbackCommand(callbackCommand_); 70 this->assignCommands(); 74 71 } 75 72 } -
code/branches/core5/src/libraries/core/input/KeyDetector.h
r5738 r5864 32 32 #include "InputPrereqs.h" 33 33 34 #include <string>34 #include "util/Singleton.h" 35 35 #include "KeyBinder.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _CoreExport KeyDetector : public KeyBinder 39 class _CoreExport KeyDetector : public KeyBinder, public Singleton<KeyDetector> 40 40 { 41 friend class Singleton<KeyDetector>; 42 41 43 public: 42 44 KeyDetector(); 43 ~KeyDetector() ;44 void setCallbackCommand(const std::string& command); 45 void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);45 ~KeyDetector() { } 46 47 void setCallback(Functor* function) { this->callbackFunction_ = function; } 46 48 47 49 private: 48 std::string callbackCommand_; 50 KeyDetector(const KeyDetector&); 51 52 void callback(const std::string& name); 53 void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList); 54 void assignCommands(); 55 56 Functor* callbackFunction_; 57 static std::string callbackCommand_s; 58 static KeyDetector* singletonPtr_s; 49 59 }; 50 60 }
Note: See TracChangeset
for help on using the changeset viewer.