Changeset 6281 for code/branches/presentation2/src/libraries/core/input
- Timestamp:
- Dec 9, 2009, 12:43:12 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/core/input
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc
r6266 r6281 29 29 #include "KeyBinderManager.h" 30 30 31 #include <CEGUIWindow.h> 32 31 33 #include "util/Debug.h" 32 34 #include "util/Exception.h" … … 37 39 #include "InputManager.h" 38 40 #include "KeyDetector.h" 39 40 #include <CEGUIWindow.h>41 41 42 42 namespace orxonox … … 49 49 , bBinding_(false) 50 50 { 51 this->callbackFunction_ = createFunctor(&KeyBinderManager::callback, this);52 53 51 RegisterObject(KeyBinderManager); 54 52 this->setConfigValues(); … … 69 67 for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it) 70 68 delete it->second; 71 delete this->callbackFunction_;72 69 } 73 70 … … 152 149 { 153 150 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 154 KeyDetector::getInstance().setCallback( callbackFunction_);151 KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this))); 155 152 InputManager::getInstance().enterState("detector"); 156 153 this->command_ = command; … … 162 159 163 160 // Gets called by the KeyDetector (registered with a Functor) 164 void KeyBinderManager:: callback(const std::string& keyName)161 void KeyBinderManager::keybindKeyPressed(const std::string& keyName) 165 162 { 166 163 if (this->bBinding_) … … 169 166 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 170 167 InputManager::getInstance().leaveState("detector"); 168 // inform whatever was calling the command 169 if (this->callbackFunction_) 170 (*this->callbackFunction_)(); 171 171 this->bBinding_ = false; 172 172 } -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h
r6280 r6281 34 34 #include <map> 35 35 #include <string> 36 #include <boost/shared_ptr.hpp> 37 #include <CEGUIForwardRefs.h> 38 36 39 #include "util/Singleton.h" 37 40 #include "core/OrxonoxClass.h" 38 39 #include <CEGUIForwardRefs.h>40 41 41 42 namespace orxonox //tolua_export … … 99 100 inline void tkeybind(const std::string& command) 100 101 { this->keybindInternal(command, true); } 102 inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export 101 103 102 104 private: 103 105 KeyBinderManager(const KeyBinderManager&); 104 106 void keybindInternal(const std::string& command, bool bTemporary); 105 void callback(const std::string& keyName);107 void keybindKeyPressed(const std::string& keyName); 106 108 void defaultFilenameChanged(); 107 109 … … 113 115 114 116 // keybind command related 115 Functor* callbackFunction_;//! Function to be called when key was pressed after "keybind" command117 shared_ptr<Functor> callbackFunction_; //! Function to be called when key was pressed after "keybind" command 116 118 bool bBinding_; //! Tells whether a key binding process is active 117 119 bool bTemporary_; //! Stores tkeybind/keybind value -
code/branches/presentation2/src/libraries/core/input/KeyDetector.h
r5929 r6281 32 32 #include "InputPrereqs.h" 33 33 34 #include <boost/shared_ptr.hpp> 34 35 #include "util/Singleton.h" 35 36 #include "KeyBinder.h" … … 45 46 ~KeyDetector(); 46 47 47 void setCallback( Functor*function) { this->callbackFunction_ = function; }48 void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; } 48 49 49 50 private: … … 54 55 void assignCommands(); 55 56 56 Functor*callbackFunction_;57 shared_ptr<Functor> callbackFunction_; 57 58 InputState* inputState_; 58 59 static std::string callbackCommand_s;
Note: See TracChangeset
for help on using the changeset viewer.