ICursorControl.h 7.2 KB

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