GUIScrollArea.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /// <summary>
  8. /// Scroll bar options for a GUI scroll area.
  9. /// </summary>
  10. public enum ScrollBarType // Note: Must match the C++ enum ScrollBarType
  11. {
  12. ShowIfDoesntFit,
  13. AlwaysShow,
  14. NeverShow
  15. };
  16. /// <summary>
  17. /// A GUI element container with support for vertical & horizontal scrolling.
  18. /// </summary>
  19. public sealed class GUIScrollArea : GUIElement
  20. {
  21. private GUILayout _mainLayout;
  22. /// <summary>
  23. /// Default vertical layout into which you should place elements that need to be scrollable.
  24. /// </summary>
  25. public GUILayout Layout
  26. {
  27. get { return _mainLayout; }
  28. }
  29. /// <summary>
  30. /// Position of the horizontal scroll bar, ranging [0, 1]. When bar is fully to the left (no scroll) the value is
  31. /// zero, and when the bar is fully to the right (full scroll) the value is one.
  32. /// </summary>
  33. public float HorizontalScroll
  34. {
  35. get { return Internal_GetHorzScroll(mCachedPtr); }
  36. set { Internal_SetHorzScroll(mCachedPtr, value); }
  37. }
  38. /// <summary>
  39. /// Position of the vertical scroll bar, ranging [0, 1]. When bar is fully to the top (no scroll) the value is
  40. /// zero, and when the bar is fully to the bottom (full scroll) the value is one.
  41. /// </summary>
  42. public float VerticalScroll
  43. {
  44. get { return Internal_GetVertScroll(mCachedPtr); }
  45. set { Internal_SetVertScroll(mCachedPtr, value); }
  46. }
  47. /// <summary>
  48. /// Returns the bounds of the scroll area not including the scroll bars. (i.e. only the portion that contains the
  49. /// contents).
  50. /// </summary>
  51. public Rect2I ContentBounds
  52. {
  53. get
  54. {
  55. Rect2I bounds;
  56. Internal_GetContentBounds(mCachedPtr, out bounds);
  57. return bounds;
  58. }
  59. }
  60. /// <summary>
  61. /// Number of pixels the scroll bar will occupy when active. This is width for vertical scrollbar, and height for
  62. /// horizontal scrollbar.
  63. /// </summary>
  64. public int ScrollBarWidth
  65. {
  66. get { return Internal_GetScrollBarWidth(mCachedPtr); }
  67. }
  68. /// <summary>
  69. /// Creates a new scroll area.
  70. /// </summary>
  71. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  72. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  73. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved
  74. /// from the active GUISkin. If not specified default element style is used.</param>
  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. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  79. /// override any similar options set by style.</param>
  80. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string scrollBarStyle,
  81. string style, params GUIOption[] options)
  82. {
  83. Internal_CreateInstance(this, vertBarType, horzBarType, scrollBarStyle, style, options);
  84. _mainLayout = new GUILayoutY(this);
  85. }
  86. /// <summary>
  87. /// Creates a new scroll area.
  88. /// </summary>
  89. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  90. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  91. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  92. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  93. /// default element style is used.</param>
  94. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  95. /// override any similar options set by style.</param>
  96. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string style, params GUIOption[] options)
  97. {
  98. Internal_CreateInstance(this, vertBarType, horzBarType, "", style, options);
  99. _mainLayout = new GUILayoutY(this);
  100. }
  101. /// <summary>
  102. /// Creates a new scroll area.
  103. /// </summary>
  104. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  105. /// <param name="horzBarType">Type of the horizontal scroll bar.</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 GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
  109. {
  110. Internal_CreateInstance(this, vertBarType, horzBarType, "", "", options);
  111. _mainLayout = new GUILayoutY(this);
  112. }
  113. /// <summary>
  114. /// Creates a new scroll area.
  115. /// </summary>
  116. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  117. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  118. /// default element style is used.</param>
  119. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  120. /// override any similar options set by style.</param>
  121. public GUIScrollArea(string style, params GUIOption[] options)
  122. {
  123. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", style, options);
  124. _mainLayout = new GUILayoutY(this);
  125. }
  126. /// <summary>
  127. /// Creates a new scroll area.
  128. /// </summary>
  129. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  130. /// override any similar options set by style.</param>
  131. public GUIScrollArea(params GUIOption[] options)
  132. {
  133. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", "", options);
  134. _mainLayout = new GUILayoutY(this);
  135. }
  136. /// <summary>
  137. /// Creates a new scroll area.
  138. /// </summary>
  139. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved
  140. /// from the active GUISkin. If not specified 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 GUIScrollArea(string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options)
  144. {
  145. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
  146. _mainLayout = new GUILayoutY(this);
  147. }
  148. /// <inheritdoc/>
  149. public override void Destroy()
  150. {
  151. _mainLayout.Destroy();
  152. base.Destroy();
  153. }
  154. [MethodImpl(MethodImplOptions.InternalCall)]
  155. private static extern void Internal_CreateInstance(GUIScrollArea instance, ScrollBarType vertBarType, ScrollBarType horzBarType,
  156. string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options);
  157. [MethodImpl(MethodImplOptions.InternalCall)]
  158. private static extern void Internal_GetContentBounds(IntPtr nativeInstance, out Rect2I value);
  159. [MethodImpl(MethodImplOptions.InternalCall)]
  160. private static extern float Internal_GetHorzScroll(IntPtr nativeInstance);
  161. [MethodImpl(MethodImplOptions.InternalCall)]
  162. private static extern void Internal_SetHorzScroll(IntPtr nativeInstance, float value);
  163. [MethodImpl(MethodImplOptions.InternalCall)]
  164. private static extern float Internal_GetVertScroll(IntPtr nativeInstance);
  165. [MethodImpl(MethodImplOptions.InternalCall)]
  166. private static extern void Internal_SetVertScroll(IntPtr nativeInstance, float value);
  167. [MethodImpl(MethodImplOptions.InternalCall)]
  168. private static extern int Internal_GetScrollBarWidth(IntPtr nativeInstance);
  169. }
  170. }