GUIElementStyle.cs 20 KB

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