1 /* 2 The zlib/libpng License 3 4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 5 6 This software is provided 'as-is', without any express or implied warranty. In no event will 7 the authors be held liable for any damages arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, including commercial 10 applications, and to alter it and redistribute it freely, subject to the following 11 restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not claim that 14 you wrote the original software. If you use this software in a product, 15 an acknowledgment in the product documentation would be appreciated but is 16 not required. 17 18 2. Altered source versions must be plainly marked as such, and must not be 19 misrepresented as being the original software. 20 21 3. This notice may not be removed or altered from any source distribution. 22 */ 23 #ifndef OIS_Mouse_H 24 #define OIS_Mouse_H 25 #include "OISObject.h" 26 #include "OISEvents.h" 27 28 namespace OIS 29 { 30 //! Button ID for mouse devices 31 enum MouseButtonID 32 { 33 MB_Left = 0, MB_Right, MB_Middle, 34 MB_Button3, MB_Button4, MB_Button5, MB_Button6, MB_Button7 35 }; 36 37 /** 38 Represents the state of the mouse 39 All members are valid for both buffered and non buffered mode 40 */ 41 class _OISExport MouseState 42 { 43 public: MouseState()44 MouseState() : width(50), height(50), buttons(0) {}; 45 46 /** Represents the height/width of your display area.. used if mouse clipping 47 or mouse grabbed in case of X11 - defaults to 50.. Make sure to set this 48 and change when your size changes.. */ 49 mutable int width, height; 50 51 //! X Axis component 52 Axis X; 53 54 //! Y Axis Component 55 Axis Y; 56 57 //! Z Axis Component 58 Axis Z; 59 60 //! represents all buttons - bit position indicates button down 61 int buttons; 62 63 //! Button down test buttonDown(MouseButtonID button)64 inline bool buttonDown( MouseButtonID button ) const 65 { 66 return ((buttons & ( 1L << button )) == 0) ? false : true; 67 } 68 69 //! Clear all the values clear()70 void clear() 71 { 72 X.clear(); 73 Y.clear(); 74 Z.clear(); 75 buttons = 0; 76 } 77 }; 78 79 /** Specialised for mouse events */ 80 class _OISExport MouseEvent : public EventArg 81 { 82 public: MouseEvent(Object * obj,const MouseState & ms)83 MouseEvent( Object *obj, const MouseState &ms ) : EventArg(obj), state(ms) {} ~MouseEvent()84 virtual ~MouseEvent() {} 85 86 //! The state of the mouse - including buttons and axes 87 const MouseState &state; 88 }; 89 90 /** 91 To recieve buffered mouse input, derive a class from this, and implement the 92 methods here. Then set the call back to your Mouse instance with Mouse::setEventCallback 93 */ 94 class _OISExport MouseListener 95 { 96 public: ~MouseListener()97 virtual ~MouseListener() {} 98 virtual bool mouseMoved( const MouseEvent &arg ) = 0; 99 virtual bool mousePressed( const MouseEvent &arg, MouseButtonID id ) = 0; 100 virtual bool mouseReleased( const MouseEvent &arg, MouseButtonID id ) = 0; 101 }; 102 103 /** 104 Mouse base class. To be implemented by specific system (ie. DirectX Mouse) 105 This class is useful as you remain OS independent using this common interface. 106 */ 107 class _OISExport Mouse : public Object 108 { 109 public: ~Mouse()110 virtual ~Mouse() {} 111 112 /** 113 @remarks 114 Register/unregister a Mouse Listener - Only one allowed for simplicity. If broadcasting 115 is neccessary, just broadcast from the callback you registered. 116 @param mouseListener 117 Send a pointer to a class derived from MouseListener or 0 to clear the callback 118 */ setEventCallback(MouseListener * mouseListener)119 virtual void setEventCallback( MouseListener *mouseListener ) {mListener = mouseListener;} 120 121 /** @remarks Returns currently set callback.. or 0 */ getEventCallback()122 MouseListener* getEventCallback() const {return mListener;} 123 124 /** @remarks Returns the state of the mouse - is valid for both buffered and non buffered mode */ getMouseState()125 const MouseState& getMouseState() const { return mState; } 126 127 protected: Mouse(const std::string & vendor,bool buffered,int devID,InputManager * creator)128 Mouse(const std::string &vendor, bool buffered, int devID, InputManager* creator) 129 : Object(vendor, OISMouse, buffered, devID, creator), mListener(0) {} 130 131 //! The state of the mouse 132 MouseState mState; 133 134 //! Used for buffered/actionmapping callback 135 MouseListener *mListener; 136 }; 137 } 138 #endif 139