GUIPanel.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, short 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. internal void Destroy()
  42. {
  43. GUIArea[] tempAreas = childAreas.ToArray();
  44. for (int i = 0; i < tempAreas.Length; i++)
  45. tempAreas[i].Destroy();
  46. childAreas.Clear();
  47. Internal_Destroy(mCachedPtr);
  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. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern void Internal_Destroy(IntPtr nativeInstance);
  55. }
  56. }