GUIPanel.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. internal void Initialize()
  21. {
  22. mainArea = AddArea(0, 0, 0, 0);
  23. _mainLayout = mainArea.layout;
  24. }
  25. public GUIArea AddArea(int x, int y, int width, int height, UInt16 depth = 0)
  26. {
  27. GUIArea area = GUIArea.Create(this, x, y, width, height, depth);
  28. area.SetParent(this);
  29. return area;
  30. }
  31. public void SetVisible(bool visible)
  32. {
  33. for (int i = 0; i < childAreas.Count; i++)
  34. childAreas[i].SetVisible(visible);
  35. }
  36. internal void SetArea(int x, int y, int width, int height)
  37. {
  38. Internal_SetArea(mCachedPtr, x, y, width, height);
  39. mainArea.SetArea(0, 0, width, height);
  40. }
  41. // Note: Only to be called from EditorWindow.DestroyPanel
  42. internal void Destroy()
  43. {
  44. GUIArea[] tempAreas = childAreas.ToArray();
  45. for (int i = 0; i < tempAreas.Length; i++)
  46. tempAreas[i].Destroy();
  47. childAreas.Clear();
  48. }
  49. [MethodImpl(MethodImplOptions.InternalCall)]
  50. private static extern void Internal_SetArea(IntPtr nativeInstance, int x, int y, int width, int height);
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern void Internal_CreateInstance(GUIPanel instance);
  53. }
  54. }