GUIArea.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. public sealed class GUIArea : ScriptObject
  6. {
  7. private GUILayout _layout;
  8. private GUIPanel parent;
  9. private bool isDestroyed;
  10. public GUILayout layout
  11. {
  12. get { return _layout;}
  13. }
  14. internal GUIArea()
  15. { }
  16. internal void SetParent(GUIPanel parent)
  17. {
  18. if (this.parent != null)
  19. this.parent.childAreas.Remove(this);
  20. this.parent = parent;
  21. if(parent != null)
  22. parent.childAreas.Add(this);
  23. }
  24. // Note: Should only ever be called by its parent GUIPanel
  25. internal static GUIArea Create(GUIPanel parent, int x, int y, int width, int height, UInt16 depth)
  26. {
  27. GUIArea newArea = new GUIArea();
  28. Internal_CreateInstance(newArea, parent, x, y, width, height, depth);
  29. newArea._layout = new GUILayoutX(newArea);
  30. return newArea;
  31. }
  32. public void SetArea(int x, int y, int width, int height, UInt16 depth = 0)
  33. {
  34. Internal_SetArea(mCachedPtr, x, y, width, height, depth);
  35. }
  36. public void SetVisible(bool visible)
  37. {
  38. Internal_SetVisible(mCachedPtr, visible);
  39. }
  40. public bool IsDestroyed()
  41. {
  42. return isDestroyed;
  43. }
  44. public void Destroy()
  45. {
  46. SetParent(null);
  47. _layout.Destroy();
  48. isDestroyed = true;
  49. Internal_Destroy(mCachedPtr);
  50. }
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern void Internal_CreateInstance(GUIArea instance, GUIPanel parent, int x, int y, int width, int height, UInt16 depth);
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern void Internal_SetArea(IntPtr nativeInstance, int x, int y, int width, int height, UInt16 depth);
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. private static extern void Internal_Destroy(IntPtr nativeInstance);
  57. [MethodImpl(MethodImplOptions.InternalCall)]
  58. private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
  59. }
  60. }