GUISlider.cs 6.6 KB

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