GUISlider.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /// Creates a new horizontal slider.
  26. /// </summary>
  27. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  28. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  29. /// is used.
  30. /// </param>
  31. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  32. /// override any similar options set by style.
  33. /// </param>
  34. public GUISliderH(string style, params GUIOption[] options)
  35. {
  36. Internal_CreateInstance(this, style, options);
  37. }
  38. /// <summary>
  39. /// Creates a new vertical 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 default element style
  43. /// is used.
  44. /// </param>
  45. public GUISliderH(string style = "")
  46. {
  47. Internal_CreateInstance(this, style, new GUIOption[0]);
  48. }
  49. /// <summary>
  50. /// Colors the element with a specific tint.
  51. /// </summary>
  52. /// <param name="color">Tint to apply to the element.</param>
  53. public void SetTint(Color color)
  54. {
  55. Internal_SetTint(mCachedPtr, color);
  56. }
  57. /// <summary>
  58. /// Triggered by the native interop object when the slider handle is moved.
  59. /// </summary>
  60. /// <param name="percent">New position of the slider handle, in percent ranging [0, 1].</param>
  61. private void DoOnChanged(float percent)
  62. {
  63. if (OnChanged != null)
  64. OnChanged(percent);
  65. }
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_CreateInstance(GUISliderH instance, string style, GUIOption[] options);
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern float Internal_GetPercent(IntPtr nativeInstance);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern void Internal_SetPercent(IntPtr nativeInstance, float percent);
  72. [MethodImpl(MethodImplOptions.InternalCall)]
  73. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  74. }
  75. /// <summary>
  76. /// A GUI element that represents a vertical slider with a draggable handle.
  77. /// </summary>
  78. public sealed class GUISliderV : GUIElement
  79. {
  80. public delegate void OnChangedDelegate(float percent);
  81. /// <summary>
  82. /// Triggered when the slider handle moves. Provided parameter represents
  83. /// the position of the handle, in percent ranging [0, 1].
  84. /// </summary>
  85. public event OnChangedDelegate OnChanged;
  86. /// <summary>
  87. /// Returns the position of the slider handle, in percent ranging [0, 1].
  88. /// </summary>
  89. public float Percent
  90. {
  91. get { return Internal_GetPercent(mCachedPtr); }
  92. set { Internal_SetPercent(mCachedPtr, value); }
  93. }
  94. /// <summary>
  95. /// Creates a new vertical slider.
  96. /// </summary>
  97. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  98. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  99. /// is used.
  100. /// </param>
  101. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  102. /// override any similar options set by style.
  103. /// </param>
  104. public GUISliderV(string style, params GUIOption[] options)
  105. {
  106. Internal_CreateInstance(this, style, options);
  107. }
  108. /// <summary>
  109. /// Creates a new vertical slider.
  110. /// </summary>
  111. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  112. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  113. /// is used.
  114. /// </param>
  115. public GUISliderV(string style = "")
  116. {
  117. Internal_CreateInstance(this, style, new GUIOption[0]);
  118. }
  119. /// <summary>
  120. /// Colors the element with a specific tint.
  121. /// </summary>
  122. /// <param name="color">Tint to apply to the element.</param>
  123. public void SetTint(Color color)
  124. {
  125. Internal_SetTint(mCachedPtr, color);
  126. }
  127. /// <summary>
  128. /// Triggered by the native interop object when the slider handle is moved.
  129. /// </summary>
  130. /// <param name="percent">New position of the slider handle, in percent ranging [0, 1].</param>
  131. private void DoOnChanged(float percent)
  132. {
  133. if (OnChanged != null)
  134. OnChanged(percent);
  135. }
  136. [MethodImpl(MethodImplOptions.InternalCall)]
  137. private static extern void Internal_CreateInstance(GUISliderV instance, string style, GUIOption[] options);
  138. [MethodImpl(MethodImplOptions.InternalCall)]
  139. private static extern float Internal_GetPercent(IntPtr nativeInstance);
  140. [MethodImpl(MethodImplOptions.InternalCall)]
  141. private static extern void Internal_SetPercent(IntPtr nativeInstance, float percent);
  142. [MethodImpl(MethodImplOptions.InternalCall)]
  143. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  144. }
  145. }