GUISkin.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. namespace BansheeEngine
  6. {
  7. /** @addtogroup GUI_Engine
  8. * @{
  9. */
  10. /// <summary>
  11. /// Holds a set of styles that control how are GUI element types positioned and displayed in the GUI. Each element type
  12. /// can be assigned a specific style.
  13. /// </summary>
  14. public sealed class GUISkin : Resource
  15. {
  16. // Constructor for runtime use only (dummy parameter to differentiate from the normal constructor)
  17. private GUISkin(bool dummy)
  18. { }
  19. /// <summary>
  20. /// Creates a new empty GUI skin.
  21. /// </summary>
  22. public GUISkin()
  23. {
  24. Internal_CreateInstance(this);
  25. }
  26. /// <summary>
  27. /// Returns names of all GUI element styles registered on this skin.
  28. /// </summary>
  29. public string[] StyleNames
  30. {
  31. get { return Internal_GetStyleNames(mCachedPtr); }
  32. }
  33. /// <summary>
  34. /// Checks if the style with the specified name exists.
  35. /// </summary>
  36. /// <param name="name">Name of the style to look for.</param>
  37. /// <returns>True if the style exists in this skin, false otherwise.</returns>
  38. public bool HasStyle(string name)
  39. {
  40. return Internal_HasStyle(mCachedPtr, name);
  41. }
  42. /// <summary>
  43. /// Returns a style for the specified GUI element type.
  44. /// </summary>
  45. /// <param name="name">Name of the style to look for.</param>
  46. /// <returns>Found element style, or null if a style with the specified name was not found.</returns>
  47. public GUIElementStyle GetStyle(string name)
  48. {
  49. return Internal_GetStyle(mCachedPtr, name);
  50. }
  51. /// <summary>
  52. /// Sets a style for the specified GUI element type.
  53. /// </summary>
  54. /// <param name="name">Name of the style to add/modify.</param>
  55. /// <param name="style">Style object containing style options.</param>
  56. public void SetStyle(string name, GUIElementStyle style)
  57. {
  58. IntPtr stylePtr = IntPtr.Zero;
  59. if (style != null)
  60. stylePtr = style.GetCachedPtr();
  61. Internal_SetStyle(mCachedPtr, name, stylePtr);
  62. }
  63. /// <summary>
  64. /// Removes a style from the skin.
  65. /// </summary>
  66. /// <param name="name">Name of the style to remove.</param>
  67. public void RemoveStyle(string name)
  68. {
  69. Internal_RemoveStyle(mCachedPtr, name);
  70. }
  71. [MethodImpl(MethodImplOptions.InternalCall)]
  72. private static extern void Internal_CreateInstance(GUISkin instance);
  73. [MethodImpl(MethodImplOptions.InternalCall)]
  74. private static extern bool Internal_HasStyle(IntPtr thisPtr, string name);
  75. [MethodImpl(MethodImplOptions.InternalCall)]
  76. private static extern GUIElementStyle Internal_GetStyle(IntPtr thisPtr, string name);
  77. [MethodImpl(MethodImplOptions.InternalCall)]
  78. private static extern void Internal_SetStyle(IntPtr thisPtr, string name, IntPtr style);
  79. [MethodImpl(MethodImplOptions.InternalCall)]
  80. private static extern void Internal_RemoveStyle(IntPtr thisPtr, string name);
  81. [MethodImpl(MethodImplOptions.InternalCall)]
  82. private static extern string[] Internal_GetStyleNames(IntPtr thisPtr);
  83. }
  84. /** @} */
  85. }