GUIScrollBar.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. /// GUI element representing an element with a draggable handle of a variable size.
  12. /// </summary>
  13. public class GUIScrollBar : GUIElement
  14. {
  15. /// <summary>
  16. /// Position of the scroll handle in percent (ranging [0, 1]).
  17. /// </summary>
  18. public float Position
  19. {
  20. get { return Internal_GetPosition(mCachedPtr); }
  21. set { Internal_SetPosition(mCachedPtr, value); }
  22. }
  23. /// <summary>
  24. /// Size of the scroll handle in percent (ranging [0, 1]) of the total scroll bar area.
  25. /// </summary>
  26. public float HandleSize
  27. {
  28. get { return Internal_GetHandleSize(mCachedPtr); }
  29. set { Internal_SetHandleSize(mCachedPtr, value); }
  30. }
  31. /// <summary>
  32. /// Colors the element with a specific tint.
  33. /// </summary>
  34. /// <param name="color">Tint to apply to the element.</param>
  35. public void SetTint(Color color)
  36. {
  37. Internal_SetTint(mCachedPtr, ref color);
  38. }
  39. [MethodImpl(MethodImplOptions.InternalCall)]
  40. private static extern float Internal_GetPosition(IntPtr nativeInstance);
  41. [MethodImpl(MethodImplOptions.InternalCall)]
  42. private static extern void Internal_SetPosition(IntPtr nativeInstance, float percent);
  43. [MethodImpl(MethodImplOptions.InternalCall)]
  44. private static extern float Internal_GetHandleSize(IntPtr nativeInstance);
  45. [MethodImpl(MethodImplOptions.InternalCall)]
  46. private static extern void Internal_SetHandleSize(IntPtr nativeInstance, float percent);
  47. [MethodImpl(MethodImplOptions.InternalCall)]
  48. private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
  49. }
  50. /// <summary>
  51. /// GUI element representing a horizontal scroll bar.
  52. /// </summary>
  53. public sealed class GUIScrollBarH : GUIScrollBar
  54. {
  55. /// <summary>
  56. /// Event triggered whenever the user moves the scroll bar. Value reported is the position of the scroll bar handle
  57. /// in percent, in [0, 1] range.
  58. /// </summary>
  59. public event Action<float> OnScroll;
  60. /// <summary>
  61. /// Creates a new horizontal scroll bar element.
  62. /// </summary>
  63. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  64. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  65. /// default element style is used.</param>
  66. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  67. /// override any similar options set by style.</param>
  68. public GUIScrollBarH(string style, params GUIOption[] options)
  69. {
  70. Internal_CreateInstance(this, style, options);
  71. }
  72. /// <summary>
  73. /// Creates a new horizontal scroll bar element.
  74. /// </summary>
  75. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  76. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  77. /// default element style is used.</param>
  78. public GUIScrollBarH(string style = "")
  79. {
  80. Internal_CreateInstance(this, style, new GUIOption[0]);
  81. }
  82. private void Internal_DoOnScroll(float position)
  83. {
  84. if (OnScroll != null)
  85. OnScroll(position);
  86. }
  87. [MethodImpl(MethodImplOptions.InternalCall)]
  88. private static extern void Internal_CreateInstance(GUIScrollBarH instance, string style, GUIOption[] options);
  89. }
  90. /// <summary>
  91. /// GUI element representing a vertical scroll bar.
  92. /// </summary>
  93. public sealed class GUIScrollBarV : GUIScrollBar
  94. {
  95. /// <summary>
  96. /// Event triggered whenever the user moves the scroll bar. Value reported is the position of the scroll bar handle
  97. /// in percent, in [0, 1] range.
  98. /// </summary>
  99. public event Action<float> OnScroll;
  100. /// <summary>
  101. /// Creates a new vertical scroll bar element.
  102. /// </summary>
  103. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  104. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  105. /// default element style is used.</param>
  106. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  107. /// override any similar options set by style.</param>
  108. public GUIScrollBarV(string style, params GUIOption[] options)
  109. {
  110. Internal_CreateInstance(this, style, options);
  111. }
  112. /// <summary>
  113. /// Creates a new vertical scroll bar element.
  114. /// </summary>
  115. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  116. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  117. /// default element style is used.</param>
  118. public GUIScrollBarV(string style = "")
  119. {
  120. Internal_CreateInstance(this, style, new GUIOption[0]);
  121. }
  122. private void Internal_DoOnScroll(float position)
  123. {
  124. if (OnScroll != null)
  125. OnScroll(position);
  126. }
  127. [MethodImpl(MethodImplOptions.InternalCall)]
  128. private static extern void Internal_CreateInstance(GUIScrollBarV instance, string style, GUIOption[] options);
  129. }
  130. /// <summary>
  131. /// GUI element representing a horizontal scroll bar, with resize handles that allow the user to resize the visible
  132. /// scroll area.
  133. /// </summary>
  134. public sealed class GUIResizeableScrollBarH : GUIScrollBar
  135. {
  136. /// <summary>
  137. /// Event triggered whenever the user moves or resizes the scroll bar. Value reported is the position and size of
  138. /// the scroll bar handle in percent, in [0, 1] range.
  139. /// </summary>
  140. public event Action<float, float> OnScrollOrResize;
  141. /// <summary>
  142. /// Creates a new resizeable horizontal scroll bar element.
  143. /// </summary>
  144. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  145. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  146. /// default element style is used.</param>
  147. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  148. /// override any similar options set by style.</param>
  149. public GUIResizeableScrollBarH(string style, params GUIOption[] options)
  150. {
  151. Internal_CreateInstance(this, style, options);
  152. }
  153. /// <summary>
  154. /// Creates a new resizeable horizontal scroll bar element.
  155. /// </summary>
  156. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  157. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  158. /// default element style is used.</param>
  159. public GUIResizeableScrollBarH(string style = "")
  160. {
  161. Internal_CreateInstance(this, style, new GUIOption[0]);
  162. }
  163. private void Internal_DoOnScrollOrResize(float percent, float size)
  164. {
  165. if (OnScrollOrResize != null)
  166. OnScrollOrResize(percent, size);
  167. }
  168. [MethodImpl(MethodImplOptions.InternalCall)]
  169. private static extern void Internal_CreateInstance(GUIResizeableScrollBarH instance, string style, GUIOption[] options);
  170. }
  171. /// <summary>
  172. /// GUI element representing a vertical scroll bar, with resize handles that allow the user to resize the visible
  173. /// scroll area.
  174. /// </summary>
  175. public sealed class GUIResizeableScrollBarV : GUIScrollBar
  176. {
  177. /// <summary>
  178. /// Event triggered whenever the user moves or resizes the scroll bar. Value reported is the position and size of
  179. /// the scroll bar handle in percent, in [0, 1] range.
  180. /// </summary>
  181. public event Action<float, float> OnScrollOrResize;
  182. /// <summary>
  183. /// Creates a new resizeable vertical scroll bar element.
  184. /// </summary>
  185. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  186. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  187. /// default element style is used.</param>
  188. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  189. /// override any similar options set by style.</param>
  190. public GUIResizeableScrollBarV(string style, params GUIOption[] options)
  191. {
  192. Internal_CreateInstance(this, style, options);
  193. }
  194. /// <summary>
  195. /// Creates a new resizeable vertical scroll bar element.
  196. /// </summary>
  197. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  198. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  199. /// default element style is used.</param>
  200. public GUIResizeableScrollBarV(string style = "")
  201. {
  202. Internal_CreateInstance(this, style, new GUIOption[0]);
  203. }
  204. private void Internal_DoOnScrollOrResize(float percent, float size)
  205. {
  206. if (OnScrollOrResize != null)
  207. OnScrollOrResize(percent, size);
  208. }
  209. [MethodImpl(MethodImplOptions.InternalCall)]
  210. private static extern void Internal_CreateInstance(GUIResizeableScrollBarV instance, string style, GUIOption[] options);
  211. }
  212. /** @} */
  213. }