ICursorControl.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef IRR_I_CURSOR_CONTROL_H_INCLUDED
  5. #define IRR_I_CURSOR_CONTROL_H_INCLUDED
  6. #include "IReferenceCounted.h"
  7. #include "position2d.h"
  8. #include "rect.h"
  9. namespace irr
  10. {
  11. namespace gui
  12. {
  13. class IGUISpriteBank;
  14. //! Default icons for cursors
  15. enum ECURSOR_ICON
  16. {
  17. // Following cursors might be system specific, or might use an Irrlicht icon-set. No guarantees so far.
  18. ECI_NORMAL, // arrow
  19. ECI_CROSS, // Crosshair
  20. ECI_HAND, // Hand
  21. ECI_HELP, // Arrow and question mark
  22. ECI_IBEAM, // typical text-selection cursor
  23. ECI_NO, // should not click icon
  24. ECI_WAIT, // hourglass
  25. ECI_SIZEALL, // arrow in all directions
  26. ECI_SIZENESW, // resizes in direction north-east or south-west
  27. ECI_SIZENWSE, // resizes in direction north-west or south-east
  28. ECI_SIZENS, // resizes in direction north or south
  29. ECI_SIZEWE, // resizes in direction west or east
  30. ECI_UP, // up-arrow
  31. // Implementer note: Should we add system specific cursors, which use guaranteed the system icons,
  32. // then I would recommend using a naming scheme like ECI_W32_CROSS, ECI_X11_CROSSHAIR and adding those
  33. // additionally.
  34. ECI_COUNT // maximal of defined cursors. Note that higher values can be created at runtime
  35. };
  36. //! Names for ECURSOR_ICON
  37. const c8* const GUICursorIconNames[ECI_COUNT+1] =
  38. {
  39. "normal",
  40. "cross",
  41. "hand",
  42. "help",
  43. "ibeam",
  44. "no",
  45. "wait",
  46. "sizeall",
  47. "sizenesw",
  48. "sizenwse",
  49. "sizens",
  50. "sizewe",
  51. "sizeup",
  52. 0
  53. };
  54. //! structure used to set sprites as cursors.
  55. struct SCursorSprite
  56. {
  57. SCursorSprite()
  58. : SpriteBank(0), SpriteId(-1)
  59. {
  60. }
  61. SCursorSprite( gui::IGUISpriteBank * spriteBank, s32 spriteId, const core::position2d<s32> &hotspot=(core::position2d<s32>(0,0)) )
  62. : SpriteBank(spriteBank), SpriteId(spriteId), HotSpot(hotspot)
  63. {
  64. }
  65. IGUISpriteBank * SpriteBank;
  66. s32 SpriteId;
  67. core::position2d<s32> HotSpot;
  68. };
  69. //! platform specific behavior flags for the cursor
  70. enum ECURSOR_PLATFORM_BEHAVIOR
  71. {
  72. //! default - no platform specific behavior
  73. ECPB_NONE = 0,
  74. //! On X11 try caching cursor updates as XQueryPointer calls can be expensive.
  75. /** Update cursor positions only when the irrlicht timer has been updated or the timer is stopped.
  76. This means you usually get one cursor update per device->run() which will be fine in most cases.
  77. See this forum-thread for a more detailed explanation:
  78. http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=45525
  79. */
  80. ECPB_X11_CACHE_UPDATES = 1
  81. };
  82. //! Interface to manipulate the mouse cursor.
  83. class ICursorControl : public virtual IReferenceCounted
  84. {
  85. public:
  86. //! Changes the visible state of the mouse cursor.
  87. /** \param visible: The new visible state. If true, the cursor will be visible,
  88. if false, it will be invisible. */
  89. virtual void setVisible(bool visible) = 0;
  90. //! Returns if the cursor is currently visible.
  91. /** \return True if the cursor flag is set to visible, false if not. */
  92. virtual bool isVisible() const = 0;
  93. //! Sets the new position of the cursor.
  94. /** The position must be
  95. between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
  96. the top left corner and (1.0f, 1.0f) is the bottom right corner of the
  97. render window.
  98. \param pos New position of the cursor. */
  99. virtual void setPosition(const core::position2d<f32> &pos) = 0;
  100. //! Sets the new position of the cursor.
  101. /** The position must be
  102. between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
  103. the top left corner and (1.0f, 1.0f) is the bottom right corner of the
  104. render window.
  105. \param x New x-coord of the cursor.
  106. \param y New x-coord of the cursor. */
  107. virtual void setPosition(f32 x, f32 y) = 0;
  108. //! Sets the new position of the cursor.
  109. /** \param pos: New position of the cursor. The coordinates are pixel units. */
  110. virtual void setPosition(const core::position2d<s32> &pos) = 0;
  111. //! Sets the new position of the cursor.
  112. /** \param x New x-coord of the cursor. The coordinates are pixel units.
  113. \param y New y-coord of the cursor. The coordinates are pixel units. */
  114. virtual void setPosition(s32 x, s32 y) = 0;
  115. //! Returns the current position of the mouse cursor.
  116. /** \param updateCursor When true ask system/OS for current cursor position.
  117. When false return the last known (buffered) position ( this is useful to
  118. check what has become of a setPosition call with float numbers).
  119. \return Returns the current position of the cursor. The returned position
  120. is the position of the mouse cursor in pixel units. */
  121. virtual const core::position2d<s32>& getPosition(bool updateCursor=true) = 0;
  122. //! Returns the current position of the mouse cursor.
  123. /** \param updateCursor When true ask system/OS for current cursor position.
  124. When false return the last known (buffered) position (this is
  125. useful to check what has become of a setPosition call with float numbers
  126. and is often different from the values you passed in setPosition).
  127. \return Returns the current position of the cursor. The returned position
  128. is a value between (0.0f, 0.0f) and (1.0f, 1.0f), where (0.0f, 0.0f) is
  129. the top left corner and (1.0f, 1.0f) is the bottom right corner of the
  130. render window. */
  131. virtual core::position2d<f32> getRelativePosition(bool updateCursor=true) = 0;
  132. //! Sets an absolute reference rect for setting and retrieving the cursor position.
  133. /** If this rect is set, the cursor position is not being calculated relative to
  134. the rendering window but to this rect. You can set the rect pointer to 0 to disable
  135. this feature again. This feature is useful when rendering into parts of foreign windows
  136. for example in an editor.
  137. \param rect: A pointer to an reference rectangle or 0 to disable the reference rectangle.*/
  138. virtual void setReferenceRect(core::rect<s32>* rect=0) = 0;
  139. //! Returns the current absolute reference rect used for the cursor position
  140. /** \param rect Will receive the reference rectangle when the function returns true
  141. When the result is false drivers can still write some platform specific values in there.
  142. Generally at least the width/height of the returned rect will correspond to the current window size.
  143. \return Return true when a reference rectangle has been set and is used by this driver */
  144. virtual bool getReferenceRect(core::rect<s32>& rect) { return false; }
  145. //! Sets the active cursor icon
  146. /** Setting cursor icons is so far only supported on Win32 and Linux */
  147. virtual void setActiveIcon(ECURSOR_ICON iconId) {}
  148. //! Gets the currently active icon
  149. virtual ECURSOR_ICON getActiveIcon() const { return gui::ECI_NORMAL; }
  150. //! Add a custom sprite as cursor icon.
  151. /** \return Identification for the icon */
  152. virtual ECURSOR_ICON addIcon(const gui::SCursorSprite& icon) { return gui::ECI_NORMAL; }
  153. //! replace a cursor icon.
  154. /** Changing cursor icons is so far only supported on Win32 and Linux
  155. Note that this only changes the icons within your application, system cursors outside your
  156. application will not be affected.
  157. */
  158. virtual void changeIcon(ECURSOR_ICON iconId, const gui::SCursorSprite& sprite) {}
  159. //! Return a system-specific size which is supported for cursors. Larger icons will fail, smaller icons might work.
  160. virtual core::dimension2di getSupportedIconSize() const { return core::dimension2di(0,0); }
  161. //! Set platform specific behavior flags.
  162. virtual void setPlatformBehavior(ECURSOR_PLATFORM_BEHAVIOR behavior) {}
  163. //! Return platform specific behavior.
  164. /** \return Behavior set by setPlatformBehavior or ECPB_NONE for platforms not implementing specific behaviors.
  165. */
  166. virtual ECURSOR_PLATFORM_BEHAVIOR getPlatformBehavior() const { return ECPB_NONE; }
  167. };
  168. } // end namespace gui
  169. } // end namespace irr
  170. #endif