Cursor.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Runtime.CompilerServices;
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup Utility
  7. * @{
  8. */
  9. /// <summary>
  10. /// Allows manipulation of the platform cursor.
  11. /// </summary>
  12. public static class Cursor
  13. {
  14. /// <summary>
  15. /// Position of the cursor in screen coordinates.
  16. /// </summary>
  17. public static Vector2I ScreenPosition
  18. {
  19. get
  20. {
  21. Vector2I value;
  22. Internal_GetScreenPosition(out value);
  23. return value;
  24. }
  25. set
  26. {
  27. Internal_SetScreenPosition(ref value);
  28. }
  29. }
  30. /// <summary>
  31. /// Hides the cursor.
  32. /// </summary>
  33. public static void Hide()
  34. {
  35. Internal_Hide();
  36. }
  37. /// <summary>
  38. /// Shows the cursor.
  39. /// </summary>
  40. public static void Show()
  41. {
  42. Internal_Show();
  43. }
  44. /// <summary>
  45. /// Clips the cursor to the specified area. Enabled until <see cref="ClipDisable"/> is called.
  46. /// </summary>
  47. /// <param name="area">Area in screen space to clip the cursor to.</param>
  48. public static void ClipToRect(Rect2I area)
  49. {
  50. Internal_ClipToRect(ref area);
  51. }
  52. /// <summary>
  53. /// Disables cursor clipping previously enabled with <see cref="ClipToRect"/>.
  54. /// </summary>
  55. public static void ClipDisable()
  56. {
  57. Internal_ClipDisable();
  58. }
  59. /// <summary>
  60. /// Changes the active cursor icon.
  61. /// </summary>
  62. /// <param name="name">Name of the cursor icon, previously registered with
  63. /// <see cref="SetCursorIcon(string,PixelData,Vector2I)"/></param>
  64. public static void SetCursor(string name)
  65. {
  66. Internal_SetCursorStr(name);
  67. }
  68. /// <summary>
  69. /// Changes the active cursor icon.
  70. /// </summary>
  71. /// <param name="type">One of the built-in cursor types.</param>
  72. public static void SetCursor(CursorType type)
  73. {
  74. Internal_SetCursor(type);
  75. }
  76. /// <summary>
  77. /// Updates the look of a specific cursor icon.
  78. /// </summary>
  79. /// <param name="name">Name of the cursor.</param>
  80. /// <param name="iconData">Pixel data specifying the new look.</param>
  81. /// <param name="hotspot">Offset into the icon image that determines where the cursor point is.</param>
  82. public static void SetCursorIcon(string name, PixelData iconData, Vector2I hotspot)
  83. {
  84. Internal_SetCursorIconStr(name, iconData, ref hotspot);
  85. }
  86. /// <summary>
  87. /// Updates the look of a specific cursor icon.
  88. /// </summary>
  89. /// <param name="type">One of the built-in cursor types.</param>
  90. /// <param name="iconData">Pixel data specifying the new look.</param>
  91. /// <param name="hotspot">Offset into the icon image that determines where the cursor point is.</param>
  92. public static void SetCursorIcon(CursorType type, PixelData iconData, Vector2I hotspot)
  93. {
  94. Internal_SetCursorIcon(type, iconData, ref hotspot);
  95. }
  96. /// <summary>
  97. /// Removes a cursor icon.
  98. /// </summary>
  99. /// <param name="name">Name of the cursor.</param>
  100. public static void ClearCursorIcon(string name)
  101. {
  102. Internal_ClearCursorIconStr(name);
  103. }
  104. /// <summary>
  105. /// Removes a cursor icon.
  106. /// </summary>
  107. /// <param name="type">One of the built-in cursor types.</param>
  108. public static void ClearCursorIcon(CursorType type)
  109. {
  110. Internal_ClearCursorIcon(type);
  111. }
  112. [MethodImpl(MethodImplOptions.InternalCall)]
  113. private static extern void Internal_GetScreenPosition(out Vector2I value);
  114. [MethodImpl(MethodImplOptions.InternalCall)]
  115. private static extern void Internal_SetScreenPosition(ref Vector2I value);
  116. [MethodImpl(MethodImplOptions.InternalCall)]
  117. private static extern void Internal_Hide();
  118. [MethodImpl(MethodImplOptions.InternalCall)]
  119. private static extern void Internal_Show();
  120. [MethodImpl(MethodImplOptions.InternalCall)]
  121. private static extern void Internal_ClipToRect(ref Rect2I value);
  122. [MethodImpl(MethodImplOptions.InternalCall)]
  123. private static extern void Internal_ClipDisable();
  124. [MethodImpl(MethodImplOptions.InternalCall)]
  125. private static extern void Internal_SetCursorStr(string name);
  126. [MethodImpl(MethodImplOptions.InternalCall)]
  127. private static extern void Internal_SetCursor(CursorType cursor);
  128. [MethodImpl(MethodImplOptions.InternalCall)]
  129. private static extern void Internal_SetCursorIconStr(string name, PixelData iconData, ref Vector2I hotspot);
  130. [MethodImpl(MethodImplOptions.InternalCall)]
  131. private static extern void Internal_SetCursorIcon(CursorType cursor, PixelData iconData, ref Vector2I hotspot);
  132. [MethodImpl(MethodImplOptions.InternalCall)]
  133. private static extern void Internal_ClearCursorIconStr(string name);
  134. [MethodImpl(MethodImplOptions.InternalCall)]
  135. private static extern void Internal_ClearCursorIcon(CursorType cursor);
  136. }
  137. /// <summary>
  138. /// Built-in cursor types.
  139. /// </summary>
  140. public enum CursorType //Note: Must match C++ enum CursorType
  141. {
  142. Arrow,
  143. ArrowDrag,
  144. ArrowLeftRight,
  145. Wait,
  146. IBeam,
  147. SizeNESW,
  148. SizeNS,
  149. SizeNWSE,
  150. SizeWE,
  151. Deny,
  152. // Keep at the end
  153. Count
  154. };
  155. /** @} */
  156. }