Changeset 3274 for code/branches/core4/src/core/input/InputManager.cc
- Timestamp:
- Jul 12, 2009, 4:12:04 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core4/src/core/input/InputManager.cc
r3272 r3274 50 50 #include "core/ConsoleCommand.h" 51 51 #include "core/CommandLine.h" 52 #include "core/Functor.h" 52 53 53 54 #include "InputBuffer.h" 54 55 #include "KeyDetector.h" 56 #include "InputHandler.h" 55 57 #include "InputState.h" 56 #include "SimpleInputState.h" 57 #include "JoyStickDeviceNumberListener.h" 58 #include "JoyStickQuantityListener.h" 58 59 #include "JoyStick.h" 60 #include "Mouse.h" 61 #include "Keyboard.h" 59 62 60 63 // HACK (include this as last, X11 seems to define some macros...) … … 73 76 SetCommandLineSwitch(keyboard_no_grab).information("Whether not to exclusively grab the keyboard"); 74 77 75 EmptyHandler InputManager::EMPTY_HANDLER;78 InputHandler InputHandler::EMPTY; 76 79 InputManager* InputManager::singletonRef_s = 0; 77 78 using namespace InputDevice;79 80 80 81 /** … … 109 110 InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight) 110 111 : inputSystem_(0) 111 , keyboard_(0) 112 , mouse_(0) 113 , devicesNum_(0) 112 , devices_(2) 114 113 , windowHnd_(0) 115 114 , internalState_(Uninitialised) … … 117 116 , keyDetector_(0) 118 117 , calibratorCallbackBuffer_(0) 119 , keyboardModifiers_(0)120 118 { 121 119 RegisterRootObject(InputManager); … … 182 180 #endif 183 181 182 // TODO: clean this up 184 183 try 185 184 { … … 199 198 } 200 199 200 // TODO: Remove the two parameters 201 201 _initialiseMouse(windowWidth, windowHeight); 202 202 … … 220 220 221 221 // Lowest priority empty InputState 222 stateEmpty_ = createInputState <SimpleInputState>("empty", false, false, InputStatePriority::Empty);223 stateEmpty_->setHandler(& EMPTY_HANDLER);222 stateEmpty_ = createInputState("empty", false, false, InputStatePriority::Empty); 223 stateEmpty_->setHandler(&InputHandler::EMPTY); 224 224 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; 225 225 226 226 // KeyDetector to evaluate a pressed key's name 227 SimpleInputState* detector = createInputState<SimpleInputState>("detector", false, false, InputStatePriority::Detector); 227 InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector); 228 FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers); 229 bufferFunctor->setObject(this); 230 detector->setLeaveFunctor(bufferFunctor); 228 231 keyDetector_ = new KeyDetector(); 229 232 detector->setHandler(keyDetector_); 230 233 231 234 // Joy stick calibration helper callback 232 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", false, false, InputStatePriority::Calibrator);233 calibrator->setHandler(& EMPTY_HANDLER);235 InputState* calibrator = createInputState("calibrator", false, false, InputStatePriority::Calibrator); 236 calibrator->setHandler(&InputHandler::EMPTY); 234 237 calibratorCallbackBuffer_ = new InputBuffer(); 235 calibratorCallbackBuffer_->registerListener(this, &InputManager::_ completeCalibration, '\r', true);238 calibratorCallbackBuffer_->registerListener(this, &InputManager::_stopCalibration, '\r', true); 236 239 calibrator->setKeyHandler(calibratorCallbackBuffer_); 237 240 … … 246 249 } 247 250 248 /**249 @brief250 Creates a keyboard and sets the event handler.251 @return252 False if keyboard stays uninitialised, true otherwise.253 */254 251 void InputManager::_initialiseKeyboard() 255 252 { 256 if (keyboard_ != 0) 257 { 258 CCOUT(2) << "Warning: Keyboard already initialised, skipping." << std::endl; 259 return; 260 } 253 assert(devices_[InputDeviceEnumerator::Keyboard] == 0); 261 254 if (inputSystem_->getNumberOfDevices(OIS::OISKeyboard) > 0) 262 { 263 keyboard_ = (OIS::Keyboard*)inputSystem_->createInputObject(OIS::OISKeyboard, true); 264 // register our listener in OIS. 265 keyboard_->setEventCallback(this); 266 // note: OIS will not detect keys that have already been down when the keyboard was created. 267 CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl; 268 } 255 devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard); 269 256 else 270 {271 257 ThrowException(InitialisationFailed, "InputManager: No keyboard found, cannot proceed!"); 272 } 273 } 274 275 /** 276 @brief 277 Creates a mouse and sets the event handler. 278 @return 279 False if mouse stays uninitialised, true otherwise. 280 */ 258 } 259 281 260 void InputManager::_initialiseMouse(unsigned int windowWidth, unsigned int windowHeight) 282 261 { 283 if (mouse_ != 0) 284 { 285 CCOUT(2) << "Warning: Mouse already initialised, skipping." << std::endl; 286 return; 287 } 288 try 289 { 290 if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) 291 { 292 mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true)); 293 // register our listener in OIS. 294 mouse_->setEventCallback(this); 295 CCOUT(ORX_DEBUG) << "Created OIS mouse" << std::endl; 296 297 // Set mouse region 298 setWindowExtents(windowWidth, windowHeight); 299 } 300 else 301 { 302 CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl; 303 } 304 } 305 catch (OIS::Exception ex) 306 { 307 CCOUT(ORX_WARNING) << "Warning: Failed to create an OIS mouse\n" 308 << "OIS error message: \"" << ex.eText << "\"\n Proceeding without mouse support." << std::endl; 309 mouse_ = 0; 310 } 262 assert(devices_[InputDeviceEnumerator::Mouse] == 0); 263 if (inputSystem_->getNumberOfDevices(OIS::OISMouse) > 0) 264 { 265 try 266 { 267 devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, windowWidth, windowHeight); 268 } 269 catch (const OIS::Exception& ex) 270 { 271 CCOUT(2) << "Warning: Failed to create Mouse:" << ex.eText << std::endl 272 << "Proceeding without mouse support." << std::endl; 273 } 274 } 275 else 276 CCOUT(ORX_WARNING) << "Warning: No mouse found! Proceeding without mouse support." << std::endl; 311 277 } 312 278 … … 319 285 void InputManager::_initialiseJoySticks() 320 286 { 321 if (!this->joySticks_.empty()) 322 { 323 CCOUT(2) << "Warning: Joy sticks already initialised, skipping." << std::endl; 324 return; 325 } 326 327 devicesNum_ = 2 + inputSystem_->getNumberOfDevices(OIS::OISJoyStick); 328 // state management 329 activeStatesTriggered_.resize(devicesNum_); 287 assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick); 330 288 331 289 for (int i = 0; i < inputSystem_->getNumberOfDevices(OIS::OISJoyStick); i++) … … 333 291 try 334 292 { 335 joySticks_.push_back(new JoyStick(activeStatesTriggered_[2 + i],i));293 devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i)); 336 294 } 337 295 catch (std::exception ex) … … 342 300 343 301 // inform all JoyStick Device Number Listeners 344 for (ObjectList<JoyStick DeviceNumberListener>::iterator it = ObjectList<JoyStickDeviceNumberListener>::begin(); it; ++it)345 it->JoyStick DeviceNumberChanged(joySticks_.size());302 for (ObjectList<JoyStickQuantityListener>::iterator it = ObjectList<JoyStickQuantityListener>::begin(); it; ++it) 303 it->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick); 346 304 } 347 305 348 306 void InputManager::_startCalibration() 349 307 { 350 BOOST_FOREACH( JoyStick* stick, joySticks_)351 stick->startCalibration();308 BOOST_FOREACH(InputDevice* device, devices_) 309 device->startCalibration(); 352 310 353 311 getInstance().internalState_ |= Calibrating; … … 355 313 } 356 314 357 void InputManager::_ completeCalibration()358 { 359 BOOST_FOREACH( JoyStick* stick, joySticks_)360 stick->stopCalibration();315 void InputManager::_stopCalibration() 316 { 317 BOOST_FOREACH(InputDevice* device, devices_) 318 device->stopCalibration(); 361 319 362 320 // restore old input state 363 321 requestLeaveState("calibrator"); 364 322 internalState_ &= ~Calibrating; 323 // Clear buffers to prevent button hold events 324 this->clearBuffers(); 365 325 } 366 326 … … 374 334 Destroys all the created input devices and states. 375 335 */ 336 // TODO: export this to be used with reload() 376 337 InputManager::~InputManager() 377 338 { … … 379 340 { 380 341 CCOUT(3) << "Destroying ..." << std::endl; 381 382 // kick all active states 'nicely'383 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();384 rit != activeStates_.rend(); ++rit)385 {386 (*rit).second->onLeave();387 }388 342 389 343 // Destroy calibrator helper handler and state … … 401 355 402 356 // destroy the devices 403 _destroyKeyboard(); 404 _destroyMouse(); 405 _destroyJoySticks(); 357 BOOST_FOREACH(InputDevice*& device, devices_) 358 { 359 std::string className = device->getClassName(); 360 try 361 { 362 if (device) 363 delete device; 364 device = 0; 365 CCOUT(4) << className << " destroyed." << std::endl; 366 } 367 catch (...) 368 { 369 CCOUT(1) << className << " destruction failed! Potential resource leak!" << std::endl; 370 } 371 } 372 devices_.resize(InputDeviceEnumerator::FirstJoyStick); 406 373 407 374 try … … 416 383 417 384 singletonRef_s = 0; 418 }419 420 /**421 @brief422 Destroys the keyboard and sets it to 0.423 */424 void InputManager::_destroyKeyboard()425 {426 assert(inputSystem_);427 try428 {429 if (keyboard_)430 inputSystem_->destroyInputObject(keyboard_);431 keyboard_ = 0;432 CCOUT(4) << "Keyboard destroyed." << std::endl;433 }434 catch (...)435 {436 CCOUT(1) << "Keyboard destruction failed! Potential resource leak!" << std::endl;437 }438 }439 440 /**441 @brief442 Destroys the mouse and sets it to 0.443 */444 void InputManager::_destroyMouse()445 {446 assert(inputSystem_);447 try448 {449 if (mouse_)450 inputSystem_->destroyInputObject(mouse_);451 mouse_ = 0;452 CCOUT(4) << "Mouse destroyed." << std::endl;453 }454 catch (...)455 {456 CCOUT(1) << "Mouse destruction failed! Potential resource leak!" << std::endl;457 }458 }459 460 /**461 @brief462 Destroys all the joy sticks and resizes the lists to 0.463 */464 void InputManager::_destroyJoySticks()465 {466 assert(inputSystem_);467 while (!joySticks_.empty())468 {469 try470 {471 delete joySticks_.back();472 }473 catch (...)474 {475 CCOUT(1) << "Joy stick destruction failed! Potential resource leak!" << std::endl;476 }477 joySticks_.pop_back();478 devicesNum_ = 2;479 }480 CCOUT(4) << "Joy sticks destroyed." << std::endl;481 385 } 482 386 … … 539 443 540 444 // Save mouse clipping size 541 int mouseWidth = mouse_->getMouseState().width;542 int mouseHeight = mouse_->getMouseState().height;445 int mouseWidth = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingWidth(); 446 int mouseHeight = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingHeight(); 543 447 544 448 internalState_ &= ~OISReady; 545 449 546 450 // destroy the devices 547 _destroyKeyboard(); 548 _destroyMouse(); 549 _destroyJoySticks(); 451 // destroy the devices 452 BOOST_FOREACH(InputDevice*& device, devices_) 453 { 454 try 455 { 456 if (device) 457 delete device; 458 device = 0; 459 CCOUT(4) << device->getClassName() << " destroyed." << std::endl; 460 } 461 catch (...) 462 { 463 CCOUT(1) << device->getClassName() << " destruction failed! Potential resource leak!" << std::endl; 464 } 465 } 466 devices_.resize(InputDeviceEnumerator::FirstJoyStick); 550 467 551 468 OIS::InputManager::destroyInputSystem(inputSystem_); … … 592 509 it != stateLeaveRequests_.end(); ++it) 593 510 { 594 (*it)-> onLeave();511 (*it)->left(); 595 512 // just to be sure that the state actually is registered 596 513 assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end()); … … 631 548 activeStates_[(*it)->getPriority()] = (*it); 632 549 _updateActiveStates(); 633 (*it)-> onEnter();550 (*it)->entered(); 634 551 } 635 552 stateEnterRequests_.clear(); … … 647 564 } 648 565 649 // check whether a state has changed its EMPTY _HANDLERsituation566 // check whether a state has changed its EMPTY situation 650 567 bool bUpdateRequired = false; 651 568 for (std::map<int, InputState*>::iterator it = activeStates_.begin(); it != activeStates_.end(); ++it) 652 569 { 653 if (it->second->ha ndlersChanged())654 { 655 it->second->reset HandlersChanged();570 if (it->second->hasExpired()) 571 { 572 it->second->resetExpiration(); 656 573 bUpdateRequired = true; 657 574 } … … 664 581 665 582 // Capture all the input. This calls the event handlers in InputManager. 666 if (keyboard_) 667 keyboard_->capture(); 668 if (mouse_) 669 mouse_->capture(); 670 BOOST_FOREACH(JoyStick* stick, joySticks_) 671 stick->capture(); 583 BOOST_FOREACH(InputDevice* device, devices_) 584 device->update(time); 672 585 673 586 if (!(internalState_ & Calibrating)) 674 587 { 675 // call all the handlers for the held key events 676 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 677 { 678 KeyEvent kEvt(keysDown_[iKey], keyboardModifiers_); 679 680 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 681 activeStatesTriggered_[Keyboard][iState]->keyHeld(kEvt); 682 } 683 684 // call all the handlers for the held mouse button events 685 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 686 { 687 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 688 activeStatesTriggered_[Mouse][iState]->mouseButtonHeld(mouseButtonsDown_[iButton]); 689 } 690 691 // update the handlers for each active handler 692 for (unsigned int i = 0; i < devicesNum_; ++i) 693 { 694 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState) 695 activeStatesTriggered_[i][iState]->updateInput(time.getDeltaTime(), i); 696 } 697 698 // update the handler with a general tick afterwards 588 // update the states with a general tick afterwards 699 589 for (unsigned int i = 0; i < activeStatesTicked_.size(); ++i) 700 activeStatesTicked_[i]->update Input(time.getDeltaTime());590 activeStatesTicked_[i]->update(time.getDeltaTime()); 701 591 } 702 592 … … 711 601 void InputManager::_updateActiveStates() 712 602 { 713 for (unsigned int i = 0; i < devicesNum_; ++i) 714 { 603 // temporary resize 604 for (unsigned int i = 0; i < devices_.size(); ++i) 605 { 606 std::vector<InputState*>& states = devices_[i]->getStateListRef(); 715 607 bool occupied = false; 716 activeStatesTriggered_[i].clear();717 for (std::map<int, InputState*>:: const_reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit)608 states.clear(); 609 for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin(); rit != activeStates_.rend(); ++rit) 718 610 { 719 611 if (rit->second->isInputDeviceEnabled(i) && (!occupied || rit->second->bAlwaysGetsInput_)) 720 612 { 721 activeStatesTriggered_[i].push_back(rit->second);613 states.push_back(rit->second); 722 614 if (!rit->second->bTransparent_) 723 615 occupied = true; … … 729 621 // Using a std::set to avoid duplicates 730 622 std::set<InputState*> tempSet; 731 for (unsigned int i = 0; i < devices Num_; ++i)732 for (unsigned int iState = 0; iState < activeStatesTriggered_[i].size(); ++iState)733 tempSet.insert( activeStatesTriggered_[i][iState]);623 for (unsigned int i = 0; i < devices_.size(); ++i) 624 for (unsigned int iState = 0; iState < devices_[i]->getStateListRef().size(); ++iState) 625 tempSet.insert(devices_[i]->getStateListRef()[iState]); 734 626 735 627 // copy the content of the std::set back to the actual vector … … 737 629 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) 738 630 activeStatesTicked_.push_back(*it); 739 740 this->mouseButtonsDown_.clear();741 631 } 742 632 … … 747 637 void InputManager::clearBuffers() 748 638 { 749 keysDown_.clear(); 750 keyboardModifiers_ = 0; 751 mouseButtonsDown_.clear(); 752 BOOST_FOREACH(JoyStick* stick, joySticks_) 753 stick->clearBuffer(); 754 } 755 756 757 // ############################################################ 758 // ##### OIS events ##### 759 // ########## ########## 760 // ############################################################ 761 762 // ###### Key Events ###### 763 764 /** 765 @brief 766 Event handler for the keyPressed Event. 767 @param e 768 Event information 769 */ 770 bool InputManager::keyPressed(const OIS::KeyEvent &e) 771 { 772 // check whether the key already is in the list (can happen when focus was lost) 773 unsigned int iKey = 0; 774 while (iKey < keysDown_.size() && keysDown_[iKey].key != (KeyCode::ByEnum)e.key) 775 iKey++; 776 if (iKey == keysDown_.size()) 777 keysDown_.push_back(Key(e)); 778 else 779 { 780 // This happens when XAutoRepeat is set under linux. The KeyPressed event gets then sent 781 // continuously. 782 return true; 783 } 784 785 // update modifiers 786 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 787 keyboardModifiers_ |= KeyboardModifier::Alt; // alt key 788 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 789 keyboardModifiers_ |= KeyboardModifier::Ctrl; // ctrl key 790 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 791 keyboardModifiers_ |= KeyboardModifier::Shift; // shift key 792 793 KeyEvent kEvt(e, keyboardModifiers_); 794 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 795 activeStatesTriggered_[Keyboard][iState]->keyPressed(kEvt); 796 797 return true; 798 } 799 800 /** 801 @brief 802 Event handler for the keyReleased Event. 803 @param e 804 Event information 805 */ 806 bool InputManager::keyReleased(const OIS::KeyEvent &e) 807 { 808 // remove the key from the keysDown_ list 809 for (unsigned int iKey = 0; iKey < keysDown_.size(); iKey++) 810 { 811 if (keysDown_[iKey].key == (KeyCode::ByEnum)e.key) 812 { 813 keysDown_.erase(keysDown_.begin() + iKey); 814 break; 815 } 816 } 817 818 // update modifiers 819 if(e.key == OIS::KC_RMENU || e.key == OIS::KC_LMENU) 820 keyboardModifiers_ &= ~KeyboardModifier::Alt; // alt key 821 if(e.key == OIS::KC_RCONTROL || e.key == OIS::KC_LCONTROL) 822 keyboardModifiers_ &= ~KeyboardModifier::Ctrl; // ctrl key 823 if(e.key == OIS::KC_RSHIFT || e.key == OIS::KC_LSHIFT) 824 keyboardModifiers_ &= ~KeyboardModifier::Shift; // shift key 825 826 KeyEvent kEvt(e, keyboardModifiers_); 827 for (unsigned int iState = 0; iState < activeStatesTriggered_[Keyboard].size(); ++iState) 828 activeStatesTriggered_[Keyboard][iState]->keyReleased(kEvt); 829 830 return true; 831 } 832 833 834 // ###### Mouse Events ###### 835 836 /** 837 @brief 838 Event handler for the mouseMoved Event. 839 @param e 840 Event information 841 */ 842 bool InputManager::mouseMoved(const OIS::MouseEvent &e) 843 { 844 // check for actual moved event 845 if (e.state.X.rel != 0 || e.state.Y.rel != 0) 846 { 847 IntVector2 abs(e.state.X.abs, e.state.Y.abs); 848 IntVector2 rel(e.state.X.rel, e.state.Y.rel); 849 IntVector2 clippingSize(e.state.width, e.state.height); 850 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 851 activeStatesTriggered_[Mouse][iState]->mouseMoved(abs, rel, clippingSize); 852 } 853 854 // check for mouse scrolled event 855 if (e.state.Z.rel != 0) 856 { 857 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 858 activeStatesTriggered_[Mouse][iState]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); 859 } 860 861 return true; 862 } 863 864 /** 865 @brief 866 Event handler for the mousePressed Event. 867 @param e 868 Event information 869 @param id 870 The ID of the mouse button 871 */ 872 bool InputManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id) 873 { 874 // check whether the button already is in the list (can happen when focus was lost) 875 unsigned int iButton = 0; 876 while (iButton < mouseButtonsDown_.size() && mouseButtonsDown_[iButton] != (MouseButtonCode::ByEnum)id) 877 iButton++; 878 if (iButton == mouseButtonsDown_.size()) 879 mouseButtonsDown_.push_back((MouseButtonCode::ByEnum)id); 880 881 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 882 activeStatesTriggered_[Mouse][iState]->mouseButtonPressed((MouseButtonCode::ByEnum)id); 883 884 return true; 885 } 886 887 /** 888 @brief 889 Event handler for the mouseReleased Event. 890 @param e 891 Event information 892 @param id 893 The ID of the mouse button 894 */ 895 bool InputManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id) 896 { 897 // remove the button from the keysDown_ list 898 for (unsigned int iButton = 0; iButton < mouseButtonsDown_.size(); iButton++) 899 { 900 if (mouseButtonsDown_[iButton] == (MouseButtonCode::ByEnum)id) 901 { 902 mouseButtonsDown_.erase(mouseButtonsDown_.begin() + iButton); 903 break; 904 } 905 } 906 907 for (unsigned int iState = 0; iState < activeStatesTriggered_[Mouse].size(); ++iState) 908 activeStatesTriggered_[Mouse][iState]->mouseButtonReleased((MouseButtonCode::ByEnum)id); 909 910 return true; 639 BOOST_FOREACH(InputDevice* device, devices_) 640 device->clearBuffers(); 911 641 } 912 642 … … 923 653 Returns true if ID is ok (unique), false otherwise. 924 654 */ 925 bool InputManager::checkJoyStickID(const std::string& idString) 926 { 927 BOOST_FOREACH(JoyStick* stick, joySticks_) 928 { 929 if (stick->getIDString() == idString) 655 bool InputManager::checkJoyStickID(const std::string& idString) const 656 { 657 for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i) 658 if (static_cast<JoyStick*>(devices_[i])->getIDString() == idString) 930 659 return false; 931 }932 660 return true; 933 661 } … … 938 666 // ########## ########## 939 667 // ############################################################ 940 941 /**942 @brief943 Adjusts the mouse window metrics.944 This method has to be called every time the size of the window changes.945 @param width946 The new width of the render window947 @param^height948 The new height of the render window949 */950 void InputManager::setWindowExtents(const int width, const int height)951 {952 if (mouse_)953 {954 // Set mouse region (if window resizes, we should alter this to reflect as well)955 mouse_->getMouseState().width = width;956 mouse_->getMouseState().height = height;957 }958 }959 668 960 669 /** … … 970 679 971 680 // ###### InputStates ###### 681 682 /** 683 @brief 684 Creates a new InputState by type, name and priority. 685 686 You will have to use this method because the 687 c'tors and d'tors are private. 688 @remarks 689 The InputManager will take care of the state completely. That also 690 means it gets deleted when the InputManager is destroyed! 691 @param name 692 Name of the InputState when referenced as string 693 @param priority 694 Priority matters when multiple states are active. You can specify any 695 number, but 1 - 99 is preferred (99 means high). 696 */ 697 InputState* InputManager::createInputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority) 698 { 699 InputState* state = new InputState; 700 if (_configureInputState(state, name, bAlwaysGetsInput, bTransparent, priority)) 701 return state; 702 else 703 { 704 delete state; 705 return 0; 706 } 707 } 972 708 973 709 /** … … 1008 744 } 1009 745 inputStatesByName_[name] = state; 1010 state->JoyStick DeviceNumberChanged(numberOfJoySticks());746 state->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick); 1011 747 state->setName(name); 1012 748 state->bAlwaysGetsInput_ = bAlwaysGetsInput;
Note: See TracChangeset
for help on using the changeset viewer.