GUIArea.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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, Int16 depth, GUILayoutType layoutType)
  26. {
  27. GUIArea newArea = new GUIArea();
  28. Internal_CreateInstance(newArea, parent, x, y, width, height, depth, layoutType);
  29. newArea._layout = new GUILayoutX(newArea);
  30. return newArea;
  31. }
  32. public void SetArea(int x, int y, int width, int height, Int16 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,
  53. int width, int height, Int16 depth, GUILayoutType layoutType);
  54. [MethodImpl(MethodImplOptions.InternalCall)]
  55. private static extern void Internal_SetArea(IntPtr nativeInstance, int x, int y, int width, int height, Int16 depth);
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. private static extern void Internal_Destroy(IntPtr nativeInstance);
  58. [MethodImpl(MethodImplOptions.InternalCall)]
  59. private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
  60. }
  61. // Note: Must have same layout as GUILayoutType
  62. public enum GUILayoutType
  63. {
  64. X, Y, Explicit
  65. }
  66. }