GUIElementStyle.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. using System.Runtime.InteropServices;
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup GUI_Engine
  9. * @{
  10. */
  11. /// <summary>
  12. /// Rectangle represented in the form of offsets from some parent rectangle.
  13. /// </summary>
  14. [StructLayout(LayoutKind.Sequential)]
  15. public struct RectOffset // Note: Must match the C++ struct RectOffset
  16. {
  17. public int left, right, top, bottom;
  18. };
  19. /// <summary>
  20. /// Possible positions used for positioning content image within a GUI element.
  21. /// </summary>
  22. public enum GUIImagePosition // Note: Must match the C++ enum GUIImagePosition.
  23. {
  24. Left, Right
  25. };
  26. /// <summary>
  27. /// Specifies how is text horizontally aligned within its bounds.
  28. /// </summary>
  29. public enum TextHorzAlign // Note: Must match the C++ enum TextHorzAlign.
  30. {
  31. Left, Center, Right
  32. };
  33. /// <summary>
  34. /// Specifies how is text vertically aligned within its bounds.
  35. /// </summary>
  36. public enum TextVertAlign // Note: Must match the C++ enum TextVertAlign
  37. {
  38. Top, Center, Bottom
  39. };
  40. /// <summary>
  41. /// GUI element style that determines the look of a GUI element, as well as the element's default layout options.
  42. /// Different looks can be provided for different element states.
  43. /// </summary>
  44. [SerializeObject]
  45. public sealed class GUIElementStyle : ScriptObject
  46. {
  47. // Constructor for runtime use only (dummy parameter to differentiate from the normal constructor)
  48. private GUIElementStyle(bool dummy)
  49. { }
  50. /// <summary>
  51. /// Constructs a new GUI element style with default values.
  52. /// </summary>
  53. public GUIElementStyle()
  54. {
  55. Internal_CreateInstance(this);
  56. }
  57. /// <summary>
  58. /// Font to use for all text within the GUI element.
  59. /// </summary>
  60. public Font Font
  61. {
  62. get { Font value; Internal_GetFont(mCachedPtr, out value); return value; }
  63. set { Internal_SetFont(mCachedPtr, value); }
  64. }
  65. /// <summary>
  66. /// Font size to use for all text within the GUI element.
  67. /// </summary>
  68. public int FontSize
  69. {
  70. get { int value; Internal_GetFontSize(mCachedPtr, out value); return value; }
  71. set { Internal_SetFontSize(mCachedPtr, value); }
  72. }
  73. /// <summary>
  74. /// Horizontal alignment of text within the GUI element.
  75. /// </summary>
  76. public TextHorzAlign TextHorzAlign
  77. {
  78. get { TextHorzAlign value; Internal_GetTextHorzAlign(mCachedPtr, out value); return value; }
  79. set { Internal_SetTextHorzAlign(mCachedPtr, value); }
  80. }
  81. /// <summary>
  82. /// Vertical alignment of text within the GUI element.
  83. /// </summary>
  84. public TextVertAlign TextVertAlign
  85. {
  86. get { TextVertAlign value; Internal_GetTextVertAlign(mCachedPtr, out value); return value; }
  87. set { Internal_SetTextVertAlign(mCachedPtr, value); }
  88. }
  89. /// <summary>
  90. /// Position of content image relative to text.
  91. /// </summary>
  92. public GUIImagePosition ImagePosition
  93. {
  94. get { GUIImagePosition value; Internal_GetImagePosition(mCachedPtr, out value); return value; }
  95. set { Internal_SetImagePosition(mCachedPtr, value); }
  96. }
  97. /// <summary>
  98. /// Determines should the text word wrap if it doesn't fit in its element's bounds.
  99. /// </summary>
  100. public bool WordWrap
  101. {
  102. get { bool value; Internal_GetWordWrap(mCachedPtr, out value); return value; }
  103. set { Internal_SetWordWrap(mCachedPtr, value); }
  104. }
  105. /// <summary>
  106. /// Style used when element is in normal state and off.
  107. /// </summary>
  108. public GUIElementStateStyle Normal
  109. {
  110. get { GUIElementStateStyle value; Internal_GetNormal(mCachedPtr, out value); return value; }
  111. set { Internal_SetNormal(mCachedPtr, ref value); }
  112. }
  113. /// <summary>
  114. /// Style used when element is in hover state and off.
  115. /// </summary>
  116. public GUIElementStateStyle Hover
  117. {
  118. get { GUIElementStateStyle value; Internal_GetHover(mCachedPtr, out value); return value; }
  119. set { Internal_SetHover(mCachedPtr, ref value); }
  120. }
  121. /// <summary>
  122. /// Style used when element is in active state and off.
  123. /// </summary>
  124. public GUIElementStateStyle Active
  125. {
  126. get { GUIElementStateStyle value; Internal_GetActive(mCachedPtr, out value); return value; }
  127. set { Internal_SetActive(mCachedPtr, ref value); }
  128. }
  129. /// <summary>
  130. /// Style used when element is in focused state and off.
  131. /// </summary>
  132. public GUIElementStateStyle Focused
  133. {
  134. get { GUIElementStateStyle value; Internal_GetFocused(mCachedPtr, out value); return value; }
  135. set { Internal_SetFocused(mCachedPtr, ref value); }
  136. }
  137. /// <summary>
  138. /// Style used when element is in normal state and on.
  139. /// </summary>
  140. public GUIElementStateStyle NormalOn
  141. {
  142. get { GUIElementStateStyle value; Internal_GetNormalOn(mCachedPtr, out value); return value; }
  143. set { Internal_SetNormalOn(mCachedPtr, ref value); }
  144. }
  145. /// <summary>
  146. /// Style used when element is in hover state and on.
  147. /// </summary>
  148. public GUIElementStateStyle HoverOn
  149. {
  150. get { GUIElementStateStyle value; Internal_GetHoverOn(mCachedPtr, out value); return value; }
  151. set { Internal_SetHoverOn(mCachedPtr, ref value); }
  152. }
  153. /// <summary>
  154. /// Style used when element is in active state and on.
  155. /// </summary>
  156. public GUIElementStateStyle ActiveOn
  157. {
  158. get { GUIElementStateStyle value; Internal_GetActiveOn(mCachedPtr, out value); return value; }
  159. set { Internal_SetActiveOn(mCachedPtr, ref value); }
  160. }
  161. /// <summary>
  162. /// Style used when element is in focused state and on.
  163. /// </summary>
  164. public GUIElementStateStyle FocusedOn
  165. {
  166. get { GUIElementStateStyle value; Internal_GetFocusedOn(mCachedPtr, out value); return value; }
  167. set { Internal_SetFocusedOn(mCachedPtr, ref value); }
  168. }
  169. /// <summary>
  170. /// Determines how the element is scaled (using the typical Scale9Grid approach).
  171. /// </summary>
  172. public RectOffset Border
  173. {
  174. get { RectOffset value; Internal_GetBorder(mCachedPtr, out value); return value; }
  175. set { Internal_SetBorder(mCachedPtr, ref value); }
  176. }
  177. /// <summary>
  178. /// Determines offset from the background graphics to the content. Input uses bounds offset by this value.
  179. /// </summary>
  180. public RectOffset Margins
  181. {
  182. get { RectOffset value; Internal_GetMargins(mCachedPtr, out value); return value; }
  183. set { Internal_SetMargins(mCachedPtr, ref value); }
  184. }
  185. /// <summary>
  186. /// Additional offset to the content, that doesn't effect the bounds. Applied on top of the margins offsets.
  187. /// </summary>
  188. public RectOffset ContentOffset
  189. {
  190. get { RectOffset value; Internal_GetContentOffset(mCachedPtr, out value); return value; }
  191. set { Internal_SetContentOffset(mCachedPtr, ref value); }
  192. }
  193. /// <summary>
  194. /// Wanted width of the GUI element in pixels. Only used if <see cref="FixedWidth"/> is enabled.
  195. /// </summary>
  196. public int Width
  197. {
  198. get { int value; Internal_GetWidth(mCachedPtr, out value); return value; }
  199. set { Internal_SetWidth(mCachedPtr, value); }
  200. }
  201. /// <summary>
  202. /// Wanted height of the GUI element in pixels. Only used if <see cref="FixedHeight"/> is enabled.
  203. /// </summary>
  204. public int Height
  205. {
  206. get { int value; Internal_GetHeight(mCachedPtr, out value); return value; }
  207. set { Internal_SetHeight(mCachedPtr, value); }
  208. }
  209. /// <summary>
  210. /// Minimum width allowed for the GUI element. Used by the layout only when exact width is not specified.
  211. /// </summary>
  212. public int MinWidth
  213. {
  214. get { int value; Internal_GetMinWidth(mCachedPtr, out value); return value; }
  215. set { Internal_SetMinWidth(mCachedPtr, value); }
  216. }
  217. /// <summary>
  218. /// Maximum width allowed for the GUI element. Used by the layout only when exact width is not specified.
  219. /// </summary>
  220. public int MaxWidth
  221. {
  222. get { int value; Internal_GetMaxWidth(mCachedPtr, out value); return value; }
  223. set { Internal_SetMaxWidth(mCachedPtr, value); }
  224. }
  225. /// <summary>
  226. /// Minimum height allowed for the GUI element. Used by the layout only when exact height is not specified.
  227. /// </summary>
  228. public int MinHeight
  229. {
  230. get { int value; Internal_GetMinHeight(mCachedPtr, out value); return value; }
  231. set { Internal_SetMinHeight(mCachedPtr, value); }
  232. }
  233. /// <summary>
  234. /// Maximum height allowed for the GUI element. Used by the layout only when exact height is not specified.
  235. /// </summary>
  236. public int MaxHeight
  237. {
  238. get { int value; Internal_GetMaxHeight(mCachedPtr, out value); return value; }
  239. set { Internal_SetMaxHeight(mCachedPtr, value); }
  240. }
  241. /// <summary>
  242. /// Determines should the layout resize the element depending on available size. If true no resizing will be done.
  243. /// </summary>
  244. public bool FixedWidth
  245. {
  246. get { bool value; Internal_GetFixedWidth(mCachedPtr, out value); return value; }
  247. set { Internal_SetFixedWidth(mCachedPtr, value); }
  248. }
  249. /// <summary>
  250. /// Determines should the layout resize the element depending on available size. If true no resizing will be done.
  251. /// </summary>
  252. public bool FixedHeight
  253. {
  254. get { bool value; Internal_GetFixedHeight(mCachedPtr, out value); return value; }
  255. set { Internal_SetFixedHeight(mCachedPtr, value); }
  256. }
  257. /// <summary>
  258. /// Registers a new sub-style that is used by complex GUI elements that contain one or multiple sub-elements.
  259. /// </summary>
  260. /// <param name="guiType">Name of the sub-element this style is to be used for. This depends on GUI element the
  261. /// style is applied to.</param>
  262. /// <param name="styleName">Name of the style in GUI skin to use for the sub-element.</param>
  263. public void AddSubStyle(string guiType, string styleName)
  264. {
  265. if (guiType == null || styleName == null)
  266. return;
  267. Internal_AddSubStyle(mCachedPtr, guiType, styleName);
  268. }
  269. [MethodImpl(MethodImplOptions.InternalCall)]
  270. private static extern void Internal_CreateInstance(GUIElementStyle instance);
  271. [MethodImpl(MethodImplOptions.InternalCall)]
  272. private static extern void Internal_GetFont(IntPtr nativeInstance, out Font value);
  273. [MethodImpl(MethodImplOptions.InternalCall)]
  274. private static extern void Internal_SetFont(IntPtr nativeInstance, Font value);
  275. [MethodImpl(MethodImplOptions.InternalCall)]
  276. private static extern void Internal_GetFontSize(IntPtr nativeInstance, out int value);
  277. [MethodImpl(MethodImplOptions.InternalCall)]
  278. private static extern void Internal_SetFontSize(IntPtr nativeInstance, int value);
  279. [MethodImpl(MethodImplOptions.InternalCall)]
  280. private static extern void Internal_GetTextHorzAlign(IntPtr nativeInstance, out TextHorzAlign value);
  281. [MethodImpl(MethodImplOptions.InternalCall)]
  282. private static extern void Internal_SetTextHorzAlign(IntPtr nativeInstance, TextHorzAlign value);
  283. [MethodImpl(MethodImplOptions.InternalCall)]
  284. private static extern void Internal_GetTextVertAlign(IntPtr nativeInstance, out TextVertAlign value);
  285. [MethodImpl(MethodImplOptions.InternalCall)]
  286. private static extern void Internal_SetTextVertAlign(IntPtr nativeInstance, TextVertAlign value);
  287. [MethodImpl(MethodImplOptions.InternalCall)]
  288. private static extern void Internal_GetImagePosition(IntPtr nativeInstance, out GUIImagePosition value);
  289. [MethodImpl(MethodImplOptions.InternalCall)]
  290. private static extern void Internal_SetImagePosition(IntPtr nativeInstance, GUIImagePosition value);
  291. [MethodImpl(MethodImplOptions.InternalCall)]
  292. private static extern void Internal_GetWordWrap(IntPtr nativeInstance, out bool value);
  293. [MethodImpl(MethodImplOptions.InternalCall)]
  294. private static extern void Internal_SetWordWrap(IntPtr nativeInstance, bool value);
  295. [MethodImpl(MethodImplOptions.InternalCall)]
  296. private static extern void Internal_GetNormal(IntPtr nativeInstance, out GUIElementStateStyle value);
  297. [MethodImpl(MethodImplOptions.InternalCall)]
  298. private static extern void Internal_SetNormal(IntPtr nativeInstance, ref GUIElementStateStyle value);
  299. [MethodImpl(MethodImplOptions.InternalCall)]
  300. private static extern void Internal_GetHover(IntPtr nativeInstance, out GUIElementStateStyle value);
  301. [MethodImpl(MethodImplOptions.InternalCall)]
  302. private static extern void Internal_SetHover(IntPtr nativeInstance, ref GUIElementStateStyle value);
  303. [MethodImpl(MethodImplOptions.InternalCall)]
  304. private static extern void Internal_GetActive(IntPtr nativeInstance, out GUIElementStateStyle value);
  305. [MethodImpl(MethodImplOptions.InternalCall)]
  306. private static extern void Internal_SetActive(IntPtr nativeInstance, ref GUIElementStateStyle value);
  307. [MethodImpl(MethodImplOptions.InternalCall)]
  308. private static extern void Internal_GetFocused(IntPtr nativeInstance, out GUIElementStateStyle value);
  309. [MethodImpl(MethodImplOptions.InternalCall)]
  310. private static extern void Internal_SetFocused(IntPtr nativeInstance, ref GUIElementStateStyle value);
  311. [MethodImpl(MethodImplOptions.InternalCall)]
  312. private static extern void Internal_GetNormalOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  313. [MethodImpl(MethodImplOptions.InternalCall)]
  314. private static extern void Internal_SetNormalOn(IntPtr nativeInstance, ref GUIElementStateStyle value);
  315. [MethodImpl(MethodImplOptions.InternalCall)]
  316. private static extern void Internal_GetHoverOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  317. [MethodImpl(MethodImplOptions.InternalCall)]
  318. private static extern void Internal_SetHoverOn(IntPtr nativeInstance, ref GUIElementStateStyle value);
  319. [MethodImpl(MethodImplOptions.InternalCall)]
  320. private static extern void Internal_GetActiveOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  321. [MethodImpl(MethodImplOptions.InternalCall)]
  322. private static extern void Internal_SetActiveOn(IntPtr nativeInstance, ref GUIElementStateStyle value);
  323. [MethodImpl(MethodImplOptions.InternalCall)]
  324. private static extern void Internal_GetFocusedOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  325. [MethodImpl(MethodImplOptions.InternalCall)]
  326. private static extern void Internal_SetFocusedOn(IntPtr nativeInstance, ref GUIElementStateStyle value);
  327. [MethodImpl(MethodImplOptions.InternalCall)]
  328. private static extern void Internal_GetBorder(IntPtr nativeInstance, out RectOffset value);
  329. [MethodImpl(MethodImplOptions.InternalCall)]
  330. private static extern void Internal_SetBorder(IntPtr nativeInstance, ref RectOffset value);
  331. [MethodImpl(MethodImplOptions.InternalCall)]
  332. private static extern void Internal_GetMargins(IntPtr nativeInstance, out RectOffset value);
  333. [MethodImpl(MethodImplOptions.InternalCall)]
  334. private static extern void Internal_SetMargins(IntPtr nativeInstance, ref RectOffset value);
  335. [MethodImpl(MethodImplOptions.InternalCall)]
  336. private static extern void Internal_GetContentOffset(IntPtr nativeInstance, out RectOffset value);
  337. [MethodImpl(MethodImplOptions.InternalCall)]
  338. private static extern void Internal_SetContentOffset(IntPtr nativeInstance, ref RectOffset value);
  339. [MethodImpl(MethodImplOptions.InternalCall)]
  340. private static extern void Internal_GetWidth(IntPtr nativeInstance, out int value);
  341. [MethodImpl(MethodImplOptions.InternalCall)]
  342. private static extern void Internal_SetWidth(IntPtr nativeInstance, int value);
  343. [MethodImpl(MethodImplOptions.InternalCall)]
  344. private static extern void Internal_GetHeight(IntPtr nativeInstance, out int value);
  345. [MethodImpl(MethodImplOptions.InternalCall)]
  346. private static extern void Internal_SetHeight(IntPtr nativeInstance, int value);
  347. [MethodImpl(MethodImplOptions.InternalCall)]
  348. private static extern void Internal_GetMinWidth(IntPtr nativeInstance, out int value);
  349. [MethodImpl(MethodImplOptions.InternalCall)]
  350. private static extern void Internal_SetMinWidth(IntPtr nativeInstance, int value);
  351. [MethodImpl(MethodImplOptions.InternalCall)]
  352. private static extern void Internal_GetMaxWidth(IntPtr nativeInstance, out int value);
  353. [MethodImpl(MethodImplOptions.InternalCall)]
  354. private static extern void Internal_SetMaxWidth(IntPtr nativeInstance, int value);
  355. [MethodImpl(MethodImplOptions.InternalCall)]
  356. private static extern void Internal_GetMinHeight(IntPtr nativeInstance, out int value);
  357. [MethodImpl(MethodImplOptions.InternalCall)]
  358. private static extern void Internal_SetMinHeight(IntPtr nativeInstance, int value);
  359. [MethodImpl(MethodImplOptions.InternalCall)]
  360. private static extern void Internal_GetMaxHeight(IntPtr nativeInstance, out int value);
  361. [MethodImpl(MethodImplOptions.InternalCall)]
  362. private static extern void Internal_SetMaxHeight(IntPtr nativeInstance, int value);
  363. [MethodImpl(MethodImplOptions.InternalCall)]
  364. private static extern void Internal_GetFixedWidth(IntPtr nativeInstance, out bool value);
  365. [MethodImpl(MethodImplOptions.InternalCall)]
  366. private static extern void Internal_SetFixedWidth(IntPtr nativeInstance, bool value);
  367. [MethodImpl(MethodImplOptions.InternalCall)]
  368. private static extern void Internal_GetFixedHeight(IntPtr nativeInstance, out bool value);
  369. [MethodImpl(MethodImplOptions.InternalCall)]
  370. private static extern void Internal_SetFixedHeight(IntPtr nativeInstance, bool value);
  371. [MethodImpl(MethodImplOptions.InternalCall)]
  372. private static extern void Internal_AddSubStyle(IntPtr nativeInstance, string guiType, string styleName);
  373. }
  374. /** @} */
  375. }