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.

Location:
code/branches/resource2/src
Files:
10 edited

Legend:

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

    r5658 r5670  
    4141#include <cstdio>
    4242#include <boost/filesystem.hpp>
    43 #include <OgreRenderWindow.h>
    4443
    4544#ifdef ORXONOX_PLATFORM_WINDOWS
     
    309308        graphicsManager_->upgradeToGraphics();
    310309
    311         // The render window width and height are used to set up the mouse movement.
    312         size_t windowHnd = 0;
    313         graphicsManager_->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
    314 
    315310        // Calls the InputManager which sets up the input devices.
    316         inputManager_.reset(new InputManager(windowHnd));
     311        inputManager_.reset(new InputManager());
    317312
    318313        // load the CEGUI interface
    319         guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow()));
     314        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
     315            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
    320316
    321317        unloader.Dismiss();
     
    331327
    332328        // Load Ogre::Root again, but without the render system
    333         this->graphicsManager_.reset(new GraphicsManager(false));
     329        try
     330            { this->graphicsManager_.reset(new GraphicsManager(false)); }
     331        catch (...)
     332        {
     333            COUT(0) << "An exception occurred during 'new GraphicsManager' while "
     334                    << "another exception was being handled. This will lead to undefined behaviour!" << std::endl
     335                    << "Terminating the program." << std::endl;
     336            abort();
     337        }
    334338
    335339        bGraphicsLoaded_ = false;
  • code/branches/resource2/src/core/GUIManager.cc

    r5661 r5670  
    3737#include <CEGUIExceptions.h>
    3838#include <CEGUIInputEvent.h>
     39#include <CEGUIMouseCursor.h>
    3940#include <CEGUIResourceProvider.h>
    4041#include <CEGUISystem.h>
     
    9697    @return true if success, otherwise false
    9798    */
    98     GUIManager::GUIManager(Ogre::RenderWindow* renderWindow)
     99    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen)
    99100        : renderWindow_(renderWindow)
    100101        , resourceProvider_(0)
     
    127128        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
    128129        this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
     130
     131        // Align CEGUI mouse with OIS mouse
     132        guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
     133
     134#ifdef ORXONOX_PLATFORM_WINDOWS
     135        // Hide the mouse cursor unless playing in fullscreen mode
     136        if (!bFullScreen)
     137            CEGUI::MouseCursor::getSingleton().hide();
     138#endif
    129139    }
    130140
     
    254264    void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
    255265    {
    256         guiSystem_->injectMouseMove(static_cast<float>(rel.x), static_cast<float>(rel.y));
     266        guiSystem_->injectMousePosition(static_cast<float>(abs.x), static_cast<float>(abs.y));
    257267    }
    258268    void GUIManager::mouseScrolled(int abs, int rel)
  • code/branches/resource2/src/core/GUIManager.h

    r5661 r5670  
    6060        friend class Singleton<GUIManager>;
    6161    public:
    62         GUIManager(Ogre::RenderWindow* renderWindow);
     62        GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen);
    6363        ~GUIManager();
    6464
  • code/branches/resource2/src/core/GraphicsManager.cc

    r5662 r5670  
    128128    GraphicsManager::~GraphicsManager()
    129129    {
     130        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
    130131        // TODO: Destroy the console command
    131132    }
     
    337338    }
    338339
     340    size_t GraphicsManager::getRenderWindowHandle()
     341    {
     342        size_t windowHnd = 0;
     343        renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
     344        return windowHnd;
     345    }
     346
     347    bool GraphicsManager::isFullScreen() const
     348    {
     349        Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions();
     350        if (options.find("Full Screen") != options.end())
     351        {
     352            if (options["Full Screen"].currentValue == "Yes")
     353                return true;
     354            else
     355                return false;
     356        }
     357        else
     358        {
     359            COUT(0) << "Could not find 'Full Screen' render system option. Fix This!!!" << std::endl;
     360            return false;
     361        }
     362    }
     363
    339364    void GraphicsManager::printScreen()
    340365    {
  • code/branches/resource2/src/core/GraphicsManager.h

    r5657 r5670  
    6767        Ogre::Viewport* getViewport()         { return this->viewport_; }
    6868        Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
     69        size_t getRenderWindowHandle();
     70        bool isFullScreen() const;
    6971
    7072        void upgradeToGraphics();
  • 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    // ############################################################
  • code/branches/resource2/src/core/input/InputManager.h

    r3370 r5670  
    8484            the constructor fails with an std::exception.
    8585        */
    86         InputManager(size_t windowHnd);
     86        InputManager();
    8787        //! Destroys all devices AND all input states!
    8888        ~InputManager();
     
    167167            { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
    168168        //! 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;
    171171
    172172    private: // functions
     
    175175
    176176        // Intenal methods
    177         void loadDevices(size_t windowHnd);
     177        void loadDevices();
    178178        void loadMouse();
    179179        void loadJoySticks();
     
    193193        OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
    194194        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
    197196
    198197        // some internally handled states and handlers
  • code/branches/resource2/src/core/input/InputState.cc

    r3327 r5670  
    3737        , bAlwaysGetsInput_(bAlwaysGetsInput)
    3838        , bTransparent_(bTransparent)
     39        , bExclusiveMouse_(true)
    3940        , bExpired_(true)
    4041        , handlers_(2)
  • code/branches/resource2/src/core/input/InputState.h

    r3327 r5670  
    7575          not influence ony other InputState at all.
    7676
    77         Priorities
    78         **********
     77    @par Priorities
    7978        Every InputState has a priority when on the stack, but mostly this
    8079        priority is dynamic (InputStatePriority::Dynamic) which means that a state
     
    8382        a high priority (InputStatePriority::HighPriority). These 'special' ones
    8483        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.
    8591    */
    8692    class _CoreExport InputState : public JoyStickQuantityListener
     
    114120        void setHandler        (InputHandler* handler);
    115121
     122        void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }
     123        bool getIsExclusiveMouse() const { return bExclusiveMouse_; }
     124
    116125        //! Returns the name of the state (which is unique!)
    117126        const std::string& getName() const { return name_; }
     
    165174        const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
    166175        const bool                  bTransparent_;          //!< See class declaration for explanation
     176        bool                        bExclusiveMouse_;       //!< See class declaration for explanation
    167177        int                         priority_;              //!< Current priority (might change)
    168178        bool                        bExpired_;              //!< See hasExpired()
  • code/branches/resource2/src/orxonox/gamestates/GSMainMenu.cc

    r5661 r5670  
    5252        inputState_->setHandler(GUIManager::getInstancePtr());
    5353        inputState_->setJoyStickHandler(&InputHandler::EMPTY);
     54        inputState_->setIsExclusiveMouse(false);
    5455
    5556        // create an empty Scene
Note: See TracChangeset for help on using the changeset viewer.