GUIElementStyle.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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
  37. /// the element's default layout options. Different looks can be provided
  38. /// for different element states.
  39. /// </summary>
  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
  254. /// one or multiple sub-elements.
  255. /// </summary>
  256. /// <param name="guiType">Name of the sub-element this style is to be used for.
  257. /// This depends on GUI element the style is applied to.
  258. /// </param>
  259. /// <param name="styleName">Name of the style in GUI skin to use for the sub-element.
  260. /// </param>
  261. public void AddSubStyle(string guiType, string styleName)
  262. {
  263. if (guiType == null || styleName == null)
  264. return;
  265. Internal_AddSubStyle(mCachedPtr, guiType, styleName);
  266. }
  267. [MethodImpl(MethodImplOptions.InternalCall)]
  268. private static extern void Internal_CreateInstance(GUIElementStyle instance);
  269. [MethodImpl(MethodImplOptions.InternalCall)]
  270. private static extern void Internal_GetFont(IntPtr nativeInstance, out Font value);
  271. [MethodImpl(MethodImplOptions.InternalCall)]
  272. private static extern void Internal_SetFont(IntPtr nativeInstance, Font value);
  273. [MethodImpl(MethodImplOptions.InternalCall)]
  274. private static extern void Internal_GetFontSize(IntPtr nativeInstance, out int value);
  275. [MethodImpl(MethodImplOptions.InternalCall)]
  276. private static extern void Internal_SetFontSize(IntPtr nativeInstance, int value);
  277. [MethodImpl(MethodImplOptions.InternalCall)]
  278. private static extern void Internal_GetTextHorzAlign(IntPtr nativeInstance, out TextHorzAlign value);
  279. [MethodImpl(MethodImplOptions.InternalCall)]
  280. private static extern void Internal_SetTextHorzAlign(IntPtr nativeInstance, TextHorzAlign value);
  281. [MethodImpl(MethodImplOptions.InternalCall)]
  282. private static extern void Internal_GetTextVertAlign(IntPtr nativeInstance, out TextVertAlign value);
  283. [MethodImpl(MethodImplOptions.InternalCall)]
  284. private static extern void Internal_SetTextVertAlign(IntPtr nativeInstance, TextVertAlign value);
  285. [MethodImpl(MethodImplOptions.InternalCall)]
  286. private static extern void Internal_GetImagePosition(IntPtr nativeInstance, out GUIImagePosition value);
  287. [MethodImpl(MethodImplOptions.InternalCall)]
  288. private static extern void Internal_SetImagePosition(IntPtr nativeInstance, GUIImagePosition value);
  289. [MethodImpl(MethodImplOptions.InternalCall)]
  290. private static extern void Internal_GetWordWrap(IntPtr nativeInstance, out bool value);
  291. [MethodImpl(MethodImplOptions.InternalCall)]
  292. private static extern void Internal_SetWordWrap(IntPtr nativeInstance, bool value);
  293. [MethodImpl(MethodImplOptions.InternalCall)]
  294. private static extern void Internal_GetNormal(IntPtr nativeInstance, out GUIElementStateStyle value);
  295. [MethodImpl(MethodImplOptions.InternalCall)]
  296. private static extern void Internal_SetNormal(IntPtr nativeInstance, GUIElementStateStyle value);
  297. [MethodImpl(MethodImplOptions.InternalCall)]
  298. private static extern void Internal_GetHover(IntPtr nativeInstance, out GUIElementStateStyle value);
  299. [MethodImpl(MethodImplOptions.InternalCall)]
  300. private static extern void Internal_SetHover(IntPtr nativeInstance, GUIElementStateStyle value);
  301. [MethodImpl(MethodImplOptions.InternalCall)]
  302. private static extern void Internal_GetActive(IntPtr nativeInstance, out GUIElementStateStyle value);
  303. [MethodImpl(MethodImplOptions.InternalCall)]
  304. private static extern void Internal_SetActive(IntPtr nativeInstance, GUIElementStateStyle value);
  305. [MethodImpl(MethodImplOptions.InternalCall)]
  306. private static extern void Internal_GetFocused(IntPtr nativeInstance, out GUIElementStateStyle value);
  307. [MethodImpl(MethodImplOptions.InternalCall)]
  308. private static extern void Internal_SetFocused(IntPtr nativeInstance, GUIElementStateStyle value);
  309. [MethodImpl(MethodImplOptions.InternalCall)]
  310. private static extern void Internal_GetNormalOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  311. [MethodImpl(MethodImplOptions.InternalCall)]
  312. private static extern void Internal_SetNormalOn(IntPtr nativeInstance, GUIElementStateStyle value);
  313. [MethodImpl(MethodImplOptions.InternalCall)]
  314. private static extern void Internal_GetHoverOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  315. [MethodImpl(MethodImplOptions.InternalCall)]
  316. private static extern void Internal_SetHoverOn(IntPtr nativeInstance, GUIElementStateStyle value);
  317. [MethodImpl(MethodImplOptions.InternalCall)]
  318. private static extern void Internal_GetActiveOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  319. [MethodImpl(MethodImplOptions.InternalCall)]
  320. private static extern void Internal_SetActiveOn(IntPtr nativeInstance, GUIElementStateStyle value);
  321. [MethodImpl(MethodImplOptions.InternalCall)]
  322. private static extern void Internal_GetFocusedOn(IntPtr nativeInstance, out GUIElementStateStyle value);
  323. [MethodImpl(MethodImplOptions.InternalCall)]
  324. private static extern void Internal_SetFocusedOn(IntPtr nativeInstance, GUIElementStateStyle value);
  325. [MethodImpl(MethodImplOptions.InternalCall)]
  326. private static extern void Internal_GetBorder(IntPtr nativeInstance, out RectOffset value);
  327. [MethodImpl(MethodImplOptions.InternalCall)]
  328. private static extern void Internal_SetBorder(IntPtr nativeInstance, ref RectOffset value);
  329. [MethodImpl(MethodImplOptions.InternalCall)]
  330. private static extern void Internal_GetMargins(IntPtr nativeInstance, out RectOffset value);
  331. [MethodImpl(MethodImplOptions.InternalCall)]
  332. private static extern void Internal_SetMargins(IntPtr nativeInstance, ref RectOffset value);
  333. [MethodImpl(MethodImplOptions.InternalCall)]
  334. private static extern void Internal_GetContentOffset(IntPtr nativeInstance, out RectOffset value);
  335. [MethodImpl(MethodImplOptions.InternalCall)]
  336. private static extern void Internal_SetContentOffset(IntPtr nativeInstance, ref RectOffset value);
  337. [MethodImpl(MethodImplOptions.InternalCall)]
  338. private static extern void Internal_GetWidth(IntPtr nativeInstance, out int value);
  339. [MethodImpl(MethodImplOptions.InternalCall)]
  340. private static extern void Internal_SetWidth(IntPtr nativeInstance, int value);
  341. [MethodImpl(MethodImplOptions.InternalCall)]
  342. private static extern void Internal_GetHeight(IntPtr nativeInstance, out int value);
  343. [MethodImpl(MethodImplOptions.InternalCall)]
  344. private static extern void Internal_SetHeight(IntPtr nativeInstance, int value);
  345. [MethodImpl(MethodImplOptions.InternalCall)]
  346. private static extern void Internal_GetMinWidth(IntPtr nativeInstance, out int value);
  347. [MethodImpl(MethodImplOptions.InternalCall)]
  348. private static extern void Internal_SetMinWidth(IntPtr nativeInstance, int value);
  349. [MethodImpl(MethodImplOptions.InternalCall)]
  350. private static extern void Internal_GetMaxWidth(IntPtr nativeInstance, out int value);
  351. [MethodImpl(MethodImplOptions.InternalCall)]
  352. private static extern void Internal_SetMaxWidth(IntPtr nativeInstance, int value);
  353. [MethodImpl(MethodImplOptions.InternalCall)]
  354. private static extern void Internal_GetMinHeight(IntPtr nativeInstance, out int value);
  355. [MethodImpl(MethodImplOptions.InternalCall)]
  356. private static extern void Internal_SetMinHeight(IntPtr nativeInstance, int value);
  357. [MethodImpl(MethodImplOptions.InternalCall)]
  358. private static extern void Internal_GetMaxHeight(IntPtr nativeInstance, out int value);
  359. [MethodImpl(MethodImplOptions.InternalCall)]
  360. private static extern void Internal_SetMaxHeight(IntPtr nativeInstance, int value);
  361. [MethodImpl(MethodImplOptions.InternalCall)]
  362. private static extern void Internal_GetFixedWidth(IntPtr nativeInstance, out bool value);
  363. [MethodImpl(MethodImplOptions.InternalCall)]
  364. private static extern void Internal_SetFixedWidth(IntPtr nativeInstance, bool value);
  365. [MethodImpl(MethodImplOptions.InternalCall)]
  366. private static extern void Internal_GetFixedHeight(IntPtr nativeInstance, out bool value);
  367. [MethodImpl(MethodImplOptions.InternalCall)]
  368. private static extern void Internal_SetFixedHeight(IntPtr nativeInstance, bool value);
  369. [MethodImpl(MethodImplOptions.InternalCall)]
  370. private static extern void Internal_AddSubStyle(IntPtr nativeInstance, string guiType, string styleName);
  371. }
  372. }