Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 24, 2009, 9:43:34 AM (15 years ago)
Author:
rgrieder
Message:

Added support for non exclusive mouse mode on Windows. This means you get the normal mouse cursor when displaying a GUI menu in windowed mode.
The feature is activated via InputState (InputState::setIsExclusiveMouse(bool)). Whenever that state is on top of the mouse state stack, the input manager reloads if necessary.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/core/input/InputManager.cc

    r3370 r5670  
    4141#include <boost/foreach.hpp>
    4242
     43#include "util/Convert.h"
    4344#include "util/Exception.h"
    4445#include "util/ScopeGuard.h"
     
    4950#include "core/CommandLine.h"
    5051#include "core/Functor.h"
     52#include "core/GraphicsManager.h"
    5153
    5254#include "InputBuffer.h"
     
    8284    // ##########                                        ##########
    8385    // ############################################################
    84     InputManager::InputManager(size_t windowHnd)
     86    InputManager::InputManager()
    8587        : internalState_(Bad)
    8688        , oisInputManager_(0)
    8789        , devices_(2)
    88         , windowHnd_(0)
     90        , bExclusiveMouse_(false)
    8991        , emptyState_(0)
    9092        , keyDetector_(0)
     
    9799        this->setConfigValues();
    98100
    99         this->loadDevices(windowHnd);
     101        this->loadDevices();
    100102
    101103        // Lowest priority empty InputState
     
    147149        Creates the OIS::InputMananger, the keyboard, the mouse and
    148150        the joys ticks. If either of the first two fail, this method throws an exception.
    149     @param windowHnd
    150         The window handle of the render window
    151151    @param windowWidth
    152152        The width of the render window
     
    154154        The height of the render window
    155155    */
    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;
    159159
    160160        // When loading the devices they should not already be loaded
     
    164164        assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
    165165
    166         // store handle internally so we can reload OIS
    167         windowHnd_ = windowHnd;
    168 
     166        // Fill parameter list
    169167        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)));
    175170#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")));
    180177#elif defined(ORXONOX_PLATFORM_LINUX)
    181178        paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
     
    212209        }
    213210
    214         // TODO: Remove the two parameters
    215211        this->loadMouse();
    216212        this->loadJoySticks();
     
    219215        this->updateActiveStates();
    220216
    221         CCOUT(3) << "Input devices loaded." << std::endl;
     217        CCOUT(4) << "Input devices loaded." << std::endl;
    222218    }
    223219
     
    275271    InputManager::~InputManager()
    276272    {
    277         CCOUT(4) << "Destroying..." << std::endl;
     273        CCOUT(3) << "Destroying..." << std::endl;
    278274
    279275        // Destroy calibrator helper handler and state
     
    293289            this->destroyDevices();
    294290
    295         CCOUT(4) << "Destruction complete." << std::endl;
     291        CCOUT(3) << "Destruction complete." << std::endl;
    296292    }
    297293
     
    304300    void InputManager::destroyDevices()
    305301    {
    306         CCOUT(3) << "Destroying devices..." << std::endl;
     302        CCOUT(4) << "Destroying devices..." << std::endl;
    307303
    308304        BOOST_FOREACH(InputDevice*& device, devices_)
     
    336332
    337333        internalState_ |= Bad;
    338         CCOUT(3) << "Destroyed devices." << std::endl;
     334        CCOUT(4) << "Destroyed devices." << std::endl;
    339335    }
    340336
     
    365361
    366362        this->destroyDevices();
    367         this->loadDevices(windowHnd_);
     363        this->loadDevices();
    368364
    369365        internalState_ &= ~Bad;
    370366        internalState_ &= ~ReloadRequest;
    371         CCOUT(3) << "Reloading complete." << std::endl;
     367        CCOUT(4) << "Reloading complete." << std::endl;
    372368    }
    373369
     
    481477    void InputManager::updateActiveStates()
    482478    {
     479        assert((internalState_ & InputManager::Ticking) == 0);
    483480        // temporary resize
    484481        for (unsigned int i = 0; i < devices_.size(); ++i)
     
    512509        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
    513510            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
    514523    }
    515524
     
    556565    }
    557566
    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                  #####
    560581    // ##########                                        ##########
    561582    // ############################################################
Note: See TracChangeset for help on using the changeset viewer.