[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 | #ifndef _Core_Mouse_H__ |
---|
| 30 | #define _Core_Mouse_H__ |
---|
| 31 | |
---|
| 32 | #include "InputPrereqs.h" |
---|
| 33 | #include "InputDevice.h" |
---|
| 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
[3285] | 37 | struct MouseTraits |
---|
| 38 | { |
---|
| 39 | typedef Mouse DeviceClass; |
---|
| 40 | typedef OIS::Mouse OISDeviceClass; |
---|
| 41 | typedef MouseButtonCode::ByEnum ButtonType; |
---|
| 42 | typedef MouseButtonCode::ByEnum ButtonTypeParam; |
---|
| 43 | static const OIS::Type OISDeviceValue = OIS::OISMouse; |
---|
| 44 | }; |
---|
| 45 | |
---|
[3274] | 46 | /** |
---|
| 47 | @brief |
---|
| 48 | Wraps around an OIS::Mouse and forwards the input events to |
---|
| 49 | a list of input states. |
---|
| 50 | */ |
---|
| 51 | class _CoreExport Mouse |
---|
| 52 | : public InputDeviceTemplated<MouseTraits> |
---|
| 53 | , public OIS::MouseListener |
---|
| 54 | { |
---|
[3275] | 55 | friend class InputDeviceTemplated<MouseTraits>; |
---|
[3274] | 56 | //! Super class alias |
---|
| 57 | typedef InputDeviceTemplated<MouseTraits> super; |
---|
| 58 | |
---|
| 59 | public: |
---|
| 60 | Mouse(unsigned int id, unsigned int windowWidth, unsigned int windowHeight); |
---|
| 61 | ~Mouse() { } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | @brief |
---|
| 65 | Adjusts the mouse window metrics. |
---|
| 66 | |
---|
| 67 | This method has to be called every time the size of the window changes. |
---|
| 68 | */ |
---|
| 69 | void setMouseClipping(unsigned int width, unsigned int height); |
---|
| 70 | unsigned int getClippingWidth() const; |
---|
| 71 | unsigned int getClippingHeight() const; |
---|
| 72 | |
---|
[3276] | 73 | // HACK! |
---|
[3274] | 74 | static void setMouseClipping_s(unsigned int width, unsigned int height) |
---|
| 75 | { instancePointer_s->setMouseClipping(width, height); } |
---|
| 76 | void setConfigValues() { } |
---|
[3276] | 77 | #ifdef ORXONOX_PLATFORM_LINUX |
---|
| 78 | // HACK! |
---|
| 79 | static void grabMouse(); |
---|
| 80 | static void ungrabMouse(); |
---|
| 81 | #endif |
---|
[3274] | 82 | |
---|
| 83 | private: |
---|
| 84 | // TODO: Do we need to reset the mouse position? |
---|
| 85 | void clearBuffersImpl() { } |
---|
| 86 | |
---|
| 87 | //! OIS event handler |
---|
| 88 | bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id) |
---|
| 89 | { |
---|
| 90 | super::buttonPressed(static_cast<MouseButtonCode::ByEnum>(id)); |
---|
| 91 | return true; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | //! OIS event handler |
---|
| 95 | bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id) |
---|
| 96 | { |
---|
| 97 | super::buttonReleased(static_cast<MouseButtonCode::ByEnum>(id)); |
---|
| 98 | return true; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | bool mouseMoved(const OIS::MouseEvent &arg); |
---|
| 102 | |
---|
[3285] | 103 | static std::string getClassNameImpl() { return "Mouse"; } |
---|
| 104 | |
---|
[3274] | 105 | // HACK: |
---|
| 106 | static Mouse* instancePointer_s; |
---|
| 107 | }; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | #endif /* _Core_Mouse_H__ */ |
---|