/src/ois/includes/OISMouse.h

https://bitbucket.org/cabalistic/ogredeps/ · C Header · 138 lines · 62 code · 19 blank · 57 comment · 1 complexity · 0fe0b8cb8e97fb4f3e66b9f8262c4b73 MD5 · raw file

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