GUISkin.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /// Returns a style for the specified GUI element type.
  30. /// </summary>
  31. /// <param name="name">Name of the style to look for.</param>
  32. /// <returns>Found element style, or null if a style with the specified name was not found.</returns>
  33. public GUIElementStyle GetStyle(string name)
  34. {
  35. return Internal_GetStyle(mCachedPtr, name);
  36. }
  37. /// <summary>
  38. /// Sets a style for the specified GUI element type.
  39. /// </summary>
  40. /// <param name="name">Name of the style to add/modify.</param>
  41. /// <param name="style">Style object containing style options.</param>
  42. public void SetStyle(string name, GUIElementStyle style)
  43. {
  44. IntPtr stylePtr = IntPtr.Zero;
  45. if (style != null)
  46. stylePtr = style.GetCachedPtr();
  47. Internal_SetStyle(mCachedPtr, name, stylePtr);
  48. }
  49. /// <summary>
  50. /// Removes a style from the skin.
  51. /// </summary>
  52. /// <param name="name">Name of the style to remove.</param>
  53. public void RemoveStyle(string name)
  54. {
  55. Internal_RemoveStyle(mCachedPtr, name);
  56. }
  57. [MethodImpl(MethodImplOptions.InternalCall)]
  58. private static extern void Internal_CreateInstance(GUISkin instance);
  59. [MethodImpl(MethodImplOptions.InternalCall)]
  60. private static extern GUIElementStyle Internal_GetStyle(IntPtr thisPtr, string name);
  61. [MethodImpl(MethodImplOptions.InternalCall)]
  62. private static extern void Internal_SetStyle(IntPtr thisPtr, string name, IntPtr style);
  63. [MethodImpl(MethodImplOptions.InternalCall)]
  64. private static extern void Internal_RemoveStyle(IntPtr thisPtr, string name);
  65. [MethodImpl(MethodImplOptions.InternalCall)]
  66. private static extern string[] Internal_GetStyleNames(IntPtr thisPtr);
  67. }
  68. }