Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/libraries/core/input/Mouse.cc @ 5991

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

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

  • Property svn:eol-style set to native
File size: 3.1 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/ConsoleCommand.h"
33#include "core/CoreIncludes.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    Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager)
44        : super(id, oisInputManager)
45    {
46        RegisterRootObject(Mouse);
47        this->windowResized(this->getWindowWidth(), this->getWindowHeight());
48
49#ifdef ORXONOX_PLATFORM_LINUX
50        // Mouse grab console command
51        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::grab, this), "grab"), false);
52        // Mouse ungrab console command
53        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::ungrab, this), "ungrab"), false);
54#endif
55    }
56
57    //! OIS event handler
58    bool Mouse::mouseMoved(const OIS::MouseEvent &e)
59    {
60        // check for actual moved event
61        if (e.state.X.rel != 0 || e.state.Y.rel != 0)
62        {
63            IntVector2 abs(e.state.X.abs, e.state.Y.abs);
64            IntVector2 rel(e.state.X.rel, e.state.Y.rel);
65            IntVector2 clippingSize(e.state.width, e.state.height);
66            for (unsigned int i = 0; i < inputStates_.size(); ++i)
67                inputStates_[i]->mouseMoved(abs, rel, clippingSize);
68        }
69
70        // check for mouse scrolled event
71        if (e.state.Z.rel != 0)
72        {
73            for (unsigned int i = 0; i < inputStates_.size(); ++i)
74                inputStates_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
75        }
76
77        return true;
78    }
79
80    void Mouse::windowResized(unsigned int newWidth, unsigned int newHeight)
81    {
82        oisDevice_->getMouseState().width  = newWidth;
83        oisDevice_->getMouseState().height = newHeight;
84    }
85
86#ifdef ORXONOX_PLATFORM_LINUX
87    void Mouse::grab()
88    {
89        OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(oisDevice_);
90        assert(linuxMouse);
91        linuxMouse->grab(true);
92    }
93
94    void Mouse::ungrab()
95    {
96        OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(oisDevice_);
97        assert(linuxMouse);
98        linuxMouse->grab(false);
99    }
100#endif
101}
Note: See TracBrowser for help on using the repository browser.