Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/input/Mouse.cc @ 7989

Last change on this file since 7989 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 3.6 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#include "Mouse.h"
30
31#include <ois/OISMouse.h>
32#include "core/CoreIncludes.h"
33#include "core/command/ConsoleCommand.h"
34#include "InputState.h"
35
36#ifdef ORXONOX_PLATFORM_LINUX
37// include this as last, X11 seems to define some macros...
38#include <ois/linux/LinuxMouse.h>
39#endif
40
41namespace orxonox
42{
43#ifdef ORXONOX_PLATFORM_LINUX
44    static const std::string __CC_Mouse_name = "Mouse";
45    static const std::string __CC_grab_name = "grab";
46    static const std::string __CC_ungrab_name = "ungrab";
47
48    SetConsoleCommand(__CC_Mouse_name, __CC_grab_name,   &Mouse::grab);
49    SetConsoleCommand(__CC_Mouse_name, __CC_ungrab_name, &Mouse::ungrab);
50#endif
51
52    Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager)
53        : super(id, oisInputManager)
54    {
55        RegisterRootObject(Mouse);
56        this->windowResized(this->getWindowWidth(), this->getWindowHeight());
57
58#ifdef ORXONOX_PLATFORM_LINUX
59        ModifyConsoleCommand(__CC_Mouse_name, __CC_grab_name).setObject(this);
60        ModifyConsoleCommand(__CC_Mouse_name, __CC_ungrab_name).setObject(this);
61#endif
62    }
63
64    Mouse::~Mouse()
65    {
66#ifdef ORXONOX_PLATFORM_LINUX
67        ModifyConsoleCommand(__CC_Mouse_name, __CC_grab_name).setObject(0);
68        ModifyConsoleCommand(__CC_Mouse_name, __CC_ungrab_name).setObject(0);
69#endif
70    }
71
72    //! OIS event handler
73    bool Mouse::mouseMoved(const OIS::MouseEvent &e)
74    {
75        // check for actual moved event
76        if (e.state.X.rel != 0 || e.state.Y.rel != 0)
77        {
78            IntVector2 abs(e.state.X.abs, e.state.Y.abs);
79            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
80            IntVector2 clippingSize(e.state.width, e.state.height);
81            for (unsigned int i = 0; i < inputStates_.size(); ++i)
82                inputStates_[i]->mouseMoved(abs, rel, clippingSize);
83        }
84
85        // check for mouse scrolled event
86        if (e.state.Z.rel != 0)
87        {
88            for (unsigned int i = 0; i < inputStates_.size(); ++i)
89                inputStates_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
90        }
91
92        return true;
93    }
94
95    void Mouse::windowResized(unsigned int newWidth, unsigned int newHeight)
96    {
97        oisDevice_->getMouseState().width  = newWidth;
98        oisDevice_->getMouseState().height = newHeight;
99    }
100
101#ifdef ORXONOX_PLATFORM_LINUX
102    void Mouse::grab()
103    {
104        OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(oisDevice_);
105        assert(linuxMouse);
106        linuxMouse->grab(true);
107    }
108
109    void Mouse::ungrab()
110    {
111        OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(oisDevice_);
112        assert(linuxMouse);
113        linuxMouse->grab(false);
114    }
115#endif
116}
Note: See TracBrowser for help on using the repository browser.