GUIPanel.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. internal void SetArea(int x, int y, int width, int height)
  39. {
  40. Internal_SetArea(x, y, width, height);
  41. mainArea.SetArea(x, y, width, height);
  42. }
  43. internal void Destroy()
  44. {
  45. GUIArea[] tempAreas = childAreas.ToArray();
  46. for (int i = 0; i < tempAreas.Length; i++)
  47. tempAreas[i].Destroy();
  48. childAreas.Clear();
  49. Internal_Destroy(mCachedPtr);
  50. }
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern void Internal_SetArea(int x, int y, int width, int height);
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern void Internal_CreateInstance(GUIPanel instance);
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. private static extern void Internal_Destroy(IntPtr nativeInstance);
  57. }
  58. }