GUIPanel.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. namespace BansheeEngine
  5. {
  6. public sealed class GUIPanel : ScriptObject
  7. {
  8. private GUIArea mainArea;
  9. private GUILayout _mainLayout;
  10. internal List<GUIArea> childAreas = new List<GUIArea>();
  11. public GUILayout layout
  12. {
  13. get { return _mainLayout; }
  14. }
  15. public GUISkin skin; // TODO
  16. internal GUIPanel()
  17. {
  18. Internal_CreateInstance(this);
  19. }
  20. ~GUIPanel()
  21. {
  22. GUIArea[] childArray = childAreas.ToArray(); // Iterating over it will modify it so make a copy
  23. for (int i = 0; i < childArray.Length; i++)
  24. childArray[i].Destroy();
  25. childAreas.Clear();
  26. }
  27. internal void Initialize()
  28. {
  29. mainArea = AddArea(0, 0, 0, 0);
  30. _mainLayout = mainArea.layout;
  31. }
  32. public GUIArea AddArea(int x, int y, int width, int height, short depth = 0)
  33. {
  34. GUIArea area = GUIArea.Create(this, x, y, width, height, depth);
  35. area.SetParent(this);
  36. return area;
  37. }
  38. public void SetVisible(bool visible)
  39. {
  40. for (int i = 0; i < childAreas.Count; i++)
  41. childAreas[i].SetVisible(visible);
  42. }
  43. internal void SetArea(int x, int y, int width, int height)
  44. {
  45. Internal_SetArea(mCachedPtr, x, y, width, height);
  46. mainArea.SetArea(0, 0, width, height);
  47. }
  48. internal void Destroy()
  49. {
  50. GUIArea[] tempAreas = childAreas.ToArray();
  51. for (int i = 0; i < tempAreas.Length; i++)
  52. tempAreas[i].Destroy();
  53. childAreas.Clear();
  54. Internal_Destroy(mCachedPtr);
  55. }
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. private static extern void Internal_SetArea(IntPtr nativeInstance, int x, int y, int width, int height);
  58. [MethodImpl(MethodImplOptions.InternalCall)]
  59. private static extern void Internal_CreateInstance(GUIPanel instance);
  60. [MethodImpl(MethodImplOptions.InternalCall)]
  61. private static extern void Internal_Destroy(IntPtr nativeInstance);
  62. }
  63. }