Cursor.cs 5.6 KB

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