Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3291


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
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/CorePrereqs.h

    r3274 r3291  
    153153    class TclThreadManager;
    154154    class Template;
    155     class Tickable;
     155    class WindowEventListener;
    156156    class XMLFile;
    157157    class XMLNameListener;
  • code/branches/core4/src/core/WindowEventListener.cc

    r3290 r3291  
    3232namespace orxonox
    3333{
     34    unsigned int WindowEventListener::windowWidth_s  = 0;
     35    unsigned int WindowEventListener::windowHeight_s = 0;
     36
    3437    WindowEventListener::WindowEventListener()
    3538    {
    3639        RegisterRootObject(WindowEventListener);
    3740    }
     41
     42    //! Calls all registered objects
     43    /*static*/ void WindowEventListener::moveWindow()
     44    {
     45        for (ObjectList<WindowEventListener>::iterator it = ObjectList<WindowEventListener>::begin(); it; ++it)
     46            it->windowMoved();
     47    }
     48
     49    //! Calls all registered objects and sets the static variables
     50    /*static*/ void WindowEventListener::resizeWindow(unsigned int newWidth, unsigned int newHeight)
     51    {
     52        windowWidth_s = newWidth;
     53        windowHeight_s = newHeight;
     54        for (ObjectList<WindowEventListener>::iterator it = ObjectList<WindowEventListener>::begin(); it; ++it)
     55            it->windowResized(newWidth, newHeight);
     56    }
     57
     58    //! Calls all registered objects
     59    /*static*/ void WindowEventListener::changeWindowFocus()
     60    {
     61        for (ObjectList<WindowEventListener>::iterator it = ObjectList<WindowEventListener>::begin(); it; ++it)
     62            it->windowFocusChanged();
     63    }
    3864}
  • code/branches/core4/src/core/WindowEventListener.h

    r3290 r3291  
    3838    class _CoreExport WindowEventListener : virtual public OrxonoxClass
    3939    {
    40         public:
     40        friend class OgreWindowEventListener;
     41
     42        protected:
    4143            WindowEventListener();
    4244            virtual ~WindowEventListener() { }
    4345
     46            //! Returns the current render window width
     47            unsigned int getWindowWidth() const { return windowWidth_s; }
     48            //! Returns the current render window height
     49            unsigned int getWindowHeight() const { return windowHeight_s; }
     50
     51        private:
    4452            //! Window has been moved
    4553            virtual void windowMoved() { }
     
    5058            //! Window has lost/gained focus
    5159            virtual void windowFocusChanged() { }
     60
     61            static void moveWindow();
     62            static void resizeWindow(unsigned int newWidth, unsigned int newHeight);
     63            static void changeWindowFocus();
     64
     65            //! Static variable that holds the latest distributed information
     66            static unsigned int windowWidth_s;
     67            static unsigned int windowHeight_s;
    5268    };
    5369}
  • 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}
  • code/branches/core4/src/orxonox/GraphicsManager.cc

    r3290 r3291  
    7575    class _OrxonoxExport OgreWindowEventListener : public Ogre::WindowEventListener
    7676    {
    77         void windowResized     (Ogre::RenderWindow* rw);
    78         void windowFocusChange (Ogre::RenderWindow* rw);
    79         void windowClosed      (Ogre::RenderWindow* rw);
    80         //void windowMoved       (Ogre::RenderWindow* rw);
     77        void windowResized     (Ogre::RenderWindow* rw)
     78            { orxonox::WindowEventListener::resizeWindow(rw->getWidth(), rw->getHeight()); }
     79        void windowFocusChange (Ogre::RenderWindow* rw)
     80            { orxonox::WindowEventListener::changeWindowFocus(); }
     81        void windowClosed      (Ogre::RenderWindow* rw)
     82            { orxonox::Game::getInstance().stop(); }
     83        void windowMoved       (Ogre::RenderWindow* rw)
     84            { orxonox::WindowEventListener::moveWindow(); }
    8185    };
    8286
     
    418422        this->renderWindow_->writeContentsToTimestampedFile(Core::getLogPathString() + "screenShot_", ".jpg");
    419423    }
    420 
    421 
    422     /****** OgreWindowEventListener ******/
    423 
    424     void OgreWindowEventListener::windowResized(Ogre::RenderWindow* rw)
    425     {
    426         for (ObjectList<orxonox::WindowEventListener>::iterator it
    427             = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    428             it->windowResized(rw->getWidth(), rw->getHeight());
    429     }
    430     void OgreWindowEventListener::windowFocusChange(Ogre::RenderWindow* rw)
    431     {
    432         for (ObjectList<orxonox::WindowEventListener>::iterator it
    433             = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    434             it->windowFocusChanged();
    435     }
    436     void OgreWindowEventListener::windowClosed(Ogre::RenderWindow* rw)
    437     {
    438         Game::getInstance().stop();
    439     }
    440424}
  • code/branches/core4/src/orxonox/OrxonoxPrereqs.h

    r3261 r3291  
    9292    class Level;
    9393    class Scene;
     94    class Tickable;
    9495
    9596    class AddQuest;
  • code/branches/core4/src/orxonox/gamestates/GSGraphics.cc

    r3279 r3291  
    3939
    4040#include "util/Convert.h"
    41 #include "core/ConfigValueIncludes.h"
    4241#include "core/Clock.h"
    4342#include "core/CommandExecutor.h"
    4443#include "core/ConsoleCommand.h"
    4544#include "core/Core.h"
    46 #include "core/CoreIncludes.h"
    4745#include "core/Game.h"
    4846#include "core/GameMode.h"
     
    7270        , debugOverlay_(0)
    7371    {
    74         RegisterRootObject(GSGraphics);
    7572    }
    7673
    7774    GSGraphics::~GSGraphics()
    78     {
    79     }
    80 
    81     /**
    82     @brief
    83         this function does nothing
    84 
    85         Indeed. Here goes nothing.
    86     */
    87     void GSGraphics::setConfigValues()
    8875    {
    8976    }
     
    10895        GameMode::setShowsGraphics(true);
    10996
    110         setConfigValues();
    111 
    11297        // Load OGRE including the render window
    11398        this->graphicsManager_ = new GraphicsManager();
     
    124109
    125110        // Calls the InputManager which sets up the input devices.
    126         inputManager_ = new InputManager(windowHnd, renderWindow->getWidth(), renderWindow->getHeight());
     111        inputManager_ = new InputManager(windowHnd);
    127112
    128113        // load master key bindings
     
    137122        // Load the InGameConsole
    138123        console_ = new InGameConsole();
    139         console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
     124        console_->initialise();
    140125
    141126        // load the CEGUI interface
     
    233218        this->graphicsManager_->update(time);
    234219    }
    235 
    236     /**
    237     @brief
    238         Window has resized.
    239     @param rw
    240         The render window it occured in
    241     @note
    242         GraphicsManager has a render window stored itself. This is the same
    243         as rw. But we have to be careful when using multiple render windows!
    244     */
    245     void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
    246     {
    247         // OIS needs this under linux even if we only use relative input measurement.
    248         // HACK:
    249         CommandExecutor::execute("setWindowExtents_s " + multi_cast<std::string>(newWidth) + " " + multi_cast<std::string>(newHeight));
    250     }
    251 
    252     /**
    253     @brief
    254         Window focus has changed.
    255     @param rw
    256         The render window it occured in
    257     */
    258     void GSGraphics::windowFocusChanged()
    259     {
    260         // instruct InputManager to clear the buffers (core library so we cannot use the interface)
    261         if (this->inputManager_)
    262             this->inputManager_->clearBuffers();
    263     }
    264 
    265220}
  • code/branches/core4/src/orxonox/gamestates/GSGraphics.h

    r3290 r3291  
    3737
    3838#include "OrxonoxPrereqs.h"
    39 
    4039#include "core/GameState.h"
    41 #include "core/WindowEventListener.h"
    4240
    4341namespace orxonox
     
    4947        This game state is only left out if we start a dedicated server where no graphics are present.
    5048    */
    51     class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
     49    class _OrxonoxExport GSGraphics : public GameState
    5250    {
    5351    public:
    5452        GSGraphics(const GameStateConstrParams& params);
    5553        ~GSGraphics();
    56         void setConfigValues();
    5754
    5855        void activate();
     
    6360
    6461    private:
    65         // Window events from WindowEventListener
    66         void windowResized(unsigned int newWidth, unsigned int newHeight);
    67         void windowFocusChanged();
    68 
    6962        // managed singletons
    7063        InputManager*         inputManager_;        //!< Reference to input management
  • code/branches/core4/src/orxonox/overlays/OrxonoxOverlay.cc

    r3265 r3291  
    4747#include "core/XMLPort.h"
    4848#include "core/ConsoleCommand.h"
    49 #include "GraphicsManager.h"
    5049
    5150namespace orxonox
     
    8180
    8281        // Get aspect ratio from the render window. Later on, we get informed automatically
    83         Ogre::RenderWindow* defaultWindow = GraphicsManager::getInstance().getRenderWindow();
    84         this->windowAspectRatio_ = (float)defaultWindow->getWidth() / defaultWindow->getHeight();
     82        this->windowAspectRatio_ = (float)this->getWindowWidth() / this->getWindowHeight();
    8583        this->sizeCorrectionChanged();
    8684
  • code/branches/core4/src/orxonox/overlays/console/InGameConsole.cc

    r3279 r3291  
    172172        @brief Initializes the InGameConsole.
    173173    */
    174     void InGameConsole::initialise(int windowWidth, int windowHeight)
     174    void InGameConsole::initialise()
    175175    {
    176176        // create the corresponding input state
     
    248248        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
    249249
    250         this->windowResized(windowWidth, windowHeight);
     250        this->windowResized(this->getWindowWidth(), this->getWindowWidth());
    251251
    252252        // move overlay "above" the top edge of the screen
  • code/branches/core4/src/orxonox/overlays/console/InGameConsole.h

    r3290 r3291  
    4646        ~InGameConsole();
    4747
    48         void initialise(int windowWidth, int windowHeight);
     48        void initialise();
    4949        void destroy();
    5050        void setConfigValues();
Note: See TracChangeset for help on using the changeset viewer.