[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/CoreIncludes.h" |
---|
[7284] | 33 | #include "core/command/ConsoleCommand.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] | 41 | namespace orxonox |
---|
| 42 | { |
---|
[7284] | 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 | |
---|
[3327] | 52 | Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager) |
---|
| 53 | : super(id, oisInputManager) |
---|
[3274] | 54 | { |
---|
[3327] | 55 | RegisterRootObject(Mouse); |
---|
| 56 | this->windowResized(this->getWindowWidth(), this->getWindowHeight()); |
---|
[3274] | 57 | |
---|
[3327] | 58 | #ifdef ORXONOX_PLATFORM_LINUX |
---|
[7284] | 59 | ModifyConsoleCommand(__CC_Mouse_name, __CC_grab_name).setObject(this); |
---|
| 60 | ModifyConsoleCommand(__CC_Mouse_name, __CC_ungrab_name).setObject(this); |
---|
[3327] | 61 | #endif |
---|
[3274] | 62 | } |
---|
| 63 | |
---|
[7284] | 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 | |
---|
[3274] | 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); |
---|
[3327] | 81 | for (unsigned int i = 0; i < inputStates_.size(); ++i) |
---|
| 82 | inputStates_[i]->mouseMoved(abs, rel, clippingSize); |
---|
[3274] | 83 | } |
---|
| 84 | |
---|
| 85 | // check for mouse scrolled event |
---|
| 86 | if (e.state.Z.rel != 0) |
---|
| 87 | { |
---|
[3327] | 88 | for (unsigned int i = 0; i < inputStates_.size(); ++i) |
---|
| 89 | inputStates_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel); |
---|
[3274] | 90 | } |
---|
| 91 | |
---|
| 92 | return true; |
---|
| 93 | } |
---|
[3276] | 94 | |
---|
[3327] | 95 | void Mouse::windowResized(unsigned int newWidth, unsigned int newHeight) |
---|
| 96 | { |
---|
| 97 | oisDevice_->getMouseState().width = newWidth; |
---|
| 98 | oisDevice_->getMouseState().height = newHeight; |
---|
| 99 | } |
---|
[3276] | 100 | |
---|
| 101 | #ifdef ORXONOX_PLATFORM_LINUX |
---|
[3327] | 102 | void Mouse::grab() |
---|
[3276] | 103 | { |
---|
[3327] | 104 | OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(oisDevice_); |
---|
[3276] | 105 | assert(linuxMouse); |
---|
| 106 | linuxMouse->grab(true); |
---|
| 107 | } |
---|
| 108 | |
---|
[3327] | 109 | void Mouse::ungrab() |
---|
[3276] | 110 | { |
---|
[3327] | 111 | OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(oisDevice_); |
---|
[3276] | 112 | assert(linuxMouse); |
---|
| 113 | linuxMouse->grab(false); |
---|
| 114 | } |
---|
| 115 | #endif |
---|
[3274] | 116 | } |
---|