GUISkin.cs 3.6 KB

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