Cursor.cs 6.0 KB

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