BsCursor.h 3.9 KB

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