GUISkin.cs 3.4 KB

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