Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 14, 2009, 11:50:47 AM (15 years ago)
Author:
rgrieder
Message:

Added window size as static variable to the WindowEventListener interface.
This resolves several hacks and inconveniences in Mouse, InputManager, InGameConsole, GSGraphics and OrxonoxOverlay.

Location:
code/branches/core4/src/core/input
Files:
5 edited

Legend:

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

    r3288 r3291  
    8282    // ##########                                        ##########
    8383    // ############################################################
    84     InputManager::InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight)
     84    InputManager::InputManager(size_t windowHnd)
    8585        : internalState_(Bad)
    8686        , oisInputManager_(0)
     
    100100        this->setConfigValues();
    101101
    102         this->loadDevices(windowHnd, windowWidth, windowHeight);
     102        this->loadDevices(windowHnd);
    103103
    104104        // Lowest priority empty InputState
     
    157157        The height of the render window
    158158    */
    159     void InputManager::loadDevices(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight)
     159    void InputManager::loadDevices(size_t windowHnd)
    160160    {
    161161        CCOUT(3) << "Loading input devices..." << std::endl;
     
    216216
    217217        // TODO: Remove the two parameters
    218         this->loadMouse(windowWidth, windowHeight);
     218        this->loadMouse();
    219219        this->loadJoySticks();
    220220
     
    226226
    227227    //! Creates a new orxonox::Mouse
    228     void InputManager::loadMouse(unsigned int windowWidth, unsigned int windowHeight)
     228    void InputManager::loadMouse()
    229229    {
    230230        if (oisInputManager_->getNumberOfDevices(OIS::OISMouse) > 0)
     
    232232            try
    233233            {
    234                 devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_, windowWidth, windowHeight);
     234                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_);
    235235            }
    236236            catch (const OIS::Exception& ex)
     
    368368        CCOUT(3) << "Reloading ..." << std::endl;
    369369
    370         // Save mouse clipping size
    371         int clippingWidth = 800;
    372         int clippingHeight = 600;
    373         if (devices_[InputDeviceEnumerator::Mouse])
    374         {
    375             int clippingWidth  = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingWidth();
    376             int clippingHeight = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse])->getClippingHeight();
    377         }
    378 
    379370        this->destroyDevices();
    380         this->loadDevices(windowHnd_, clippingWidth, clippingHeight);
     371        this->loadDevices(windowHnd_);
    381372
    382373        internalState_ &= ~Bad;
     
    563554    }
    564555
     556    //! Gets called by WindowEventListener upon focus change --> clear buffers
     557    void InputManager::windowFocusChanged()
     558    {
     559        this->clearBuffers();
     560    }
     561
    565562    // ############################################################
    566563    // #####                    Iput States                   #####
  • code/branches/core4/src/core/input/InputManager.h

    r3286 r3291  
    3737#include <vector>
    3838
    39 #include "core/OrxonoxClass.h"
     39#include "core/WindowEventListener.h"
    4040#include "InputState.h"
    4141
     
    6262          If the OIS::InputManager or the Keyboard fail, an exception is thrown.
    6363    */
    64     class _CoreExport InputManager : public OrxonoxClass
     64    class _CoreExport InputManager : public WindowEventListener
    6565    {
    6666    public:
     
    8282            the constructor fails with an std::exception.
    8383        */
    84         InputManager(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
     84        InputManager(size_t windowHnd);
    8585        //! Destroys all devices AND all input states!
    8686        ~InputManager();
     
    176176
    177177        // Intenal methods
    178         void loadDevices(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
    179         void loadMouse(unsigned int windowWidth, unsigned int windowHeight);
     178        void loadDevices(size_t windowHnd);
     179        void loadMouse();
    180180        void loadJoySticks();
    181181        void destroyDevices();
     
    186186        void destroyStateInternal(InputState* state);
    187187        void updateActiveStates();
     188
     189        // From WindowEventListener
     190        void windowFocusChanged();
    188191
    189192    private: // variables
  • code/branches/core4/src/core/input/JoyStickQuantityListener.h

    r3288 r3291  
    4444    {
    4545        friend InputManager;
    46     public:
     46    protected:
    4747        JoyStickQuantityListener();
    4848        virtual ~JoyStickQuantityListener() { }
  • code/branches/core4/src/core/input/Mouse.cc

    r3286 r3291  
    3030
    3131#include <ois/OISMouse.h>
     32#include "core/ConsoleCommand.h"
     33#include "core/CoreIncludes.h"
    3234#include "InputState.h"
    33 #include "core/ConsoleCommand.h"
    3435
    35 // HACK (include this as last, X11 seems to define some macros...)
    3636#ifdef ORXONOX_PLATFORM_LINUX
    37 #  include <ois/linux/LinuxMouse.h>
     37// include this as last, X11 seems to define some macros...
     38#include <ois/linux/LinuxMouse.h>
    3839#endif
    3940
    4041namespace orxonox
    4142{
    42     Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager, unsigned int windowWidth, unsigned int windowHeight)
     43    Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager)
    4344        : super(id, oisInputManager)
    4445    {
    45         this->setMouseClipping(windowWidth, windowHeight);
    46         // HACK:
    47         instancePointer_s = this;
    48     }
     46        RegisterRootObject(Mouse);
     47        this->windowResized(this->getWindowHeight(), this->getWindowHeight());
    4948
    50     void Mouse::setMouseClipping(unsigned int width, unsigned int height)
    51     {
    52         oisDevice_->getMouseState().width  = width;
    53         oisDevice_->getMouseState().height = height;
    54     }
    55 
    56     unsigned int Mouse::getClippingWidth() const
    57     {
    58         return oisDevice_->getMouseState().width;
    59     }
    60 
    61     unsigned int Mouse::getClippingHeight() const
    62     {
    63         return oisDevice_->getMouseState().height;
     49#ifdef ORXONOX_PLATFORM_LINUX
     50        {
     51            // Mouse grab console command
     52            FunctorMember<Mouse>* functor = createFunctor(&Mouse::grab);
     53            functor->setObject(this);
     54            this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "grab"), false);
     55        }
     56        {
     57            // Mouse ungrab console command
     58            FunctorMember<Mouse>* functor = createFunctor(&Mouse::ungrab);
     59            functor->setObject(this);
     60            this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "ungrab"), false);
     61        }
     62#endif
    6463    }
    6564
     
    8786    }
    8887
    89     // ############################################################
    90     // #####                   ugly hacks                     #####
    91     // ##########                                        ##########
    92     // ############################################################
    93 
    94     // HACK:
    95     SetConsoleCommand(Mouse, setMouseClipping_s, false);
    96 #ifdef ORXONOX_PLATFORM_LINUX
    97     SetConsoleCommand(Mouse, grabMouse, true);
    98     SetConsoleCommand(Mouse, ungrabMouse, true);
    99 #endif
    100     Mouse* Mouse::instancePointer_s = NULL;
     88    void Mouse::windowResized(unsigned int newWidth, unsigned int newHeight)
     89    {
     90        oisDevice_->getMouseState().width  = newWidth;
     91        oisDevice_->getMouseState().height = newHeight;
     92    }
    10193
    10294#ifdef ORXONOX_PLATFORM_LINUX
  • code/branches/core4/src/core/input/Mouse.h

    r3286 r3291  
    3131
    3232#include "InputPrereqs.h"
     33
    3334#include "InputDevice.h"
     35#include "core/WindowEventListener.h"
    3436
    3537namespace orxonox
     
    5355        : public InputDeviceTemplated<MouseTraits>
    5456        , public OIS::MouseListener
     57        , public WindowEventListener
    5558    {
    5659        friend class InputDeviceTemplated<MouseTraits>;
     
    6063    public:
    6164        //! Only sets the clipping size. Initialising is done in the base class.
    62         Mouse(unsigned int id, OIS::InputManager* oisInputManager, unsigned int windowWidth, unsigned int windowHeight);
     65        Mouse(unsigned int id, OIS::InputManager* oisInputManager);
    6366        ~Mouse() { }
    6467
    65         /**
    66         @brief
    67             Adjusts the mouse window metrics.
    68 
    69             This method has to be called every time the size of the window changes.
    70         */
    71         void setMouseClipping(unsigned int width, unsigned int height);
    72         // Returns the width of the mouse window
    73         unsigned int getClippingWidth() const;
    74         // Returns the height of the mouse window
    75         unsigned int getClippingHeight() const;
    76 
    77         // HACK!
    78         static void setMouseClipping_s(unsigned int width, unsigned int height)
    79             { instancePointer_s->setMouseClipping(width, height); }
    80         void setConfigValues() { }
    8168#ifdef ORXONOX_PLATFORM_LINUX
    82         // HACK!
    8369        // TODO: Make this a feature rather than a hack
    84         static void grabMouse();
    85         static void ungrabMouse();
     70        void grabMouse();
     71        void ungrabMouse();
    8672#endif
    8773
     
    10389        bool mouseMoved(const OIS::MouseEvent &arg);
    10490
     91        void windowResized(unsigned int newWidth, unsigned int newHeight);
     92
    10593        // Returns the class name as string
    10694        static std::string getClassNameImpl() { return "Mouse"; }
    107 
    108         // HACK:
    109         static Mouse* instancePointer_s;
    11095    };
    11196}
Note: See TracChangeset for help on using the changeset viewer.