GUIElementStyle.cs 19 KB

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