Changeset 6311 for code/branches/presentation2/src/libraries/core/input
- Timestamp:
- Dec 9, 2009, 11:17:14 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries/core/input
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/input/KeyBinder.cc
r6214 r6311 29 29 #include "KeyBinder.h" 30 30 31 #include <algorithm> 32 #include <sstream> 31 33 #include "util/Convert.h" 32 34 #include "util/Debug.h" … … 256 258 { 257 259 it->second->readConfigValue(this->configFile_); 258 this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;260 addButtonToCommand(it->second->bindingString_, it->second); 259 261 } 260 262 … … 267 269 if (it != allButtons_.end()) 268 270 { 271 addButtonToCommand(binding, it->second); 269 272 if (bTemporary) 270 273 it->second->configContainer_->tset(binding); … … 272 275 it->second->configContainer_->set(binding); 273 276 it->second->configContainer_->getValue(&(it->second->bindingString_), it->second); 274 this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;275 277 return true; 276 278 } … … 282 284 } 283 285 284 /** 285 @brief 286 Return the key name for a specific command 286 void KeyBinder::addButtonToCommand(std::string command, Button* button) 287 { 288 std::ostringstream stream; 289 stream << button->groupName_ << "." << button->name_; 290 291 std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_]; 292 std::vector<std::string>::iterator it = std::find(oldKeynames.begin(), oldKeynames.end(), stream.str()); 293 if(it != oldKeynames.end()) 294 { 295 oldKeynames.erase(it); 296 } 297 298 if(command != "") 299 { 300 std::vector<std::string>& keynames = this->allCommands_[command]; 301 if( std::find(keynames.begin(), keynames.end(), stream.str()) == keynames.end()) 302 { 303 this->allCommands_[command].push_back(stream.str()); 304 } 305 } 306 } 307 308 /** 309 @brief 310 Return the first key name for a specific command 287 311 */ 288 312 std::string KeyBinder::getBinding(std::string commandName) 289 313 { 290 COUT(0)<< commandName << endl;291 314 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 292 315 { 293 std::string keyname = this->allCommands_[commandName]; 294 // while(keyname.find(".")!=keyname.npos) 295 // keyname.replace(1, keyname.find("."), " "); 296 COUT(0) << keyname << endl; 297 return keyname; 298 } 299 else 316 std::vector<std::string>& keynames = this->allCommands_[commandName]; 317 return keynames.front(); 318 } 319 320 return ""; 321 } 322 323 /** 324 @brief 325 Return the key name for a specific command at a given index. 326 @param commandName 327 The command name the key name is returned for. 328 @param index 329 The index at which the key name is returned for. 330 */ 331 std::string KeyBinder::getBinding(std::string commandName, unsigned int index) 332 { 333 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 334 { 335 std::vector<std::string>& keynames = this->allCommands_[commandName]; 336 if(index < keynames.size()) 337 { 338 return keynames[index]; 339 } 340 300 341 return ""; 342 } 343 344 return ""; 345 } 346 347 /** 348 @brief 349 Get the number of different key bindings of a specific command. 350 @param commandName 351 The command. 352 */ 353 unsigned int KeyBinder::getNumberOfBindings(std::string commandName) 354 { 355 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 356 { 357 std::vector<std::string>& keynames = this->allCommands_[commandName]; 358 return keynames.size(); 359 } 360 361 return 0; 301 362 } 302 363 -
code/branches/presentation2/src/libraries/core/input/KeyBinder.h
r6214 r6311 35 35 #include <string> 36 36 #include <vector> 37 #include <map> 37 38 #include <boost/shared_ptr.hpp> 38 39 … … 66 67 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 67 68 std::string getBinding(std::string commandName); //tolua_export 69 std::string getBinding(std::string commandName, unsigned int index); //tolua_export 70 unsigned int getNumberOfBindings(std::string commandName); //tolua_export 71 68 72 const std::string& getBindingsFilename() 69 73 { return this->filename_; } … … 135 139 std::vector<HalfAxis*> allHalfAxes_; 136 140 //! Maps input commands to all Button names, including half axes 137 std::map< std::string, std::string> allCommands_;141 std::map< std::string, std::vector<std::string> > allCommands_; 138 142 139 143 /** … … 156 160 157 161 private: 162 void addButtonToCommand(std::string command, Button* button); 163 158 164 //##### ConfigValues ##### 159 165 //! Whether to filter small value analog input -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc
r6281 r6311 57 57 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind")) 58 58 .defaultValues(""); 59 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind")) 60 .defaultValues(""); 61 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind")) 62 .defaultValues(""); 59 63 60 64 // Load default key binder … … 89 93 else 90 94 this->bDefaultFileLoaded_ = false; 95 } 96 97 inline void KeyBinderManager::unbind(const std::string& binding) 98 { 99 this->currentBinder_->setBinding("", binding, false); 100 } 101 102 inline void KeyBinderManager::tunbind(const std::string& binding) 103 { 104 this->currentBinder_->setBinding("", binding, true); 91 105 } 92 106 … … 163 177 if (this->bBinding_) 164 178 { 165 COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl; 166 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 179 if (keyName == "Keys.KeyEscape") 180 { 181 COUT(0) << "Keybinding aborted." << std::endl; 182 } 183 else 184 { 185 COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl; 186 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 187 } 167 188 InputManager::getInstance().leaveState("detector"); 168 189 // inform whatever was calling the command -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h
r6281 r6311 100 100 inline void tkeybind(const std::string& command) 101 101 { this->keybindInternal(command, true); } 102 void unbind(const std::string& binding); //tolua_export 103 void tunbind(const std::string& binding); 102 104 inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export 103 105
Note: See TracChangeset
for help on using the changeset viewer.