GUISlider.cs 11 KB

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