Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core4/src/core/input/Mouse.h @ 3286

Last change on this file since 3286 was 3286, checked in by rgrieder, 15 years ago

Added and adjusted documentation for the devices.
Also removed one last ugliness where the InputManager was called from within a device (which should not even know about the InputManager).

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Core_Mouse_H__
30#define _Core_Mouse_H__
31
32#include "InputPrereqs.h"
33#include "InputDevice.h"
34
35namespace orxonox
36{
37    //! Template parameter collection for the base class
38    struct MouseTraits
39    {
40        typedef Mouse DeviceClass;
41        typedef OIS::Mouse OISDeviceClass;
42        typedef MouseButtonCode::ByEnum ButtonType;
43        typedef MouseButtonCode::ByEnum ButtonTypeParam;
44        static const OIS::Type OISDeviceValue = OIS::OISMouse;
45    };
46
47    /**
48    @brief
49        Wraps around an OIS::Mouse and forwards the input events to
50        a list of input states.
51    */
52    class _CoreExport Mouse
53        : public InputDeviceTemplated<MouseTraits>
54        , public OIS::MouseListener
55    {
56        friend class InputDeviceTemplated<MouseTraits>;
57        //! Super class alias
58        typedef InputDeviceTemplated<MouseTraits> super;
59
60    public:
61        //! 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);
63        ~Mouse() { }
64
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() { }
81#ifdef ORXONOX_PLATFORM_LINUX
82        // HACK!
83        // TODO: Make this a feature rather than a hack
84        static void grabMouse();
85        static void ungrabMouse();
86#endif
87
88    private:
89        //! OIS event handler
90        bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
91        {
92            super::buttonPressed(static_cast<MouseButtonCode::ByEnum>(id));
93            return true;
94        }
95
96        //! OIS event handler
97        bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
98        {
99            super::buttonReleased(static_cast<MouseButtonCode::ByEnum>(id));
100            return true;
101        }
102
103        bool mouseMoved(const OIS::MouseEvent &arg);
104
105        // Returns the class name as string
106        static std::string getClassNameImpl() { return "Mouse"; }
107
108        // HACK:
109        static Mouse* instancePointer_s;
110    };
111}
112
113#endif /* _Core_Mouse_H__ */
Note: See TracBrowser for help on using the repository browser.