Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Merged all remaining revisions from core4 back to the trunk.

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