Changeset 5670 for code/branches/resource2/src/core/input
- Timestamp:
- Aug 24, 2009, 9:43:34 AM (15 years ago)
- Location:
- code/branches/resource2/src/core/input
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/src/core/input/InputManager.cc
r3370 r5670 41 41 #include <boost/foreach.hpp> 42 42 43 #include "util/Convert.h" 43 44 #include "util/Exception.h" 44 45 #include "util/ScopeGuard.h" … … 49 50 #include "core/CommandLine.h" 50 51 #include "core/Functor.h" 52 #include "core/GraphicsManager.h" 51 53 52 54 #include "InputBuffer.h" … … 82 84 // ########## ########## 83 85 // ############################################################ 84 InputManager::InputManager( size_t windowHnd)86 InputManager::InputManager() 85 87 : internalState_(Bad) 86 88 , oisInputManager_(0) 87 89 , devices_(2) 88 , windowHnd_(0)90 , bExclusiveMouse_(false) 89 91 , emptyState_(0) 90 92 , keyDetector_(0) … … 97 99 this->setConfigValues(); 98 100 99 this->loadDevices( windowHnd);101 this->loadDevices(); 100 102 101 103 // Lowest priority empty InputState … … 147 149 Creates the OIS::InputMananger, the keyboard, the mouse and 148 150 the joys ticks. If either of the first two fail, this method throws an exception. 149 @param windowHnd150 The window handle of the render window151 151 @param windowWidth 152 152 The width of the render window … … 154 154 The height of the render window 155 155 */ 156 void InputManager::loadDevices( size_t windowHnd)157 { 158 CCOUT( 3) << "Loading input devices..." << std::endl;156 void InputManager::loadDevices() 157 { 158 CCOUT(4) << "Loading input devices..." << std::endl; 159 159 160 160 // When loading the devices they should not already be loaded … … 164 164 assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick); 165 165 166 // store handle internally so we can reload OIS 167 windowHnd_ = windowHnd; 168 166 // Fill parameter list 169 167 OIS::ParamList paramList; 170 std::ostringstream windowHndStr; 171 172 // Fill parameter list 173 windowHndStr << static_cast<unsigned int>(windowHnd); 174 paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); 168 size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle(); 169 paramList.insert(std::make_pair(std::string("WINDOW"), multi_cast<std::string>(windowHnd))); 175 170 #if defined(ORXONOX_PLATFORM_WINDOWS) 176 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 177 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); 178 //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE"))); 179 //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND"))); 171 // Load in non exclusive mode and change later 172 if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 173 paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_EXCLUSIVE"))); 174 else 175 paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 176 paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); 180 177 #elif defined(ORXONOX_PLATFORM_LINUX) 181 178 paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); … … 212 209 } 213 210 214 // TODO: Remove the two parameters215 211 this->loadMouse(); 216 212 this->loadJoySticks(); … … 219 215 this->updateActiveStates(); 220 216 221 CCOUT( 3) << "Input devices loaded." << std::endl;217 CCOUT(4) << "Input devices loaded." << std::endl; 222 218 } 223 219 … … 275 271 InputManager::~InputManager() 276 272 { 277 CCOUT( 4) << "Destroying..." << std::endl;273 CCOUT(3) << "Destroying..." << std::endl; 278 274 279 275 // Destroy calibrator helper handler and state … … 293 289 this->destroyDevices(); 294 290 295 CCOUT( 4) << "Destruction complete." << std::endl;291 CCOUT(3) << "Destruction complete." << std::endl; 296 292 } 297 293 … … 304 300 void InputManager::destroyDevices() 305 301 { 306 CCOUT( 3) << "Destroying devices..." << std::endl;302 CCOUT(4) << "Destroying devices..." << std::endl; 307 303 308 304 BOOST_FOREACH(InputDevice*& device, devices_) … … 336 332 337 333 internalState_ |= Bad; 338 CCOUT( 3) << "Destroyed devices." << std::endl;334 CCOUT(4) << "Destroyed devices." << std::endl; 339 335 } 340 336 … … 365 361 366 362 this->destroyDevices(); 367 this->loadDevices( windowHnd_);363 this->loadDevices(); 368 364 369 365 internalState_ &= ~Bad; 370 366 internalState_ &= ~ReloadRequest; 371 CCOUT( 3) << "Reloading complete." << std::endl;367 CCOUT(4) << "Reloading complete." << std::endl; 372 368 } 373 369 … … 481 477 void InputManager::updateActiveStates() 482 478 { 479 assert((internalState_ & InputManager::Ticking) == 0); 483 480 // temporary resize 484 481 for (unsigned int i = 0; i < devices_.size(); ++i) … … 512 509 for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it) 513 510 activeStatesTicked_.push_back(*it); 511 512 #ifdef ORXONOX_PLATFORM_WINDOWS 513 // Check whether we have to change the mouse mode 514 std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef(); 515 if (mouseStates.empty() && bExclusiveMouse_ || 516 !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_) 517 { 518 bExclusiveMouse_ = !bExclusiveMouse_; 519 if (!GraphicsManager::getInstance().isFullScreen()) 520 this->reloadInternal(); 521 } 522 #endif 514 523 } 515 524 … … 556 565 } 557 566 558 // ############################################################ 559 // ##### Iput States ##### 567 std::pair<int, int> InputManager::getMousePosition() const 568 { 569 Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]); 570 if (mouse != NULL) 571 { 572 const OIS::MouseState state = mouse->getOISDevice()->getMouseState(); 573 return std::make_pair(state.X.abs, state.Y.abs); 574 } 575 else 576 return std::make_pair(0, 0); 577 } 578 579 // ############################################################ 580 // ##### Input States ##### 560 581 // ########## ########## 561 582 // ############################################################ -
code/branches/resource2/src/core/input/InputManager.h
r3370 r5670 84 84 the constructor fails with an std::exception. 85 85 */ 86 InputManager( size_t windowHnd);86 InputManager(); 87 87 //! Destroys all devices AND all input states! 88 88 ~InputManager(); … … 167 167 { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; } 168 168 //! Returns a pointer to the OIS InputManager. Only you if you know what you're doing! 169 OIS::InputManager* getOISInputManager() 170 { return this->oisInputManager_; }169 OIS::InputManager* getOISInputManager() { return this->oisInputManager_; } 170 std::pair<int, int> getMousePosition() const; 171 171 172 172 private: // functions … … 175 175 176 176 // Intenal methods 177 void loadDevices( size_t windowHnd);177 void loadDevices(); 178 178 void loadMouse(); 179 179 void loadJoySticks(); … … 193 193 OIS::InputManager* oisInputManager_; //!< OIS input manager 194 194 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 195 // TODO: Get this from the GraphicsManager during reload 196 size_t windowHnd_; //!< Render window handle (used to reload the InputManager) 195 bool bExclusiveMouse_; //!< Currently applied mouse mode 197 196 198 197 // some internally handled states and handlers -
code/branches/resource2/src/core/input/InputState.cc
r3327 r5670 37 37 , bAlwaysGetsInput_(bAlwaysGetsInput) 38 38 , bTransparent_(bTransparent) 39 , bExclusiveMouse_(true) 39 40 , bExpired_(true) 40 41 , handlers_(2) -
code/branches/resource2/src/core/input/InputState.h
r3327 r5670 75 75 not influence ony other InputState at all. 76 76 77 Priorities 78 ********** 77 @par Priorities 79 78 Every InputState has a priority when on the stack, but mostly this 80 79 priority is dynamic (InputStatePriority::Dynamic) which means that a state … … 83 82 a high priority (InputStatePriority::HighPriority). These 'special' ones 84 83 are used for features like the KeyDetector or the console. Use with care! 84 85 @par Exclusive/Non-Exclusive mouse Mode 86 You can select a specific mouse mode that tells whether the application 87 should have exclusive accessto it or not. 88 When in non-exclusive mode, you can move the mouse out of the window 89 like with any other normal window (only for windowed mode!). 90 The setting is dictated by the topmost InputState that gets mouse events. 85 91 */ 86 92 class _CoreExport InputState : public JoyStickQuantityListener … … 114 120 void setHandler (InputHandler* handler); 115 121 122 void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; } 123 bool getIsExclusiveMouse() const { return bExclusiveMouse_; } 124 116 125 //! Returns the name of the state (which is unique!) 117 126 const std::string& getName() const { return name_; } … … 165 174 const bool bAlwaysGetsInput_; //!< See class declaration for explanation 166 175 const bool bTransparent_; //!< See class declaration for explanation 176 bool bExclusiveMouse_; //!< See class declaration for explanation 167 177 int priority_; //!< Current priority (might change) 168 178 bool bExpired_; //!< See hasExpired()
Note: See TracChangeset
for help on using the changeset viewer.