GUIArea.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. newArea.SetArea(x, y, width, height, depth);
  31. return newArea;
  32. }
  33. public void SetArea(int x, int y, int width, int height, Int16 depth = 0)
  34. {
  35. Internal_SetArea(mCachedPtr, x, y, width, height, depth);
  36. }
  37. public void SetVisible(bool visible)
  38. {
  39. Internal_SetVisible(mCachedPtr, visible);
  40. }
  41. public bool IsDestroyed()
  42. {
  43. return isDestroyed;
  44. }
  45. public void Destroy()
  46. {
  47. SetParent(null);
  48. _layout.Destroy();
  49. isDestroyed = true;
  50. Internal_Destroy(mCachedPtr);
  51. }
  52. [MethodImpl(MethodImplOptions.InternalCall)]
  53. private static extern void Internal_CreateInstance(GUIArea instance, GUIPanel parent, int x, int y,
  54. int width, int height, Int16 depth, GUILayoutType layoutType);
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. private static extern void Internal_SetArea(IntPtr nativeInstance, int x, int y, int width, int height, Int16 depth);
  57. [MethodImpl(MethodImplOptions.InternalCall)]
  58. private static extern void Internal_Destroy(IntPtr nativeInstance);
  59. [MethodImpl(MethodImplOptions.InternalCall)]
  60. private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
  61. }
  62. // Note: Must have same layout as GUILayoutType
  63. public enum GUILayoutType
  64. {
  65. X, Y, Explicit
  66. }
  67. }