BsCursor.h 3.9 KB

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