Changeset 7861 for code/trunk/src/libraries/core/input/KeyBinder.cc
- Timestamp:
- Feb 12, 2011, 11:54:07 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/input/KeyBinder.cc
r7859 r7861 385 385 } 386 386 387 /** 388 @brief Changes the keybind mode of a given console command. 389 */ 390 void KeyBinder::changeMode(ConsoleCommand* command, KeybindMode::Value new_mode) 391 { 392 // iterate over all buttons 393 for (std::map<std::string, Button*>::iterator it = this->allButtons_.begin(); it != this->allButtons_.end(); ++it) 394 { 395 Button* button = it->second; 396 397 // iterate over all modes 398 for (size_t mode_index = 0; mode_index < 3; ++mode_index) 399 { 400 if (mode_index == new_mode) // skip commands that are already in the desired mode 401 continue; 402 403 // iterate over all commands of the given mode at the given button 404 for (size_t command_index = 0; command_index < button->nCommands_[mode_index]; ++command_index) 405 { 406 CommandEvaluation* evaluation = button->commands_[mode_index][command_index]->getEvaluation(); 407 408 // compare the command 409 if (evaluation && evaluation->getConsoleCommand() == command) 410 { 411 // increase array of new mode 412 BaseCommand** array_new_mode = new BaseCommand*[button->nCommands_[new_mode] + 1]; 413 // copy array content 414 for (size_t c = 0; c < button->nCommands_[new_mode]; ++c) 415 array_new_mode[c] = button->commands_[new_mode][c]; 416 // insert changed command at the end 417 array_new_mode[button->nCommands_[new_mode]] = button->commands_[mode_index][command_index]; 418 // delete old array 419 delete[] button->commands_[new_mode]; 420 // assign new array 421 button->commands_[new_mode] = array_new_mode; 422 // increase counter 423 button->nCommands_[new_mode]++; 424 425 // erase command from old array 426 for (size_t c = command_index; c < button->nCommands_[mode_index] - 1; ++c) 427 button->commands_[mode_index][c] = button->commands_[mode_index][c + 1]; 428 // decrease counter 429 button->nCommands_[mode_index]--; 430 // note: we don't replace the old array - it's not one element too large, but no one cares since nCommands_ defines the size 431 432 // decrement the index since we shifted the array and continue searching for more occurrences of the command 433 command_index--; 434 } 435 } 436 } 437 } 438 } 439 387 440 void KeyBinder::resetJoyStickAxes() 388 441 {
Note: See TracChangeset
for help on using the changeset viewer.