GUIElementStyle.cs 19 KB

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