BsCursor.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsPixelData.h"
  5. #include "BsVector2I.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Allows you to manipulate the platform cursor in various ways.
  10. *
  11. * @note Thread safe.
  12. */
  13. class BS_EXPORT Cursor : public Module<Cursor>
  14. {
  15. /**
  16. * @brief Internal container for data about a single cursor icon.
  17. */
  18. struct CustomIcon
  19. {
  20. CustomIcon() {}
  21. CustomIcon(const PixelData& pixelData, const Vector2I& hotSpot)
  22. :hotSpot(hotSpot), pixelData(pixelData)
  23. { }
  24. Vector2I hotSpot;
  25. PixelData pixelData;
  26. };
  27. public:
  28. Cursor();
  29. /**
  30. * @brief Moves the cursor to the specified screen position.
  31. */
  32. void setScreenPosition(const Vector2I& screenPos);
  33. /**
  34. * @brief Retrieves the cursor position in screen coordinates.
  35. */
  36. Vector2I getScreenPosition();
  37. /**
  38. * @brief Hides the cursor.
  39. */
  40. void hide();
  41. /**
  42. * @brief Shows the cursor.
  43. */
  44. void show();
  45. /**
  46. * @brief Limit cursor movement to the specified window.
  47. */
  48. void clipToWindow(const RenderWindow& window);
  49. /**
  50. * @brief Limit cursor movement to specific area on the screen.
  51. */
  52. void clipToRect(const Rect2I& screenRect);
  53. /**
  54. * @brief Disables cursor clipping that was set using any of the "clipTo*" methods.
  55. */
  56. void clipDisable();
  57. /**
  58. * @brief Sets a cursor icon. Uses one of the built-in cursor types.
  59. */
  60. void setCursor(CursorType type);
  61. /**
  62. * @brief Sets a cursor icon. Uses one of the manually registered icons.
  63. *
  64. * @param name The name to identify the cursor, one set previously by calling "setCursorIcon".
  65. */
  66. void setCursor(const String& name);
  67. /**
  68. * @brief Registers a new custom cursor icon you can then set by calling "setCursor".
  69. *
  70. * @param name The name to identify the cursor.
  71. * @param pixelData Cursor image data.
  72. * @param hotSpot Offset on the cursor image to where the actual input happens (e.g. tip of the Arrow cursor).
  73. *
  74. * @note Stores an internal copy of the pixel data. Clear it by calling "removeCursorIcon".
  75. * If a custom icon with the same name already exists it will be replaced.
  76. */
  77. void setCursorIcon(const String& name, const PixelData& pixelData, const Vector2I& hotSpot);
  78. /**
  79. * @brief Registers a new custom cursor icon you can then set by calling "setCursor".
  80. *
  81. * @param type One of the built-in cursor types.
  82. * @param pixelData Cursor image data.
  83. * @param hotSpot Offset on the cursor image to where the actual input happens (e.g. tip of the Arrow cursor).
  84. *
  85. * @note Stores an internal copy of the pixel data. Clear it by calling "removeCursorIcon".
  86. * If a custom icon with the same type already exists it will be replaced.
  87. */
  88. void setCursorIcon(CursorType type, const PixelData& pixelData, const Vector2I& hotSpot);
  89. /**
  90. * @brief Removes a custom cursor icon and releases any data associated with it.
  91. */
  92. void clearCursorIcon(const String& name);
  93. /**
  94. * @brief Removes a custom cursor icon and releases any data associated with it. Restores
  95. * original icon associated with this cursor type.
  96. */
  97. void clearCursorIcon(CursorType type);
  98. private:
  99. /**
  100. * @brief Restores the default cursor icon for the specified cursor type.
  101. */
  102. void restoreCursorIcon(CursorType type);
  103. /**
  104. * @brief Sends the cursor image to the OS, making it active.
  105. */
  106. void updateCursorImage();
  107. UnorderedMap<String, UINT32> mCustomIconNameToId;
  108. UnorderedMap<UINT32, CustomIcon> mCustomIcons;
  109. UINT32 mNextUniqueId;
  110. INT32 mActiveCursorId;
  111. };
  112. }