GUISlider.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// A GUI element that represents a horizontal slider with a draggable handle.
  7. /// </summary>
  8. public sealed class GUISliderH : GUIElement
  9. {
  10. public delegate void OnChangedDelegate(float percent);
  11. /// <summary>
  12. /// Triggered when the slider handle moves. Provided parameter represents
  13. /// the position of the handle, in percent ranging [0, 1].
  14. /// </summary>
  15. public event OnChangedDelegate OnChanged;
  16. /// <summary>
  17. /// Returns the position of the slider handle, in percent ranging [0, 1].
  18. /// </summary>
  19. public float Percent
  20. {
  21. get { return Internal_GetPercent(mCachedPtr); }
  22. set { Internal_SetPercent(mCachedPtr, value); }
  23. }
  24. /// <summary>
  25. /// Returns the position of the slider handle, in range determined by <see cref="SetRange"/>. If range is not defined
  26. /// set to [0, 1] this is equivalent of <see cref="Percent"/>.
  27. /// </summary>
  28. public float Value
  29. {
  30. get { return Internal_GetValue(mCachedPtr); }
  31. set { Internal_SetValue(mCachedPtr, value); }
  32. }
  33. /// <summary>
  34. /// Creates a new horizontal slider.
  35. /// </summary>
  36. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  37. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  38. /// default element style is used.</param>
  39. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  40. /// override any similar options set by style.</param>
  41. public GUISliderH(string style, params GUIOption[] options)
  42. {
  43. Internal_CreateInstance(this, style, options);
  44. }
  45. /// <summary>
  46. /// Creates a new vertical slider.
  47. /// </summary>
  48. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  49. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  50. /// default element style is used.</param>
  51. public GUISliderH(string style = "")
  52. {
  53. Internal_CreateInstance(this, style, new GUIOption[0]);
  54. }
  55. /// <summary>
  56. /// Sets a range that will input field values will be clamped to. Set to large negative/positive values if clamping
  57. /// is not required.
  58. /// </summary>
  59. /// <param name="min">Minimum boundary of the range to clamp values to.</param>
  60. /// <param name="max">Maximum boundary of the range to clamp values to.</param>
  61. public void SetRange(float min, float max)
  62. {
  63. Internal_SetRange(mCachedPtr, min, max);
  64. }
  65. /// <summary>
  66. /// Sets a step value that determines the minimal increment the slider can be increased or decreased by.
  67. /// </summary>
  68. /// <param name="step">Step value in percent if range is not defined, otherwise in same units as the range.</param>
  69. public void SetStep(float step)
  70. {
  71. Internal_SetStep(mCachedPtr, step);
  72. }
  73. /// <summary>
  74. /// Colors the element with a specific tint.
  75. /// </summary>
  76. /// <param name="color">Tint to apply to the element.</param>
  77. public void SetTint(Color color)
  78. {
  79. Internal_SetTint(mCachedPtr, ref color);
  80. }
  81. /// <summary>
  82. /// Triggered by the native interop object when the slider handle is moved.
  83. /// </summary>
  84. /// <param name="percent">New position of the slider handle, in percent ranging [0, 1].</param>
  85. private void DoOnChanged(float percent)
  86. {
  87. if (OnChanged != null)
  88. OnChanged(percent);
  89. }
  90. [MethodImpl(MethodImplOptions.InternalCall)]
  91. private static extern void Internal_CreateInstance(GUISliderH instance, string style, GUIOption[] options);
  92. [MethodImpl(MethodImplOptions.InternalCall)]
  93. private static extern float Internal_GetPercent(IntPtr nativeInstance);
  94. [MethodImpl(MethodImplOptions.InternalCall)]
  95. private static extern void Internal_SetPercent(IntPtr nativeInstance, float percent);
  96. [MethodImpl(MethodImplOptions.InternalCall)]
  97. private static extern float Internal_GetValue(IntPtr nativeInstance);
  98. [MethodImpl(MethodImplOptions.InternalCall)]
  99. private static extern void Internal_SetValue(IntPtr nativeInstance, float percent);
  100. [MethodImpl(MethodImplOptions.InternalCall)]
  101. private static extern void Internal_SetRange(IntPtr nativeInstance, float min, float max);
  102. [MethodImpl(MethodImplOptions.InternalCall)]
  103. private static extern void Internal_SetStep(IntPtr nativeInstance, float step);
  104. [MethodImpl(MethodImplOptions.InternalCall)]
  105. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  106. }
  107. /// <summary>
  108. /// A GUI element that represents a vertical slider with a draggable handle.
  109. /// </summary>
  110. public sealed class GUISliderV : GUIElement
  111. {
  112. public delegate void OnChangedDelegate(float percent);
  113. /// <summary>
  114. /// Triggered when the slider handle moves. Provided parameter represents
  115. /// the position of the handle, in percent ranging [0, 1].
  116. /// </summary>
  117. public event OnChangedDelegate OnChanged;
  118. /// <summary>
  119. /// Returns the position of the slider handle, in percent ranging [0, 1].
  120. /// </summary>
  121. public float Percent
  122. {
  123. get { return Internal_GetPercent(mCachedPtr); }
  124. set { Internal_SetPercent(mCachedPtr, value); }
  125. }
  126. /// <summary>
  127. /// Returns the position of the slider handle, in range determined by <see cref="SetRange"/>. If range is not defined
  128. /// set to [0, 1] this is equivalent of <see cref="Percent"/>.
  129. /// </summary>
  130. public float Value
  131. {
  132. get { return Internal_GetValue(mCachedPtr); }
  133. set { Internal_SetValue(mCachedPtr, value); }
  134. }
  135. /// <summary>
  136. /// Creates a new vertical slider.
  137. /// </summary>
  138. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  139. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  140. /// default element style is used.</param>
  141. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  142. /// override any similar options set by style.</param>
  143. public GUISliderV(string style, params GUIOption[] options)
  144. {
  145. Internal_CreateInstance(this, style, options);
  146. }
  147. /// <summary>
  148. /// Creates a new vertical slider.
  149. /// </summary>
  150. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  151. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  152. /// default element style is used.</param>
  153. public GUISliderV(string style = "")
  154. {
  155. Internal_CreateInstance(this, style, new GUIOption[0]);
  156. }
  157. /// <summary>
  158. /// Sets a range that will input field values will be clamped to. Set to large negative/positive values if clamping
  159. /// is not required.
  160. /// </summary>
  161. /// <param name="min">Minimum boundary of the range to clamp values to.</param>
  162. /// <param name="max">Maximum boundary of the range to clamp values to.</param>
  163. public void SetRange(float min, float max)
  164. {
  165. Internal_SetRange(mCachedPtr, min, max);
  166. }
  167. /// <summary>
  168. /// Sets a step value that determines the minimal increment the slider can be increased or decreased by.
  169. /// </summary>
  170. /// <param name="step">Step value in percent if range is not defined, otherwise in same units as the range.</param>
  171. public void SetStep(float step)
  172. {
  173. Internal_SetStep(mCachedPtr, step);
  174. }
  175. /// <summary>
  176. /// Colors the element with a specific tint.
  177. /// </summary>
  178. /// <param name="color">Tint to apply to the element.</param>
  179. public void SetTint(Color color)
  180. {
  181. Internal_SetTint(mCachedPtr, ref color);
  182. }
  183. /// <summary>
  184. /// Triggered by the native interop object when the slider handle is moved.
  185. /// </summary>
  186. /// <param name="percent">New position of the slider handle, in percent ranging [0, 1].</param>
  187. private void DoOnChanged(float percent)
  188. {
  189. if (OnChanged != null)
  190. OnChanged(percent);
  191. }
  192. [MethodImpl(MethodImplOptions.InternalCall)]
  193. private static extern void Internal_CreateInstance(GUISliderV instance, string style, GUIOption[] options);
  194. [MethodImpl(MethodImplOptions.InternalCall)]
  195. private static extern float Internal_GetPercent(IntPtr nativeInstance);
  196. [MethodImpl(MethodImplOptions.InternalCall)]
  197. private static extern void Internal_SetPercent(IntPtr nativeInstance, float percent);
  198. [MethodImpl(MethodImplOptions.InternalCall)]
  199. private static extern float Internal_GetValue(IntPtr nativeInstance);
  200. [MethodImpl(MethodImplOptions.InternalCall)]
  201. private static extern void Internal_SetValue(IntPtr nativeInstance, float percent);
  202. [MethodImpl(MethodImplOptions.InternalCall)]
  203. private static extern void Internal_SetRange(IntPtr nativeInstance, float min, float max);
  204. [MethodImpl(MethodImplOptions.InternalCall)]
  205. private static extern void Internal_SetStep(IntPtr nativeInstance, float step);
  206. [MethodImpl(MethodImplOptions.InternalCall)]
  207. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  208. }
  209. }