Forráskód Böngészése

Refactored Script and C# GUI interface

Marko Pintera 11 éve
szülő
commit
36c918a215
40 módosított fájl, 756 hozzáadás és 502 törlés
  1. 4 0
      Inspector.txt
  2. 20 0
      MBansheeEngine/Debug.cs
  3. 22 17
      MBansheeEngine/GUI/GUIArea.cs
  4. 7 8
      MBansheeEngine/GUI/GUIBase.cs
  5. 13 4
      MBansheeEngine/GUI/GUIButton.cs
  6. 21 31
      MBansheeEngine/GUI/GUIElement.cs
  7. 3 4
      MBansheeEngine/GUI/GUILabel.cs
  8. 56 103
      MBansheeEngine/GUI/GUILayout.cs
  9. 0 2
      MBansheeEngine/GUI/GUILayoutX.cs
  10. 0 2
      MBansheeEngine/GUI/GUILayoutY.cs
  11. 8 4
      MBansheeEngine/GUI/GUIListBox.cs
  12. 41 5
      MBansheeEngine/GUI/GUIScrollArea.cs
  13. 10 2
      MBansheeEngine/GUI/GUISpace.cs
  14. 18 4
      MBansheeEngine/GUI/GUITextBox.cs
  15. 18 5
      MBansheeEngine/GUI/GUITexture.cs
  16. 28 4
      MBansheeEngine/GUI/GUIToggle.cs
  17. 1 0
      MBansheeEngine/MBansheeEngine.csproj
  18. 4 4
      SBansheeEngine/Include/BsScriptGUIArea.h
  19. 6 3
      SBansheeEngine/Include/BsScriptGUIButton.h
  20. 5 3
      SBansheeEngine/Include/BsScriptGUIFixedSpace.h
  21. 5 2
      SBansheeEngine/Include/BsScriptGUIFlexibleSpace.h
  22. 6 3
      SBansheeEngine/Include/BsScriptGUIInputBox.h
  23. 6 3
      SBansheeEngine/Include/BsScriptGUILabel.h
  24. 6 6
      SBansheeEngine/Include/BsScriptGUILayout.h
  25. 6 3
      SBansheeEngine/Include/BsScriptGUIListBox.h
  26. 7 6
      SBansheeEngine/Include/BsScriptGUIScrollArea.h
  27. 6 3
      SBansheeEngine/Include/BsScriptGUITexture.h
  28. 6 3
      SBansheeEngine/Include/BsScriptGUIToggle.h
  29. 102 96
      SBansheeEngine/SBansheeEngine.vcxproj.filters
  30. 18 14
      SBansheeEngine/Source/BsScriptGUIArea.cpp
  31. 33 19
      SBansheeEngine/Source/BsScriptGUIButton.cpp
  32. 23 8
      SBansheeEngine/Source/BsScriptGUIFixedSpace.cpp
  33. 23 8
      SBansheeEngine/Source/BsScriptGUIFlexibleSpace.cpp
  34. 33 18
      SBansheeEngine/Source/BsScriptGUIInputBox.cpp
  35. 34 18
      SBansheeEngine/Source/BsScriptGUILabel.cpp
  36. 31 14
      SBansheeEngine/Source/BsScriptGUILayout.cpp
  37. 33 19
      SBansheeEngine/Source/BsScriptGUIListBox.cpp
  38. 27 17
      SBansheeEngine/Source/BsScriptGUIScrollArea.cpp
  39. 33 18
      SBansheeEngine/Source/BsScriptGUITexture.cpp
  40. 33 19
      SBansheeEngine/Source/BsScriptGUIToggle.cpp

+ 4 - 0
Inspector.txt

@@ -19,6 +19,10 @@ Other:
 
 
 -------------
 -------------
 
 
+Boost any replacement: http://www.codeproject.com/Articles/11250/High-Performance-Dynamic-Typing-in-C-using-a-Repla
+
+-------------
+
 REFACTOR c++ GUI a bit:
 REFACTOR c++ GUI a bit:
  - GameObjectField
  - GameObjectField
    - When dragging over GameObjectField cursor needs to change depending whether drop will be accepted or not
    - When dragging over GameObjectField cursor needs to change depending whether drop will be accepted or not

+ 20 - 0
MBansheeEngine/Debug.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BansheeEngine
+{
+    public class Debug
+    {
+        public static void Log(string message)
+        {
+            // TODO - Not implemented
+        }
+
+        public static void LogWarning(string message)
+        {
+            // TODO - Not implemented
+        }
+    }
+}

+ 22 - 17
MBansheeEngine/GUI/GUIArea.cs

@@ -7,6 +7,7 @@ namespace BansheeEngine
     {
     {
         private GUILayout _layout;
         private GUILayout _layout;
         private GUIBase parent;
         private GUIBase parent;
+        private bool isDestroyed;
 
 
         public GUILayout layout
         public GUILayout layout
         {
         {
@@ -16,11 +17,20 @@ namespace BansheeEngine
         internal GUIArea()
         internal GUIArea()
         { }
         { }
 
 
+        internal void SetParent(GUIBase parent)
+        {
+            if (this.parent != null)
+                this.parent.childAreas.Remove(this);
+
+            this.parent = parent;
+
+            parent.childAreas.Add(this);
+        }
+
         internal static GUIArea Create(GUIBase parent, int x, int y, int width, int height, short depth)
         internal static GUIArea Create(GUIBase parent, int x, int y, int width, int height, short depth)
         {
         {
             GUIArea newArea = new GUIArea();
             GUIArea newArea = new GUIArea();
             Internal_CreateInstance(newArea, parent, x, y, width, height, depth);
             Internal_CreateInstance(newArea, parent, x, y, width, height, depth);
-            newArea.parent = parent;
             newArea._layout = new GUILayoutX(newArea);
             newArea._layout = new GUILayoutX(newArea);
 
 
             return newArea;
             return newArea;
@@ -30,7 +40,6 @@ namespace BansheeEngine
         {
         {
             GUIArea newArea = new GUIArea();
             GUIArea newArea = new GUIArea();
             Internal_CreateInstanceResizableX(newArea, parent, offsetLeft, offsetRight, offsetTop, height, depth);
             Internal_CreateInstanceResizableX(newArea, parent, offsetLeft, offsetRight, offsetTop, height, depth);
-            newArea.parent = parent;
             newArea._layout = new GUILayoutX(newArea);
             newArea._layout = new GUILayoutX(newArea);
 
 
             return newArea;
             return newArea;
@@ -40,7 +49,6 @@ namespace BansheeEngine
         {
         {
             GUIArea newArea = new GUIArea();
             GUIArea newArea = new GUIArea();
             Internal_CreateInstanceResizableY(newArea, parent, offsetTop, offsetBottom, offsetLeft, width, depth);
             Internal_CreateInstanceResizableY(newArea, parent, offsetTop, offsetBottom, offsetLeft, width, depth);
-            newArea.parent = parent;
             newArea._layout = new GUILayoutX(newArea);
             newArea._layout = new GUILayoutX(newArea);
 
 
             return newArea;
             return newArea;
@@ -50,28 +58,28 @@ namespace BansheeEngine
         {
         {
             GUIArea newArea = new GUIArea();
             GUIArea newArea = new GUIArea();
             Internal_CreateInstanceResizableXY(newArea, parent, offsetLeft, offsetRight, offsetTop, offsetBottom, depth);
             Internal_CreateInstanceResizableXY(newArea, parent, offsetLeft, offsetRight, offsetTop, offsetBottom, depth);
-            newArea.parent = parent;
             newArea._layout = new GUILayoutX(newArea);
             newArea._layout = new GUILayoutX(newArea);
 
 
             return newArea;
             return newArea;
         }
         }
 
 
-        public void Destroy()
+        public void SetVisible(bool visible)
         {
         {
-            _layout.Destroy();
-            parent.childAreas.Remove(this);
-
-            Internal_Destroy(mCachedPtr);
+            Internal_SetVisible(mCachedPtr, visible);
         }
         }
 
 
-        public void Enable()
+        public bool IsDestroyed()
         {
         {
-            Internal_Enable(mCachedPtr);
+            return isDestroyed;
         }
         }
 
 
-        public void Disable()
+        public void Destroy()
         {
         {
-            Internal_Disable(mCachedPtr);
+            SetParent(null);
+            _layout.Destroy();
+            isDestroyed = true;
+
+            Internal_Destroy(mCachedPtr);
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
@@ -93,9 +101,6 @@ namespace BansheeEngine
         private static extern void Internal_Destroy(IntPtr nativeInstance);
         private static extern void Internal_Destroy(IntPtr nativeInstance);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Enable(IntPtr nativeInstance);
-
-        [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Disable(IntPtr nativeInstance);
+        private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
     }
     }
 }
 }

+ 7 - 8
MBansheeEngine/GUI/GUIBase.cs

@@ -23,10 +23,9 @@ namespace BansheeEngine
 
 
         ~GUIBase()
         ~GUIBase()
         {
         {
-            for (int i = 0; i < childAreas.Count; i++)
-            {
-                childAreas[i].Destroy();
-            }
+            GUIArea[] childArray = childAreas.ToArray(); // Iterating over it will modify it so make a copy
+            for (int i = 0; i < childArray.Length; i++)
+                childArray[i].Destroy();
 
 
             childAreas.Clear();
             childAreas.Clear();
         }
         }
@@ -40,7 +39,7 @@ namespace BansheeEngine
         public GUIArea AddArea(int x, int y, int width = 0, int height = 0, short depth = 0)
         public GUIArea AddArea(int x, int y, int width = 0, int height = 0, short depth = 0)
         {
         {
             GUIArea area = GUIArea.Create(this, x, y, width, height, depth);
             GUIArea area = GUIArea.Create(this, x, y, width, height, depth);
-            childAreas.Add(area);
+            area.SetParent(this);
 
 
             return area;
             return area;
         }
         }
@@ -48,7 +47,7 @@ namespace BansheeEngine
         public GUIArea AddResizableAreaX(int offsetLeft, int offsetRight, int offsetTop, int height, short depth = 0)
         public GUIArea AddResizableAreaX(int offsetLeft, int offsetRight, int offsetTop, int height, short depth = 0)
         {
         {
             GUIArea area = GUIArea.CreateResizableX(this, offsetLeft, offsetRight, offsetTop, height, depth);
             GUIArea area = GUIArea.CreateResizableX(this, offsetLeft, offsetRight, offsetTop, height, depth);
-            childAreas.Add(area);
+            area.SetParent(this);
 
 
             return area;
             return area;
         }
         }
@@ -56,7 +55,7 @@ namespace BansheeEngine
         public GUIArea AddResizableAreaY(int offsetTop, int offsetBottom, int offsetLeft, int width, short depth = 0)
         public GUIArea AddResizableAreaY(int offsetTop, int offsetBottom, int offsetLeft, int width, short depth = 0)
         {
         {
             GUIArea area = GUIArea.CreateResizableY(this, offsetTop, offsetBottom, offsetLeft, width, depth);
             GUIArea area = GUIArea.CreateResizableY(this, offsetTop, offsetBottom, offsetLeft, width, depth);
-            childAreas.Add(area);
+            area.SetParent(this);
 
 
             return area;
             return area;
         }
         }
@@ -64,7 +63,7 @@ namespace BansheeEngine
         public GUIArea AddResizableAreaXY(int offsetLeft, int offsetRight, int offsetTop, int offsetBottom, short depth = 0)
         public GUIArea AddResizableAreaXY(int offsetLeft, int offsetRight, int offsetTop, int offsetBottom, short depth = 0)
         {
         {
             GUIArea area = GUIArea.CreateResizableXY(this, offsetLeft, offsetRight, offsetTop, offsetBottom, depth);
             GUIArea area = GUIArea.CreateResizableXY(this, offsetLeft, offsetRight, offsetTop, offsetBottom, depth);
-            childAreas.Add(area);
+            area.SetParent(this);
 
 
             return area;
             return area;
         }
         }

+ 13 - 4
MBansheeEngine/GUI/GUIButton.cs

@@ -13,10 +13,19 @@ namespace BansheeEngine
         public event OnHoverDelegate OnHover;
         public event OnHoverDelegate OnHover;
         public event OnOutDelegate OnOut;
         public event OnOutDelegate OnOut;
 
 
-        internal GUIButton(GUILayout parentLayout, GUIContent content, GUIElementStyle style, params GUIOption[] options)
-            :base(parentLayout)
+        public GUIButton(GUIContent content, GUIElementStyle style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, content, style, options);
+            Internal_CreateInstance(this, content, style, options);
+        }
+
+        public GUIButton(GUIContent content, GUIElementStyle style)
+        {
+            Internal_CreateInstance(this, content, style, new GUIOption[0]);
+        }
+
+        public GUIButton(GUIContent content, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, content, null, options);
         }
         }
 
 
         public void SetContent(GUIContent content)
         public void SetContent(GUIContent content)
@@ -43,7 +52,7 @@ namespace BansheeEngine
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUIButton instance, GUILayout layout, GUIContent content, GUIElementStyle style, GUIOption[] options);
+        private static extern void Internal_CreateInstance(GUIButton instance, GUIContent content, GUIElementStyle style, GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);
         private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);

+ 21 - 31
MBansheeEngine/GUI/GUIElement.cs

@@ -4,64 +4,54 @@ using System.Runtime.CompilerServices;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-    public class GUIElement : ScriptObject
+    public abstract class GUIElement : ScriptObject
     {
     {
-        protected GUIElement parent;
-        protected List<GUIElement> children = new List<GUIElement>();
+        protected GUILayout parent;
+        private bool isDestroyed;
 
 
-        internal GUIElement(GUIElement parent)
+        internal void SetParent(GUILayout layout)
         {
         {
-            this.parent = parent;
+            if (parent != null)
+                parent.Remove(this);
+
+            parent = layout;
 
 
             if (parent != null)
             if (parent != null)
                 parent.children.Add(this);
                 parent.children.Add(this);
-        }
 
 
-        public int GetNumChildren()
-        {
-            return children.Count;
+            Internal_SetParent(mCachedPtr, layout);
         }
         }
 
 
-        public GUIElement GetChild(int index)
+        internal virtual bool IsStatic()
         {
         {
-            if (index < 0 || index >= children.Count)
-                return null;
-
-            return children[index];
+            return false;
         }
         }
 
 
-        public void Destroy()
+        public virtual void Destroy()
         {
         {
-            for (int i = 0; i < children.Count; i++)
-                children[i].Destroy();
-
-            children.Clear();
-
-            if (parent != null)
-                parent.children.Remove(this);
-
-            parent = null;
+            SetParent(null);
 
 
             Internal_Destroy(mCachedPtr);
             Internal_Destroy(mCachedPtr);
+            isDestroyed = true;
         }
         }
 
 
-        public void Enable()
+        public bool IsDestroyed()
         {
         {
-            Internal_Enable(mCachedPtr);
+            return isDestroyed;
         }
         }
 
 
-        public void Disable()
+        public void SetVisible(bool visible)
         {
         {
-            Internal_Disable(mCachedPtr);
+            Internal_SetVisible(mCachedPtr, visible);
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Destroy(IntPtr nativeInstance);
+        private static extern void Internal_SetParent(IntPtr nativeInstance, GUILayout parent);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Enable(IntPtr nativeInstance);
+        private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_Disable(IntPtr nativeInstance);
+        private static extern void Internal_Destroy(IntPtr nativeInstance);
     }
     }
 }
 }

+ 3 - 4
MBansheeEngine/GUI/GUILabel.cs

@@ -5,10 +5,9 @@ namespace BansheeEngine
 {
 {
     public sealed class GUILabel : GUIElement
     public sealed class GUILabel : GUIElement
     {
     {
-        internal GUILabel(GUILayout parentLayout, GUIContent content, GUIElementStyle style, params GUIOption[] options)
-            :base(parentLayout)
+        public GUILabel(GUIContent content, GUIElementStyle style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, content, style, options);
+            Internal_CreateInstance(this, content, style, options);
         }
         }
 
 
         public void SetContent(GUIContent content)
         public void SetContent(GUIContent content)
@@ -17,7 +16,7 @@ namespace BansheeEngine
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUILabel instance, GUILayout layout, GUIContent content, GUIElementStyle style, GUIOption[] options);
+        private static extern void Internal_CreateInstance(GUILabel instance, GUIContent content, GUIElementStyle style, GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);
         private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);

+ 56 - 103
MBansheeEngine/GUI/GUILayout.cs

@@ -1,157 +1,110 @@
 using System;
 using System;
+using System.Collections.Generic;
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
     public abstract class GUILayout : GUIElement
     public abstract class GUILayout : GUIElement
     {
     {
-        internal GUILayout(GUIElement parent)
-            :base(parent)
-        { }
+        internal List<GUIElement> children = new List<GUIElement>();
 
 
-        public GUILabel AddLabel(GUIContent content, GUIElementStyle style, params GUIOption[] options)
+        internal override bool IsStatic()
         {
         {
-            return new GUILabel(this, content, style, options);
+            return true;
         }
         }
 
 
-        public GUILabel AddLabel(GUIContent content, params GUIOption[] options)
+        internal void AddElementInternal(GUIElement element)
         {
         {
-            return new GUILabel(this, content, null, options);
-        }
-
-        public GUIButton AddButton(GUIContent content, GUIElementStyle style, params GUIOption[] options)
-        {
-            return new GUIButton(this, content, style, options);
-        }
-
-        public GUIButton AddButton(GUIContent content, GUIElementStyle style)
-        {
-            return new GUIButton(this, content, style, new GUIOption[0]);
-        }
-
-        public GUIButton AddButton(GUIContent content, params GUIOption[] options)
-        {
-            return new GUIButton(this, content, null, options);
-        }
-
-        public GUIToggle AddToggle(GUIContent content, GUIElementStyle style, params GUIOption[] options)
-        {
-            return new GUIToggle(this, content, null, style, options);
-        }
-
-        public GUIToggle AddToggle(GUIContent content, GUIElementStyle style)
-        {
-            return new GUIToggle(this, content, null, style, new GUIOption[0]);
-        }
-
-        public GUIToggle AddToggle(GUIContent content, params GUIOption[] options)
-        {
-            return new GUIToggle(this, content, null, null, options);
-        }
-
-        public GUIToggle AddToggle(GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style, params GUIOption[] options)
-        {
-            return new GUIToggle(this, content, toggleGroup, style, options);
-        }
-
-        public GUIToggle AddToggle(GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style)
-        {
-            return new GUIToggle(this, content, toggleGroup, style, new GUIOption[0]);
-        }
+            if (IsDestroyed())
+            {
+                Debug.LogWarning("Attempting to add an element to a destroyed layout. Ignoring operation.");
+                return;
+            }
 
 
-        public GUIToggle AddToggle(GUIContent content, GUIToggleGroup toggleGroup, params GUIOption[] options)
-        {
-            return new GUIToggle(this, content, toggleGroup, null, options);
+            if (!children.Contains(element))
+                element.SetParent(this);
         }
         }
 
 
-        public GUITexture AddTexture(SpriteTexture texture, GUIImageScaleMode scale, GUIElementStyle style, params GUIOption[] options)
+        public void AddElement(GUIElement element)
         {
         {
-            return new GUITexture(this, texture, scale, style, options);
-        }
+            if (element.IsStatic())
+            {
+                Debug.LogWarning("You are trying to change parent of a static GUI element. Ignoring operation.");
+                return;
+            }
 
 
-        public GUITexture AddTexture(SpriteTexture texture, GUIImageScaleMode scale, params GUIOption[] options)
-        {
-            return new GUITexture(this, texture, scale, null, options);
+            AddElementInternal(element);
         }
         }
 
 
-        public GUITexture AddTexture(SpriteTexture texture, GUIElementStyle style, params GUIOption[] options)
+        public GUIFixedSpace AddSpace(int size)
         {
         {
-            return new GUITexture(this, texture, GUIImageScaleMode.StretchToFit, style, options);
-        }
+            GUIFixedSpace fixedSpace = new GUIFixedSpace(this, size);
+            AddElementInternal(fixedSpace);
 
 
-        public GUITexture AddTexture(SpriteTexture texture, params GUIOption[] options)
-        {
-            return new GUITexture(this, texture, GUIImageScaleMode.StretchToFit, null, options);
+            return fixedSpace;
         }
         }
 
 
-        public GUITextBox AddTextBox(bool multiline, GUIElementStyle style, params GUIOption[] options)
+        public GUIFlexibleSpace AddFlexibleSpace()
         {
         {
-            return new GUITextBox(this, multiline, style, options);
-        }
+            GUIFlexibleSpace flexibleSpace = new GUIFlexibleSpace(this);
+            AddElementInternal(flexibleSpace);
 
 
-        public GUITextBox AddTextBox(bool multiline, params GUIOption[] options)
-        {
-            return new GUITextBox(this, multiline, null, options);
+            return flexibleSpace;
         }
         }
 
 
-        public GUITextBox AddTextBox(GUIElementStyle style, params GUIOption[] options)
+        public GUILayoutX AddLayoutX()
         {
         {
-            return new GUITextBox(this, false, style, options);
-        }
+            GUILayoutX layoutX = new GUILayoutX(this);
+            AddElementInternal(layoutX);
 
 
-        public GUITextBox AddTextBox(params GUIOption[] options)
-        {
-            return new GUITextBox(this, false, null, options);
+            return layoutX;
         }
         }
 
 
-        public GUIScrollArea AddScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, GUIElementStyle style, params GUIOption[] options)
+        public GUILayoutY AddLayoutY()
         {
         {
-            return new GUIScrollArea(this, vertBarType, horzBarType, null, style, options);
-        }
+            GUILayoutY layoutY = new GUILayoutY(this);
+            AddElementInternal(layoutY);
 
 
-        public GUIScrollArea AddScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
-        {
-            return new GUIScrollArea(this, vertBarType, horzBarType, null, null, options);
+            return layoutY;
         }
         }
 
 
-        public GUIScrollArea AddScrollArea(GUIElementStyle style, params GUIOption[] options)
+        public void Remove(GUIElement element)
         {
         {
-            return new GUIScrollArea(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, null, style, options);
+            if (children.Contains(element))
+                element.SetParent(null);
         }
         }
 
 
-        public GUIScrollArea AddScrollArea(params GUIOption[] options)
+        public void Remove(int childIdx)
         {
         {
-            return new GUIScrollArea(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, null, null, options);
+            if (childIdx >= 0 && childIdx < children.Count)
+            {
+                GUIElement element = children[childIdx];
+                element.SetParent(null);
+            }
         }
         }
 
 
-        public GUIScrollArea AddScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options)
+        public int GetNumChildren()
         {
         {
-            return new GUIScrollArea(this, vertBarType, horzBarType, scrollBarStyle, scrollAreaStyle, options);
+            return children.Count;
         }
         }
 
 
-        public GUIScrollArea AddScrollArea(GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options)
+        public GUIElement GetChild(int index)
         {
         {
-            return new GUIScrollArea(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
-        }
+            if (index < 0 || index >= children.Count)
+                return null;
 
 
-        public GUIListBox AddListBox(LocString[] elements, GUIElementStyle style, params GUIOption[] options)
-        {
-            return new GUIListBox(this, elements, style, options);
+            return children[index];
         }
         }
 
 
-        public GUIListBox AddListBox(LocString[] elements, params GUIOption[] options)
+        public override void Destroy()
         {
         {
-            return new GUIListBox(this, elements, null, options);
-        }
+            GUIElement[] childArray = children.ToArray(); // Iterating over it will modify it so make a copy
+            for (int i = 0; i < childArray.Length; i++)
+                childArray[i].Destroy();
 
 
-        public GUIFixedSpace AddSpace(int size)
-        {
-            return new GUIFixedSpace(this, size);
-        }
+            children.Clear();
 
 
-        public GUIFlexibleSpace AddFlexibleSpace()
-        {
-            return new GUIFlexibleSpace(this);
+            base.Destroy();
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]

+ 0 - 2
MBansheeEngine/GUI/GUILayoutX.cs

@@ -6,13 +6,11 @@ namespace BansheeEngine
     public sealed class GUILayoutX : GUILayout
     public sealed class GUILayoutX : GUILayout
     {
     {
         internal GUILayoutX(GUIArea parentArea)
         internal GUILayoutX(GUIArea parentArea)
-            :base(null)
         {
         {
             Internal_CreateInstanceXFromArea(this, parentArea);
             Internal_CreateInstanceXFromArea(this, parentArea);
         }
         }
 
 
         internal GUILayoutX(GUILayout parentLayout)
         internal GUILayoutX(GUILayout parentLayout)
-            :base(parentLayout)
         {
         {
             Internal_CreateInstanceXFromLayout(this, parentLayout);
             Internal_CreateInstanceXFromLayout(this, parentLayout);
         }
         }

+ 0 - 2
MBansheeEngine/GUI/GUILayoutY.cs

@@ -6,13 +6,11 @@ namespace BansheeEngine
     public sealed class GUILayoutY : GUILayout
     public sealed class GUILayoutY : GUILayout
     {
     {
         internal GUILayoutY(GUILayout parentLayout)
         internal GUILayoutY(GUILayout parentLayout)
-            :base(parentLayout)
         {
         {
             Internal_CreateInstanceYFromLayout(this, parentLayout);
             Internal_CreateInstanceYFromLayout(this, parentLayout);
         }
         }
 
 
         internal GUILayoutY(GUIScrollArea parentArea)
         internal GUILayoutY(GUIScrollArea parentArea)
-            :base(parentArea)
         {
         {
             Internal_CreateInstanceYFromScrollArea(this, parentArea);
             Internal_CreateInstanceYFromScrollArea(this, parentArea);
         }
         }

+ 8 - 4
MBansheeEngine/GUI/GUIListBox.cs

@@ -9,10 +9,14 @@ namespace BansheeEngine
 
 
         public event OnSelectionChangedDelegate OnSelectionChanged;
         public event OnSelectionChangedDelegate OnSelectionChanged;
 
 
-        internal GUIListBox(GUILayout parentLayout, LocString[] elements, GUIElementStyle style, params GUIOption[] options)
-            :base(parentLayout)
+        public GUIListBox(LocString[] elements, GUIElementStyle style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, elements, style, options);
+            Internal_CreateInstance(this, elements, style, options);
+        }
+
+        public GUIListBox(LocString[] elements, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, elements, null, options);
         }
         }
 
 
         public void SetElements(LocString[] elements)
         public void SetElements(LocString[] elements)
@@ -27,7 +31,7 @@ namespace BansheeEngine
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUIListBox instance, GUILayout parentLayout, LocString[] elements, GUIElementStyle style, params GUIOption[] options);
+        private static extern void Internal_CreateInstance(GUIListBox instance, LocString[] elements, GUIElementStyle style, params GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetElements(IntPtr nativeInstance, LocString[] elements);
         private static extern void Internal_SetElements(IntPtr nativeInstance, LocString[] elements);

+ 41 - 5
MBansheeEngine/GUI/GUIScrollArea.cs

@@ -18,16 +18,52 @@ namespace BansheeEngine
             get { return _mainLayout; }
             get { return _mainLayout; }
         }
         }
 
 
-        internal GUIScrollArea(GUILayout parentLayout, ScrollBarType vertBarType, ScrollBarType horzBarType, 
-            GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options)
-            :base(parentLayout)
+        public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, GUIElementStyle scrollBarStyle, 
+            GUIElementStyle scrollAreaStyle, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, vertBarType, horzBarType, scrollBarStyle, scrollAreaStyle, options);
+            Internal_CreateInstance(this, vertBarType, horzBarType, scrollBarStyle, scrollAreaStyle, options);
             _mainLayout = new GUILayoutY(this);
             _mainLayout = new GUILayoutY(this);
         }
         }
 
 
+        public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, vertBarType, horzBarType, null, style, options);
+            _mainLayout = new GUILayoutY(this);
+        }
+
+        public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, vertBarType, horzBarType, null, null, options);
+            _mainLayout = new GUILayoutY(this);
+        }
+
+        public GUIScrollArea(GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, null, style, options);
+            _mainLayout = new GUILayoutY(this);
+        }
+
+        public GUIScrollArea(params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, null, null, options);
+            _mainLayout = new GUILayoutY(this);
+        }
+
+        public GUIScrollArea(GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
+            _mainLayout = new GUILayoutY(this);
+        }
+
+        public override void Destroy()
+        {
+            _mainLayout.Destroy();
+
+            base.Destroy();
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUIScrollArea instance, GUILayout parentLayout, ScrollBarType vertBarType, ScrollBarType horzBarType,
+        private static extern void Internal_CreateInstance(GUIScrollArea instance, ScrollBarType vertBarType, ScrollBarType horzBarType,
             GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options);
             GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options);
     }
     }
 }
 }

+ 10 - 2
MBansheeEngine/GUI/GUISpace.cs

@@ -5,11 +5,15 @@ namespace BansheeEngine
     public sealed class GUIFixedSpace : GUIElement
     public sealed class GUIFixedSpace : GUIElement
     {
     {
         internal GUIFixedSpace(GUILayout parentLayout, int size)
         internal GUIFixedSpace(GUILayout parentLayout, int size)
-            :base(parentLayout)
         {
         {
             Internal_CreateInstance(this, parentLayout, size);
             Internal_CreateInstance(this, parentLayout, size);
         }
         }
 
 
+        internal override bool IsStatic()
+        {
+            return true;
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CreateInstance(GUIFixedSpace instance, GUILayout parentLayout, int size);
         private static extern void Internal_CreateInstance(GUIFixedSpace instance, GUILayout parentLayout, int size);
     }
     }
@@ -17,11 +21,15 @@ namespace BansheeEngine
     public sealed class GUIFlexibleSpace : GUIElement
     public sealed class GUIFlexibleSpace : GUIElement
     {
     {
         internal GUIFlexibleSpace(GUILayout parentLayout)
         internal GUIFlexibleSpace(GUILayout parentLayout)
-            :base(parentLayout)
         {
         {
             Internal_CreateInstance(this, parentLayout);
             Internal_CreateInstance(this, parentLayout);
         }
         }
 
 
+        internal override bool IsStatic()
+        {
+            return true;
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CreateInstance(GUIFlexibleSpace instance, GUILayout parentLayout);
         private static extern void Internal_CreateInstance(GUIFlexibleSpace instance, GUILayout parentLayout);
     }
     }

+ 18 - 4
MBansheeEngine/GUI/GUITextBox.cs

@@ -5,10 +5,24 @@ namespace BansheeEngine
 {
 {
     public sealed class GUITextBox : GUIElement
     public sealed class GUITextBox : GUIElement
     {
     {
-        internal GUITextBox(GUILayout parentLayout, bool multiline, GUIElementStyle style, params GUIOption[] options)
-            :base(parentLayout)
+        public GUITextBox(bool multiline, GUIElementStyle style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, multiline, style, options);
+            Internal_CreateInstance(this, multiline, style, options);
+        }
+
+        public GUITextBox(bool multiline, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, multiline, null, options);
+        }
+
+        public GUITextBox(GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, false, style, options);
+        }
+
+        public GUITextBox(params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, false, null, options);
         }
         }
 
 
         public string text
         public string text
@@ -18,7 +32,7 @@ namespace BansheeEngine
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUITextBox instance, GUILayout layout, bool multiline, GUIElementStyle style, GUIOption[] options);
+        private static extern void Internal_CreateInstance(GUITextBox instance, bool multiline, GUIElementStyle style, GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetText(IntPtr nativeInstance, string text);
         private static extern void Internal_SetText(IntPtr nativeInstance, string text);

+ 18 - 5
MBansheeEngine/GUI/GUITexture.cs

@@ -11,13 +11,26 @@ namespace BansheeEngine
 		RepeatToFit
 		RepeatToFit
 	};
 	};
 
 
-
     public sealed class GUITexture : GUIElement
     public sealed class GUITexture : GUIElement
     {
     {
-        internal GUITexture(GUILayout parentLayout, SpriteTexture texture, GUIImageScaleMode scale, GUIElementStyle style, params GUIOption[] options)
-            :base(parentLayout)
+        public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, scale, style, options);
+        }
+
+        public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, scale, null, options);
+        }
+
+        public GUITexture(SpriteTexture texture, GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, style, options);
+        }
+
+        public GUITexture(SpriteTexture texture, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, texture, scale, style, options);
+            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, null, options);
         }
         }
 
 
         public void SetTexture(SpriteTexture texture)
         public void SetTexture(SpriteTexture texture)
@@ -26,7 +39,7 @@ namespace BansheeEngine
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUITexture instance, GUILayout layout, SpriteTexture texture, 
+        private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture, 
             GUIImageScaleMode scale, GUIElementStyle style, GUIOption[] options);
             GUIImageScaleMode scale, GUIElementStyle style, GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]

+ 28 - 4
MBansheeEngine/GUI/GUIToggle.cs

@@ -15,10 +15,34 @@ namespace BansheeEngine
         public event OnOutDelegate OnOut;
         public event OnOutDelegate OnOut;
         public event OnToggleDelegate OnToggled;
         public event OnToggleDelegate OnToggled;
 
 
-        internal GUIToggle(GUILayout parentLayout, GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style, params GUIOption[] options)
-            :base(parentLayout)
+        public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, parentLayout, content, toggleGroup, style, options);
+            Internal_CreateInstance(this, content, toggleGroup, style, options);
+        }
+
+        public GUIToggle(GUIContent content, GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, content, null, style, options);
+        }
+
+        public GUIToggle(GUIContent content, GUIElementStyle style)
+        {
+            Internal_CreateInstance(this, content, null, style, new GUIOption[0]);
+        }
+
+        public GUIToggle(GUIContent content, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, content, null, null, options);
+        }
+
+        public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style)
+        {
+            Internal_CreateInstance(this, content, toggleGroup, style, new GUIOption[0]);
+        }
+
+        public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, content, toggleGroup, null, options);
         }
         }
 
 
         public void SetContent(GUIContent content)
         public void SetContent(GUIContent content)
@@ -61,7 +85,7 @@ namespace BansheeEngine
         }
         }
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(GUIToggle instance, GUILayout layout, GUIContent content, 
+        private static extern void Internal_CreateInstance(GUIToggle instance, GUIContent content, 
             GUIToggleGroup toggleGroup, GUIElementStyle style, GUIOption[] options);
             GUIToggleGroup toggleGroup, GUIElementStyle style, GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]

+ 1 - 0
MBansheeEngine/MBansheeEngine.csproj

@@ -43,6 +43,7 @@
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <Compile Include="BuiltinResources.cs" />
     <Compile Include="BuiltinResources.cs" />
+    <Compile Include="Debug.cs" />
     <Compile Include="Color.cs" />
     <Compile Include="Color.cs" />
     <Compile Include="Component.cs" />
     <Compile Include="Component.cs" />
     <Compile Include="DbgComponent.cs" />
     <Compile Include="DbgComponent.cs" />

+ 4 - 4
SBansheeEngine/Include/BsScriptGUIArea.h

@@ -13,8 +13,6 @@ namespace BansheeEngine
 		GUIArea* getInternalValue() const { return mArea; }
 		GUIArea* getInternalValue() const { return mArea; }
 		void* getNativeRaw() const { return mArea; }
 		void* getNativeRaw() const { return mArea; }
 
 
-		GUIWidget& getParentWidget() const;
-
 	private:
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* parentGUI, CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height, CM::UINT16 depth);
 		static void internal_createInstance(MonoObject* instance, MonoObject* parentGUI, CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height, CM::UINT16 depth);
 		static void internal_createInstanceResizeableX(MonoObject* instance, MonoObject* parentGUI, CM::UINT32 offsetLeft, CM::UINT32 offsetRight, 
 		static void internal_createInstanceResizeableX(MonoObject* instance, MonoObject* parentGUI, CM::UINT32 offsetLeft, CM::UINT32 offsetRight, 
@@ -29,14 +27,16 @@ namespace BansheeEngine
 		static void internal_destroyInstance(ScriptGUIArea* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIArea* nativeInstance);
 
 
 		static void internal_destroy(ScriptGUIArea* nativeInstance);
 		static void internal_destroy(ScriptGUIArea* nativeInstance);
-		static void internal_disable(ScriptGUIArea* nativeInstance);
-		static void internal_enable(ScriptGUIArea* nativeInstance);
+		static void internal_setVisible(ScriptGUIArea* nativeInstance, bool visible);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
 		ScriptGUIArea(GUIArea* area, ScriptGUIBase* parentGUI);
 		ScriptGUIArea(GUIArea* area, ScriptGUIBase* parentGUI);
 
 
+		void destroy();
+
 		GUIArea* mArea;
 		GUIArea* mArea;
 		ScriptGUIBase* mParentGUI;
 		ScriptGUIBase* mParentGUI;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 3
SBansheeEngine/Include/BsScriptGUIButton.h

@@ -14,13 +14,13 @@ namespace BansheeEngine
 		void* getNativeRaw() const { return mButton; }
 		void* getNativeRaw() const { return mButton; }
 
 
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* content, MonoObject* style, MonoArray* guiOptions);
+		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoObject* style, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUIButton* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIButton* nativeInstance);
 		static void internal_setContent(ScriptGUIButton* nativeInstance, MonoObject* content);
 		static void internal_setContent(ScriptGUIButton* nativeInstance, MonoObject* content);
 
 
 		static void internal_destroy(ScriptGUIButton* nativeInstance);
 		static void internal_destroy(ScriptGUIButton* nativeInstance);
-		static void internal_disable(ScriptGUIButton* nativeInstance);
-		static void internal_enable(ScriptGUIButton* nativeInstance);
+		static void internal_setVisible(ScriptGUIButton* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIButton* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
@@ -30,7 +30,10 @@ namespace BansheeEngine
 
 
 		ScriptGUIButton(GUIButton* button);
 		ScriptGUIButton(GUIButton* button);
 
 
+		void destroy();
+
 		GUIButton* mButton;
 		GUIButton* mButton;
+		bool mIsDestroyed;
 
 
 		typedef void (__stdcall *OnClickThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnClickThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnHoverThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnHoverThunkDef) (MonoObject*, MonoException**);

+ 5 - 3
SBansheeEngine/Include/BsScriptGUIFixedSpace.h

@@ -15,15 +15,17 @@ namespace BansheeEngine
 		static void internal_destroyInstance(ScriptGUIFixedSpace* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIFixedSpace* nativeInstance);
 
 
 		static void internal_destroy(ScriptGUIFixedSpace* nativeInstance);
 		static void internal_destroy(ScriptGUIFixedSpace* nativeInstance);
-		static void internal_disable(ScriptGUIFixedSpace* nativeInstance);
-		static void internal_enable(ScriptGUIFixedSpace* nativeInstance);
+		static void internal_setVisible(ScriptGUIFixedSpace* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIFixedSpace* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
 		ScriptGUIFixedSpace(GUIFixedSpace& fixedSpace, GUILayout* parentLayout);
 		ScriptGUIFixedSpace(GUIFixedSpace& fixedSpace, GUILayout* parentLayout);
 
 
+		void destroy();
+
 		GUIFixedSpace& mFixedSpace;
 		GUIFixedSpace& mFixedSpace;
 		GUILayout* mParentLayout;
 		GUILayout* mParentLayout;
-
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 5 - 2
SBansheeEngine/Include/BsScriptGUIFlexibleSpace.h

@@ -15,14 +15,17 @@ namespace BansheeEngine
 		static void internal_destroyInstance(ScriptGUIFlexibleSpace* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIFlexibleSpace* nativeInstance);
 
 
 		static void internal_destroy(ScriptGUIFlexibleSpace* nativeInstance);
 		static void internal_destroy(ScriptGUIFlexibleSpace* nativeInstance);
-		static void internal_disable(ScriptGUIFlexibleSpace* nativeInstance);
-		static void internal_enable(ScriptGUIFlexibleSpace* nativeInstance);
+		static void internal_setVisible(ScriptGUIFlexibleSpace* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIFlexibleSpace* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
 		ScriptGUIFlexibleSpace(GUIFlexibleSpace& flexibleSpace, GUILayout* parentLayout);
 		ScriptGUIFlexibleSpace(GUIFlexibleSpace& flexibleSpace, GUILayout* parentLayout);
 
 
+		void destroy();
+
 		GUIFlexibleSpace& mFlexibleSpace;
 		GUIFlexibleSpace& mFlexibleSpace;
 		GUILayout* mParentLayout;
 		GUILayout* mParentLayout;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 3
SBansheeEngine/Include/BsScriptGUIInputBox.h

@@ -15,20 +15,23 @@ namespace BansheeEngine
 		void* getNativeRaw() const { return mInputBox; }
 		void* getNativeRaw() const { return mInputBox; }
 
 
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, bool multiline, MonoObject* style, MonoArray* guiOptions);
+		static void internal_createInstance(MonoObject* instance, bool multiline, MonoObject* style, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUIInputBox* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIInputBox* nativeInstance);
 
 
 		static void internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text);
 		static void internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text);
 		static void internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text);
 		static void internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text);
 
 
 		static void internal_destroy(ScriptGUIInputBox* nativeInstance);
 		static void internal_destroy(ScriptGUIInputBox* nativeInstance);
-		static void internal_disable(ScriptGUIInputBox* nativeInstance);
-		static void internal_enable(ScriptGUIInputBox* nativeInstance);
+		static void internal_setVisible(ScriptGUIInputBox* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIInputBox* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
 		ScriptGUIInputBox(GUIInputBox* inputBox);
 		ScriptGUIInputBox(GUIInputBox* inputBox);
 
 
+		void destroy();
+
 		GUIInputBox* mInputBox;
 		GUIInputBox* mInputBox;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 3
SBansheeEngine/Include/BsScriptGUILabel.h

@@ -14,18 +14,21 @@ namespace BansheeEngine
 		void* getNativeRaw() const { return mLabel; }
 		void* getNativeRaw() const { return mLabel; }
 
 
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* content, MonoObject* style, MonoArray* guiOptions);
+		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoObject* style, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUILabel* nativeInstance);
 		static void internal_destroyInstance(ScriptGUILabel* nativeInstance);
 		static void internal_setContent(ScriptGUILabel* nativeInstance, MonoObject* content);
 		static void internal_setContent(ScriptGUILabel* nativeInstance, MonoObject* content);
 
 
 		static void internal_destroy(ScriptGUILabel* nativeInstance);
 		static void internal_destroy(ScriptGUILabel* nativeInstance);
-		static void internal_disable(ScriptGUILabel* nativeInstance);
-		static void internal_enable(ScriptGUILabel* nativeInstance);
+		static void internal_setVisible(ScriptGUILabel* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUILabel* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
 		ScriptGUILabel(GUILabel* label);
 		ScriptGUILabel(GUILabel* label);
 
 
+		void destroy();
+
 		GUILabel* mLabel;
 		GUILabel* mLabel;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 6
SBansheeEngine/Include/BsScriptGUILayout.h

@@ -13,8 +13,6 @@ namespace BansheeEngine
 		GUILayout* getInternalValue() const { return mLayout; }
 		GUILayout* getInternalValue() const { return mLayout; }
 		void* getNativeRaw() const { return mLayout; }
 		void* getNativeRaw() const { return mLayout; }
 
 
-		GUIWidget& getParentWidget() const { return mParentWidget; }
-
 	private:
 	private:
 		static void internal_createInstanceXFromArea(MonoObject* instance, MonoObject* parentArea);
 		static void internal_createInstanceXFromArea(MonoObject* instance, MonoObject* parentArea);
 		static void internal_createInstanceXFromLayout(MonoObject* instance, MonoObject* parentLayout);
 		static void internal_createInstanceXFromLayout(MonoObject* instance, MonoObject* parentLayout);
@@ -23,15 +21,17 @@ namespace BansheeEngine
 		static void internal_destroyInstance(ScriptGUILayout* nativeInstance);
 		static void internal_destroyInstance(ScriptGUILayout* nativeInstance);
 
 
 		static void internal_destroy(ScriptGUILayout* nativeInstance);
 		static void internal_destroy(ScriptGUILayout* nativeInstance);
-		static void internal_disable(ScriptGUILayout* nativeInstance);
-		static void internal_enable(ScriptGUILayout* nativeInstance);
+		static void internal_setVisible(ScriptGUILayout* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUILayout* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
-		ScriptGUILayout(GUILayout* layout, GUIWidget& parentWidget, GUILayout* parentLayout);
+		ScriptGUILayout(GUILayout* layout, GUILayout* parentLayout);
+
+		void destroy();
 
 
 		GUILayout* mLayout;
 		GUILayout* mLayout;
 		GUILayout* mParentLayout;
 		GUILayout* mParentLayout;
-		GUIWidget& mParentWidget;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 3
SBansheeEngine/Include/BsScriptGUIListBox.h

@@ -15,13 +15,13 @@ namespace BansheeEngine
 		void* getNativeRaw() const { return mListBox; }
 		void* getNativeRaw() const { return mListBox; }
 
 
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoArray* elements, MonoObject* style, MonoArray* guiOptions);
+		static void internal_createInstance(MonoObject* instance, MonoArray* elements, MonoObject* style, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUIListBox* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIListBox* nativeInstance);
 		static void internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements);
 		static void internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements);
 
 
 		static void internal_destroy(ScriptGUIListBox* nativeInstance);
 		static void internal_destroy(ScriptGUIListBox* nativeInstance);
-		static void internal_disable(ScriptGUIListBox* nativeInstance);
-		static void internal_enable(ScriptGUIListBox* nativeInstance);
+		static void internal_setVisible(ScriptGUIListBox* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIListBox* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
@@ -29,7 +29,10 @@ namespace BansheeEngine
 
 
 		ScriptGUIListBox(GUIListBox* listBox);
 		ScriptGUIListBox(GUIListBox* listBox);
 
 
+		void destroy();
+
 		GUIListBox* mListBox;
 		GUIListBox* mListBox;
+		bool mIsDestroyed;
 
 
 		typedef void (__stdcall *OnSelectionChangedThunkDef) (MonoObject*, CM::UINT32, MonoException**);
 		typedef void (__stdcall *OnSelectionChangedThunkDef) (MonoObject*, CM::UINT32, MonoException**);
 		static OnSelectionChangedThunkDef onSelectionChangedThunk;
 		static OnSelectionChangedThunkDef onSelectionChangedThunk;

+ 7 - 6
SBansheeEngine/Include/BsScriptGUIScrollArea.h

@@ -14,21 +14,22 @@ namespace BansheeEngine
 		GUIScrollArea* getInternalValue() const { return mScrollArea; }
 		GUIScrollArea* getInternalValue() const { return mScrollArea; }
 		void* getNativeRaw() const { return mScrollArea; }
 		void* getNativeRaw() const { return mScrollArea; }
 
 
-		GUIWidget& getParentWidget() const;
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, ScrollBarType vertBarType, ScrollBarType horzBarType, 
+		static void internal_createInstance(MonoObject* instance, ScrollBarType vertBarType, ScrollBarType horzBarType, 
 			MonoObject* scrollBarStyle, MonoObject* scrollAreaStyle, MonoArray* guiOptions);
 			MonoObject* scrollBarStyle, MonoObject* scrollAreaStyle, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUIScrollArea* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIScrollArea* nativeInstance);
 
 
 		static void internal_destroy(ScriptGUIScrollArea* nativeInstance);
 		static void internal_destroy(ScriptGUIScrollArea* nativeInstance);
-		static void internal_disable(ScriptGUIScrollArea* nativeInstance);
-		static void internal_enable(ScriptGUIScrollArea* nativeInstance);
+		static void internal_setVisible(ScriptGUIScrollArea* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIScrollArea* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
-		ScriptGUIScrollArea(GUIScrollArea* scrollArea, GUIWidget& parentWidget);
+		ScriptGUIScrollArea(GUIScrollArea* scrollArea);
+
+		void destroy();
 
 
 		GUIScrollArea* mScrollArea;
 		GUIScrollArea* mScrollArea;
-		GUIWidget& mParentWidget;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 3
SBansheeEngine/Include/BsScriptGUITexture.h

@@ -15,19 +15,22 @@ namespace BansheeEngine
 		void* getNativeRaw() const { return mTexture; }
 		void* getNativeRaw() const { return mTexture; }
 
 
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* texture, 
+		static void internal_createInstance(MonoObject* instance, MonoObject* texture, 
 			GUIImageScaleMode scale, MonoObject* style, MonoArray* guiOptions);
 			GUIImageScaleMode scale, MonoObject* style, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUITexture* nativeInstance);
 		static void internal_destroyInstance(ScriptGUITexture* nativeInstance);
 		static void internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture);
 		static void internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture);
 
 
 		static void internal_destroy(ScriptGUITexture* nativeInstance);
 		static void internal_destroy(ScriptGUITexture* nativeInstance);
-		static void internal_disable(ScriptGUITexture* nativeInstance);
-		static void internal_enable(ScriptGUITexture* nativeInstance);
+		static void internal_setVisible(ScriptGUITexture* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUITexture* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
 		ScriptGUITexture(GUITexture* texture);
 		ScriptGUITexture(GUITexture* texture);
 
 
+		void destroy();
+
 		GUITexture* mTexture;
 		GUITexture* mTexture;
+		bool mIsDestroyed;
 	};
 	};
 }
 }

+ 6 - 3
SBansheeEngine/Include/BsScriptGUIToggle.h

@@ -14,7 +14,7 @@ namespace BansheeEngine
 		void* getNativeRaw() const { return mToggle; }
 		void* getNativeRaw() const { return mToggle; }
 
 
 	private:
 	private:
-		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* content, 
+		static void internal_createInstance(MonoObject* instance, MonoObject* content, 
 			MonoObject* toggleGroup, MonoObject* style, MonoArray* guiOptions);
 			MonoObject* toggleGroup, MonoObject* style, MonoArray* guiOptions);
 		static void internal_destroyInstance(ScriptGUIToggle* nativeInstance);
 		static void internal_destroyInstance(ScriptGUIToggle* nativeInstance);
 		static void internal_setContent(ScriptGUIToggle* nativeInstance, MonoObject* content);
 		static void internal_setContent(ScriptGUIToggle* nativeInstance, MonoObject* content);
@@ -22,8 +22,8 @@ namespace BansheeEngine
 		static void internal_toggleOff(ScriptGUIToggle* nativeInstance);
 		static void internal_toggleOff(ScriptGUIToggle* nativeInstance);
 
 
 		static void internal_destroy(ScriptGUIToggle* nativeInstance);
 		static void internal_destroy(ScriptGUIToggle* nativeInstance);
-		static void internal_disable(ScriptGUIToggle* nativeInstance);
-		static void internal_enable(ScriptGUIToggle* nativeInstance);
+		static void internal_setVisible(ScriptGUIToggle* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIToggle* nativeInstance, MonoObject* parentLayout);
 
 
 		static void initRuntimeData();
 		static void initRuntimeData();
 
 
@@ -34,7 +34,10 @@ namespace BansheeEngine
 
 
 		ScriptGUIToggle(GUIToggle* toggle);
 		ScriptGUIToggle(GUIToggle* toggle);
 
 
+		void destroy();
+
 		GUIToggle* mToggle;
 		GUIToggle* mToggle;
+		bool mIsDestroyed;
 
 
 		typedef void (__stdcall *OnClickThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnClickThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnHoverThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnHoverThunkDef) (MonoObject*, MonoException**);

+ 102 - 96
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -13,29 +13,17 @@
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
       <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
     </Filter>
     </Filter>
+    <Filter Include="Header Files\GUI">
+      <UniqueIdentifier>{90896fa0-9186-412e-bad6-b57e3ae7c060}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="Source Files\GUI">
+      <UniqueIdentifier>{a412791a-7e2f-4aea-a34f-6c2ad7f1246c}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="Include\BsScriptFont.h">
     <ClInclude Include="Include\BsScriptFont.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIArea.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIBase.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIElementStateStyle.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIElementStyle.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUILabel.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUILayout.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsScriptObject.h">
     <ClInclude Include="Include\BsScriptObject.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -57,36 +45,6 @@
     <ClInclude Include="Include\BsScriptHString.h">
     <ClInclude Include="Include\BsScriptHString.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIContent.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIFixedSpace.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIFlexibleSpace.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIButton.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUITexture.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIInputBox.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIScrollArea.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIListBox.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIToggleGroup.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="Include\BsScriptGUIToggle.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsRuntimeScriptObjects.h">
     <ClInclude Include="Include\BsRuntimeScriptObjects.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
@@ -150,6 +108,54 @@
     <ClInclude Include="Include\BsScriptSerializableDictionaryRTTI.h">
     <ClInclude Include="Include\BsScriptSerializableDictionaryRTTI.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIArea.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIBase.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIButton.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIContent.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIElementStateStyle.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIElementStyle.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIFixedSpace.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIFlexibleSpace.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIInputBox.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUILabel.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUILayout.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIListBox.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIScrollArea.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUITexture.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIToggle.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIToggleGroup.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -158,24 +164,6 @@
     <ClCompile Include="Source\BsScriptFont.cpp">
     <ClCompile Include="Source\BsScriptFont.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIArea.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIBase.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIElementStateStyle.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIElementStyle.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUILabel.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUILayout.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsScriptSpriteTexture.cpp">
     <ClCompile Include="Source\BsScriptSpriteTexture.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
@@ -188,36 +176,6 @@
     <ClCompile Include="Source\BsScriptStringTable.cpp">
     <ClCompile Include="Source\BsScriptStringTable.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIContent.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIFixedSpace.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIFlexibleSpace.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUITexture.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIButton.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIInputBox.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIScrollArea.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIListBox.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIToggleGroup.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="Source\BsScriptGUIToggle.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\BsRuntimeScriptObjects.cpp">
     <ClCompile Include="Source\BsRuntimeScriptObjects.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
@@ -254,5 +212,53 @@
     <ClCompile Include="Source\BsScriptSerializableDictionary.cpp">
     <ClCompile Include="Source\BsScriptSerializableDictionary.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIArea.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIBase.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIButton.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIContent.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIElementStateStyle.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIElementStyle.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIFixedSpace.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIFlexibleSpace.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIInputBox.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUILabel.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUILayout.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIListBox.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIScrollArea.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUITexture.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIToggle.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIToggleGroup.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 18 - 14
SBansheeEngine/Source/BsScriptGUIArea.cpp

@@ -13,7 +13,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUIArea::ScriptGUIArea(GUIArea* area, ScriptGUIBase* parentGUI)
 	ScriptGUIArea::ScriptGUIArea(GUIArea* area, ScriptGUIBase* parentGUI)
-		:mArea(area), mParentGUI(parentGUI)
+		:mArea(area), mParentGUI(parentGUI), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -33,13 +33,18 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_CreateInstanceResizableXY", &ScriptGUIArea::internal_createInstanceResizeableXY);
 		metaData.scriptClass->addInternalCall("Internal_CreateInstanceResizableXY", &ScriptGUIArea::internal_createInstanceResizeableXY);
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIArea::internal_destroyInstance);
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIArea::internal_destroyInstance);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIArea::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIArea::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIArea::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIArea::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIArea::internal_setVisible);
 	}
 	}
 
 
-	GUIWidget& ScriptGUIArea::getParentWidget() const 
-	{ 
-		return mParentGUI->getWidget(); 
+	void ScriptGUIArea::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIArea::destroy(mArea);
+			mArea = nullptr;
+
+			mIsDestroyed = true;
+		}
 	}
 	}
 
 
 	void ScriptGUIArea::internal_createInstance(MonoObject* instance, MonoObject* parentGUI, CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height, CM::UINT16 depth)
 	void ScriptGUIArea::internal_createInstance(MonoObject* instance, MonoObject* parentGUI, CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height, CM::UINT16 depth)
@@ -91,21 +96,20 @@ namespace BansheeEngine
 
 
 	void ScriptGUIArea::internal_destroyInstance(ScriptGUIArea* nativeInstance)
 	void ScriptGUIArea::internal_destroyInstance(ScriptGUIArea* nativeInstance)
 	{
 	{
+		nativeInstance->destroy();
 		cm_delete(nativeInstance);
 		cm_delete(nativeInstance);
 	}
 	}
 
 
 	void ScriptGUIArea::internal_destroy(ScriptGUIArea* nativeInstance)
 	void ScriptGUIArea::internal_destroy(ScriptGUIArea* nativeInstance)
 	{
 	{
-		GUIArea::destroy(nativeInstance->getInternalValue());
-	}
-
-	void ScriptGUIArea::internal_disable(ScriptGUIArea* nativeInstance)
-	{
-		nativeInstance->getInternalValue()->disable();
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUIArea::internal_enable(ScriptGUIArea* nativeInstance)
+	void ScriptGUIArea::internal_setVisible(ScriptGUIArea* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->enable();
+		if(visible)
+			nativeInstance->getInternalValue()->enable();
+		else
+			nativeInstance->getInternalValue()->disable();
 	}
 	}
 }
 }

+ 33 - 19
SBansheeEngine/Source/BsScriptGUIButton.cpp

@@ -24,7 +24,7 @@ namespace BansheeEngine
 	ScriptGUIButton::OnOutThunkDef ScriptGUIButton::onOutThunk;
 	ScriptGUIButton::OnOutThunkDef ScriptGUIButton::onOutThunk;
 
 
 	ScriptGUIButton::ScriptGUIButton(GUIButton* button)
 	ScriptGUIButton::ScriptGUIButton(GUIButton* button)
-		:mButton(button)
+		:mButton(button), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -43,17 +43,27 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIButton::internal_setContent);
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIButton::internal_setContent);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIButton::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIButton::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIButton::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIButton::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIButton::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIButton::internal_setParent);
 
 
 		onClickThunk = (OnClickThunkDef)metaData.scriptClass->getMethod("DoOnClick").getThunk();
 		onClickThunk = (OnClickThunkDef)metaData.scriptClass->getMethod("DoOnClick").getThunk();
 		onHoverThunk = (OnHoverThunkDef)metaData.scriptClass->getMethod("DoOnHover").getThunk();
 		onHoverThunk = (OnHoverThunkDef)metaData.scriptClass->getMethod("DoOnHover").getThunk();
 		onOutThunk = (OnOutThunkDef)metaData.scriptClass->getMethod("DoOnOut").getThunk();
 		onOutThunk = (OnOutThunkDef)metaData.scriptClass->getMethod("DoOnOut").getThunk();
 	}
 	}
 
 
-	void ScriptGUIButton::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* content, MonoObject* style, MonoArray* guiOptions)
+	void ScriptGUIButton::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mButton);
+			mButton = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUIButton::internal_createInstance(MonoObject* instance, MonoObject* content, MonoObject* style, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
@@ -66,26 +76,18 @@ namespace BansheeEngine
 			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
 			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
 
 
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		GUIButton* guiButton = GUIButton::create(scriptLayout->getParentWidget(), nativeContent, options, elemStyle);
+		GUIButton* guiButton = GUIButton::create(nativeContent, options, elemStyle);
 
 
 		guiButton->onClick.connect(std::bind(&ScriptGUIButton::onClick, instance));
 		guiButton->onClick.connect(std::bind(&ScriptGUIButton::onClick, instance));
 		guiButton->onHover.connect(std::bind(&ScriptGUIButton::onHover, instance));
 		guiButton->onHover.connect(std::bind(&ScriptGUIButton::onHover, instance));
 		guiButton->onOut.connect(std::bind(&ScriptGUIButton::onOut, instance));
 		guiButton->onOut.connect(std::bind(&ScriptGUIButton::onOut, instance));
 
 
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiButton);
-
 		ScriptGUIButton* nativeInstance = new (cm_alloc<ScriptGUIButton>()) ScriptGUIButton(guiButton);
 		ScriptGUIButton* nativeInstance = new (cm_alloc<ScriptGUIButton>()) ScriptGUIButton(guiButton);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIButton::internal_destroyInstance(ScriptGUIButton* nativeInstance)
-	{
-		cm_delete(nativeInstance);
-	}
-
 	void ScriptGUIButton::internal_setContent(ScriptGUIButton* nativeInstance, MonoObject* content)
 	void ScriptGUIButton::internal_setContent(ScriptGUIButton* nativeInstance, MonoObject* content)
 	{
 	{
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
@@ -94,17 +96,29 @@ namespace BansheeEngine
 
 
 	void ScriptGUIButton::internal_destroy(ScriptGUIButton* nativeInstance)
 	void ScriptGUIButton::internal_destroy(ScriptGUIButton* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
+	}
+
+	void ScriptGUIButton::internal_destroyInstance(ScriptGUIButton* nativeInstance)
+	{
+		nativeInstance->destroy();
+		cm_delete(nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIButton::internal_disable(ScriptGUIButton* nativeInstance)
+	void ScriptGUIButton::internal_setVisible(ScriptGUIButton* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
 	}
 	}
 
 
-	void ScriptGUIButton::internal_enable(ScriptGUIButton* nativeInstance)
+	void ScriptGUIButton::internal_setParent(ScriptGUIButton* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 
 
 	void ScriptGUIButton::onClick(MonoObject* instance)
 	void ScriptGUIButton::onClick(MonoObject* instance)

+ 23 - 8
SBansheeEngine/Source/BsScriptGUIFixedSpace.cpp

@@ -14,7 +14,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUIFixedSpace::ScriptGUIFixedSpace(GUIFixedSpace& fixedSpace, GUILayout* parentLayout)
 	ScriptGUIFixedSpace::ScriptGUIFixedSpace(GUIFixedSpace& fixedSpace, GUILayout* parentLayout)
-		:mFixedSpace(fixedSpace), mParentLayout(parentLayout)
+		:mFixedSpace(fixedSpace), mParentLayout(parentLayout), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -32,8 +32,19 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIFixedSpace::internal_destroyInstance);
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIFixedSpace::internal_destroyInstance);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIFixedSpace::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIFixedSpace::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIFixedSpace::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIFixedSpace::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIFixedSpace::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIFixedSpace::internal_setParent);
+	}
+
+	void ScriptGUIFixedSpace::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			mParentLayout->removeSpace(mFixedSpace);
+			mParentLayout = nullptr;
+
+			mIsDestroyed = true;
+		}
 	}
 	}
 
 
 	void ScriptGUIFixedSpace::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, UINT32 size)
 	void ScriptGUIFixedSpace::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, UINT32 size)
@@ -50,21 +61,25 @@ namespace BansheeEngine
 
 
 	void ScriptGUIFixedSpace::internal_destroyInstance(ScriptGUIFixedSpace* nativeInstance)
 	void ScriptGUIFixedSpace::internal_destroyInstance(ScriptGUIFixedSpace* nativeInstance)
 	{
 	{
+		nativeInstance->destroy();
 		cm_delete(nativeInstance);
 		cm_delete(nativeInstance);
 	}
 	}
 
 
 	void ScriptGUIFixedSpace::internal_destroy(ScriptGUIFixedSpace* nativeInstance)
 	void ScriptGUIFixedSpace::internal_destroy(ScriptGUIFixedSpace* nativeInstance)
 	{
 	{
-		nativeInstance->mParentLayout->removeSpace(nativeInstance->mFixedSpace);
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUIFixedSpace::internal_disable(ScriptGUIFixedSpace* nativeInstance)
+	void ScriptGUIFixedSpace::internal_setVisible(ScriptGUIFixedSpace* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->mFixedSpace.disableRecursively();
+		if(visible)
+			nativeInstance->mFixedSpace.enableRecursively();
+		else
+			nativeInstance->mFixedSpace.disableRecursively();
 	}
 	}
 
 
-	void ScriptGUIFixedSpace::internal_enable(ScriptGUIFixedSpace* nativeInstance)
+	void ScriptGUIFixedSpace::internal_setParent(ScriptGUIFixedSpace* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->mFixedSpace.enableRecursively();
+		// FixedSpace parent is static, so do nothing
 	}
 	}
 }
 }

+ 23 - 8
SBansheeEngine/Source/BsScriptGUIFlexibleSpace.cpp

@@ -14,7 +14,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUIFlexibleSpace::ScriptGUIFlexibleSpace(GUIFlexibleSpace& flexibleSpace, GUILayout* parentLayout)
 	ScriptGUIFlexibleSpace::ScriptGUIFlexibleSpace(GUIFlexibleSpace& flexibleSpace, GUILayout* parentLayout)
-		:mFlexibleSpace(flexibleSpace), mParentLayout(parentLayout)
+		:mFlexibleSpace(flexibleSpace), mParentLayout(parentLayout), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -32,8 +32,19 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIFlexibleSpace::internal_destroyInstance);
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIFlexibleSpace::internal_destroyInstance);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIFlexibleSpace::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIFlexibleSpace::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIFlexibleSpace::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIFlexibleSpace::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIFlexibleSpace::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIFlexibleSpace::internal_setParent);
+	}
+
+	void ScriptGUIFlexibleSpace::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			mParentLayout->removeFlexibleSpace(mFlexibleSpace);
+			mParentLayout = nullptr;
+
+			mIsDestroyed = true;
+		}
 	}
 	}
 
 
 	void ScriptGUIFlexibleSpace::internal_createInstance(MonoObject* instance, MonoObject* parentLayout)
 	void ScriptGUIFlexibleSpace::internal_createInstance(MonoObject* instance, MonoObject* parentLayout)
@@ -50,21 +61,25 @@ namespace BansheeEngine
 
 
 	void ScriptGUIFlexibleSpace::internal_destroyInstance(ScriptGUIFlexibleSpace* nativeInstance)
 	void ScriptGUIFlexibleSpace::internal_destroyInstance(ScriptGUIFlexibleSpace* nativeInstance)
 	{
 	{
+		nativeInstance->destroy();
 		cm_delete(nativeInstance);
 		cm_delete(nativeInstance);
 	}
 	}
 
 
 	void ScriptGUIFlexibleSpace::internal_destroy(ScriptGUIFlexibleSpace* nativeInstance)
 	void ScriptGUIFlexibleSpace::internal_destroy(ScriptGUIFlexibleSpace* nativeInstance)
 	{
 	{
-		nativeInstance->mParentLayout->removeFlexibleSpace(nativeInstance->mFlexibleSpace);
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUIFlexibleSpace::internal_disable(ScriptGUIFlexibleSpace* nativeInstance)
+	void ScriptGUIFlexibleSpace::internal_setVisible(ScriptGUIFlexibleSpace* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->mFlexibleSpace.disableRecursively();
+		if(visible)
+			nativeInstance->mFlexibleSpace.enableRecursively();
+		else
+			nativeInstance->mFlexibleSpace.disableRecursively();
 	}
 	}
 
 
-	void ScriptGUIFlexibleSpace::internal_enable(ScriptGUIFlexibleSpace* nativeInstance)
+	void ScriptGUIFlexibleSpace::internal_setParent(ScriptGUIFlexibleSpace* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->mFlexibleSpace.enableRecursively();
+		// FlexibleSpace parent is static, so do nothing
 	}
 	}
 }
 }

+ 33 - 18
SBansheeEngine/Source/BsScriptGUIInputBox.cpp

@@ -20,7 +20,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUIInputBox::ScriptGUIInputBox(GUIInputBox* inputBox)
 	ScriptGUIInputBox::ScriptGUIInputBox(GUIInputBox* inputBox)
-		:mInputBox(inputBox)
+		:mInputBox(inputBox), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -40,13 +40,23 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetText", &ScriptGUIInputBox::internal_setText);
 		metaData.scriptClass->addInternalCall("Internal_SetText", &ScriptGUIInputBox::internal_setText);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIInputBox::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIInputBox::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIInputBox::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIInputBox::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIInputBox::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIInputBox::internal_setParent);
 	}
 	}
 
 
-	void ScriptGUIInputBox::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, bool multiline, MonoObject* style, MonoArray* guiOptions)
+	void ScriptGUIInputBox::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mInputBox);
+			mInputBox = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUIInputBox::internal_createInstance(MonoObject* instance, bool multiline, MonoObject* style, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
@@ -58,9 +68,7 @@ namespace BansheeEngine
 		if(style != nullptr)
 		if(style != nullptr)
 			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
 			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
 
 
-		GUIInputBox* guiInputBox = GUIInputBox::create(scriptLayout->getParentWidget(), multiline, options, elemStyle);
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiInputBox);
+		GUIInputBox* guiInputBox = GUIInputBox::create(multiline, options, elemStyle);
 
 
 		ScriptGUIInputBox* nativeInstance = new (cm_alloc<ScriptGUIInputBox>()) ScriptGUIInputBox(guiInputBox);
 		ScriptGUIInputBox* nativeInstance = new (cm_alloc<ScriptGUIInputBox>()) ScriptGUIInputBox(guiInputBox);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
@@ -68,11 +76,6 @@ namespace BansheeEngine
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIInputBox::internal_destroyInstance(ScriptGUIInputBox* nativeInstance)
-	{
-		cm_delete(nativeInstance);
-	}
-
 	void ScriptGUIInputBox::internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text)
 	void ScriptGUIInputBox::internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text)
 	{
 	{
 		*text = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), nativeInstance->getInternalValue()->getText());
 		*text = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), nativeInstance->getInternalValue()->getText());
@@ -85,16 +88,28 @@ namespace BansheeEngine
 
 
 	void ScriptGUIInputBox::internal_destroy(ScriptGUIInputBox* nativeInstance)
 	void ScriptGUIInputBox::internal_destroy(ScriptGUIInputBox* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUIInputBox::internal_disable(ScriptGUIInputBox* nativeInstance)
+	void ScriptGUIInputBox::internal_destroyInstance(ScriptGUIInputBox* nativeInstance)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		nativeInstance->destroy();
+		cm_delete(nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIInputBox::internal_enable(ScriptGUIInputBox* nativeInstance)
+	void ScriptGUIInputBox::internal_setVisible(ScriptGUIInputBox* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
+	}
+
+	void ScriptGUIInputBox::internal_setParent(ScriptGUIInputBox* nativeInstance, MonoObject* parentLayout)
+	{
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 }
 }

+ 34 - 18
SBansheeEngine/Source/BsScriptGUILabel.cpp

@@ -19,7 +19,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUILabel::ScriptGUILabel(GUILabel* label)
 	ScriptGUILabel::ScriptGUILabel(GUILabel* label)
-		:mLabel(label)
+		:mLabel(label), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -30,6 +30,7 @@ namespace BansheeEngine
 
 
 		MonoManager::registerScriptType(&metaData);
 		MonoManager::registerScriptType(&metaData);
 	}
 	}
+
 	void ScriptGUILabel::initRuntimeData()
 	void ScriptGUILabel::initRuntimeData()
 	{
 	{
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUILabel::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUILabel::internal_createInstance);
@@ -37,13 +38,23 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUILabel::internal_setContent);
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUILabel::internal_setContent);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUILabel::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUILabel::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUILabel::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUILabel::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUILabel::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUILabel::internal_setParent);
 	}
 	}
 
 
-	void ScriptGUILabel::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* content, MonoObject* style, MonoArray* guiOptions)
+	void ScriptGUILabel::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mLabel);
+			mLabel = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUILabel::internal_createInstance(MonoObject* instance, MonoObject* content, MonoObject* style, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
@@ -56,9 +67,7 @@ namespace BansheeEngine
 			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
 			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
 
 
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		GUILabel* guiLabel = GUILabel::create(scriptLayout->getParentWidget(), nativeContent, options, elemStyle);
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiLabel);
+		GUILabel* guiLabel = GUILabel::create(nativeContent, options, elemStyle);
 
 
 		ScriptGUILabel* nativeInstance = new (cm_alloc<ScriptGUILabel>()) ScriptGUILabel(guiLabel);
 		ScriptGUILabel* nativeInstance = new (cm_alloc<ScriptGUILabel>()) ScriptGUILabel(guiLabel);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
@@ -66,11 +75,6 @@ namespace BansheeEngine
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 	}
 	}
 
 
-	void ScriptGUILabel::internal_destroyInstance(ScriptGUILabel* nativeInstance)
-	{
-		cm_delete(nativeInstance);
-	}
-
 	void ScriptGUILabel::internal_setContent(ScriptGUILabel* nativeInstance, MonoObject* content)
 	void ScriptGUILabel::internal_setContent(ScriptGUILabel* nativeInstance, MonoObject* content)
 	{
 	{
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
@@ -79,16 +83,28 @@ namespace BansheeEngine
 
 
 	void ScriptGUILabel::internal_destroy(ScriptGUILabel* nativeInstance)
 	void ScriptGUILabel::internal_destroy(ScriptGUILabel* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
+	}
+
+	void ScriptGUILabel::internal_destroyInstance(ScriptGUILabel* nativeInstance)
+	{
+		nativeInstance->destroy();
+		cm_delete(nativeInstance);
 	}
 	}
 
 
-	void ScriptGUILabel::internal_disable(ScriptGUILabel* nativeInstance)
+	void ScriptGUILabel::internal_setVisible(ScriptGUILabel* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
 	}
 	}
 
 
-	void ScriptGUILabel::internal_enable(ScriptGUILabel* nativeInstance)
+	void ScriptGUILabel::internal_setParent(ScriptGUILabel* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 }
 }

+ 31 - 14
SBansheeEngine/Source/BsScriptGUILayout.cpp

@@ -13,8 +13,8 @@ using namespace CamelotFramework;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	ScriptGUILayout::ScriptGUILayout(GUILayout* layout, GUIWidget& parentWidget, GUILayout* parentLayout)
-		:mLayout(layout), mParentWidget(parentWidget), mParentLayout(parentLayout)
+	ScriptGUILayout::ScriptGUILayout(GUILayout* layout, GUILayout* parentLayout)
+		:mLayout(layout), mParentLayout(parentLayout), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -35,8 +35,22 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUILayout::internal_destroyInstance);
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUILayout::internal_destroyInstance);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUILayout::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUILayout::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUILayout::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUILayout::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUILayout::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUILayout::internal_setParent);
+	}
+
+	void ScriptGUILayout::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			if(mParentLayout != nullptr)
+				mParentLayout->removeLayout(*mLayout);
+
+			mLayout = nullptr;
+			mParentLayout = nullptr;
+
+			mIsDestroyed = true;
+		}
 	}
 	}
 
 
 	void ScriptGUILayout::internal_createInstanceXFromArea(MonoObject* instance, MonoObject* parentArea)
 	void ScriptGUILayout::internal_createInstanceXFromArea(MonoObject* instance, MonoObject* parentArea)
@@ -45,7 +59,7 @@ namespace BansheeEngine
 		GUIArea* nativeArea = scriptArea->getInternalValue();
 		GUIArea* nativeArea = scriptArea->getInternalValue();
 
 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
-			ScriptGUILayout(&nativeArea->getLayout(), scriptArea->getParentWidget(), nullptr);
+			ScriptGUILayout(&nativeArea->getLayout(), nullptr);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
@@ -58,7 +72,7 @@ namespace BansheeEngine
 		GUILayout& layout = nativeLayout->addLayoutX();
 		GUILayout& layout = nativeLayout->addLayoutX();
 
 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
-			ScriptGUILayout(&layout, scriptLayout->getParentWidget(), nativeLayout);
+			ScriptGUILayout(&layout, nativeLayout);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
@@ -71,7 +85,7 @@ namespace BansheeEngine
 		GUILayout& layout = nativeLayout->addLayoutY();
 		GUILayout& layout = nativeLayout->addLayoutY();
 
 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
-			ScriptGUILayout(&layout, scriptLayout->getParentWidget(), nativeLayout);
+			ScriptGUILayout(&layout, nativeLayout);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
@@ -83,7 +97,7 @@ namespace BansheeEngine
 		GUILayout* nativeLayout = &scriptScrollArea->getInternalValue()->getLayout();
 		GUILayout* nativeLayout = &scriptScrollArea->getInternalValue()->getLayout();
 
 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
-			ScriptGUILayout(nativeLayout, scriptScrollArea->getParentWidget(), nativeLayout);
+			ScriptGUILayout(nativeLayout, nativeLayout);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
@@ -91,22 +105,25 @@ namespace BansheeEngine
 
 
 	void ScriptGUILayout::internal_destroyInstance(ScriptGUILayout* nativeInstance)
 	void ScriptGUILayout::internal_destroyInstance(ScriptGUILayout* nativeInstance)
 	{
 	{
+		nativeInstance->destroy();
 		cm_delete(nativeInstance);
 		cm_delete(nativeInstance);
 	}
 	}
 
 
 	void ScriptGUILayout::internal_destroy(ScriptGUILayout* nativeInstance)
 	void ScriptGUILayout::internal_destroy(ScriptGUILayout* nativeInstance)
 	{
 	{
-		if(nativeInstance->mParentLayout != nullptr)
-			nativeInstance->mParentLayout->removeLayout(*nativeInstance->mLayout);
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUILayout::internal_disable(ScriptGUILayout* nativeInstance)
+	void ScriptGUILayout::internal_setVisible(ScriptGUILayout* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
 	}
 	}
 
 
-	void ScriptGUILayout::internal_enable(ScriptGUILayout* nativeInstance)
+	void ScriptGUILayout::internal_setParent(ScriptGUILayout* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		// Layout parent is static, so do nothing
 	}
 	}
 }
 }

+ 33 - 19
SBansheeEngine/Source/BsScriptGUIListBox.cpp

@@ -22,7 +22,7 @@ namespace BansheeEngine
 	ScriptGUIListBox::OnSelectionChangedThunkDef ScriptGUIListBox::onSelectionChangedThunk;
 	ScriptGUIListBox::OnSelectionChangedThunkDef ScriptGUIListBox::onSelectionChangedThunk;
 
 
 	ScriptGUIListBox::ScriptGUIListBox(GUIListBox* listBox)
 	ScriptGUIListBox::ScriptGUIListBox(GUIListBox* listBox)
-		:mListBox(listBox)
+		:mListBox(listBox), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -41,15 +41,25 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetElements", &ScriptGUIListBox::internal_setElements);
 		metaData.scriptClass->addInternalCall("Internal_SetElements", &ScriptGUIListBox::internal_setElements);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIListBox::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIListBox::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIListBox::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIListBox::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIListBox::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIListBox::internal_setParent);
 
 
 		onSelectionChangedThunk = (OnSelectionChangedThunkDef)metaData.scriptClass->getMethod("DoOnSelectionChanged", 1).getThunk();
 		onSelectionChangedThunk = (OnSelectionChangedThunkDef)metaData.scriptClass->getMethod("DoOnSelectionChanged", 1).getThunk();
 	}
 	}
 
 
-	void ScriptGUIListBox::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoArray* elements, MonoObject* style, MonoArray* guiOptions)
+	void ScriptGUIListBox::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mListBox);
+			mListBox = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUIListBox::internal_createInstance(MonoObject* instance, MonoArray* elements, MonoObject* style, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 optionsArrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 optionsArrayLen = (UINT32)mono_array_length(guiOptions);
@@ -76,23 +86,15 @@ namespace BansheeEngine
 			}
 			}
 		}
 		}
 
 
-		GUIListBox* guiListBox = GUIListBox::create(scriptLayout->getParentWidget(), nativeElements, options, elemStyle);
+		GUIListBox* guiListBox = GUIListBox::create(nativeElements, options, elemStyle);
 		guiListBox->onSelectionChanged.connect(std::bind(&ScriptGUIListBox::onSelectionChanged, instance, std::placeholders::_1));
 		guiListBox->onSelectionChanged.connect(std::bind(&ScriptGUIListBox::onSelectionChanged, instance, std::placeholders::_1));
 
 
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiListBox);
-
 		ScriptGUIListBox* nativeInstance = new (cm_alloc<ScriptGUIListBox>()) ScriptGUIListBox(guiListBox);
 		ScriptGUIListBox* nativeInstance = new (cm_alloc<ScriptGUIListBox>()) ScriptGUIListBox(guiListBox);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIListBox::internal_destroyInstance(ScriptGUIListBox* nativeInstance)
-	{
-		cm_delete(nativeInstance);
-	}
-
 	void ScriptGUIListBox::internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements)
 	void ScriptGUIListBox::internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements)
 	{
 	{
 		UINT32 elementsArrayLen = (UINT32)mono_array_length(elements);
 		UINT32 elementsArrayLen = (UINT32)mono_array_length(elements);
@@ -115,17 +117,29 @@ namespace BansheeEngine
 
 
 	void ScriptGUIListBox::internal_destroy(ScriptGUIListBox* nativeInstance)
 	void ScriptGUIListBox::internal_destroy(ScriptGUIListBox* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUIListBox::internal_disable(ScriptGUIListBox* nativeInstance)
+	void ScriptGUIListBox::internal_destroyInstance(ScriptGUIListBox* nativeInstance)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		nativeInstance->destroy();
+		cm_delete(nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIListBox::internal_enable(ScriptGUIListBox* nativeInstance)
+	void ScriptGUIListBox::internal_setVisible(ScriptGUIListBox* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
+	}
+
+	void ScriptGUIListBox::internal_setParent(ScriptGUIListBox* nativeInstance, MonoObject* parentLayout)
+	{
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 
 
 	void ScriptGUIListBox::onSelectionChanged(MonoObject* instance, CM::UINT32 index)
 	void ScriptGUIListBox::onSelectionChanged(MonoObject* instance, CM::UINT32 index)

+ 27 - 17
SBansheeEngine/Source/BsScriptGUIScrollArea.cpp

@@ -19,8 +19,8 @@ using namespace CamelotFramework;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	ScriptGUIScrollArea::ScriptGUIScrollArea(GUIScrollArea* scrollArea, GUIWidget& parentWidget)
-		:mScrollArea(scrollArea), mParentWidget(parentWidget)
+	ScriptGUIScrollArea::ScriptGUIScrollArea(GUIScrollArea* scrollArea)
+		:mScrollArea(scrollArea), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -38,19 +38,24 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIScrollArea::internal_destroyInstance);
 		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIScrollArea::internal_destroyInstance);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIScrollArea::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIScrollArea::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIScrollArea::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIScrollArea::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIScrollArea::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIScrollArea::internal_setParent);
 	}
 	}
 
 
-	GUIWidget& ScriptGUIScrollArea::getParentWidget() const
+	void ScriptGUIScrollArea::destroy()
 	{
 	{
-		return mParentWidget;
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mScrollArea);
+			mScrollArea = nullptr;
+
+			mIsDestroyed = true;
+		}
 	}
 	}
 
 
-	void ScriptGUIScrollArea::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, ScrollBarType vertBarType, ScrollBarType horzBarType, 
+	void ScriptGUIScrollArea::internal_createInstance(MonoObject* instance, ScrollBarType vertBarType, ScrollBarType horzBarType, 
 		MonoObject* scrollBarStyle, MonoObject* scrollAreaStyle, MonoArray* guiOptions)
 		MonoObject* scrollBarStyle, MonoObject* scrollAreaStyle, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
@@ -67,11 +72,9 @@ namespace BansheeEngine
 		if(scrollBarNativeStyle != nullptr)
 		if(scrollBarNativeStyle != nullptr)
 			scrollBarNativeStyle = ScriptGUIElementStyle::toNative(scrollBarStyle)->getInternalValue();
 			scrollBarNativeStyle = ScriptGUIElementStyle::toNative(scrollBarStyle)->getInternalValue();
 
 
-		GUIScrollArea* guiScrollArea = GUIScrollArea::create(scriptLayout->getParentWidget(), vertBarType, horzBarType, options, scrollBarNativeStyle, scrollAreaNativeStyle);
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiScrollArea);
+		GUIScrollArea* guiScrollArea = GUIScrollArea::create(vertBarType, horzBarType, options, scrollBarNativeStyle, scrollAreaNativeStyle);
 
 
-		ScriptGUIScrollArea* nativeInstance = new (cm_alloc<ScriptGUIScrollArea>()) ScriptGUIScrollArea(guiScrollArea, scriptLayout->getParentWidget());
+		ScriptGUIScrollArea* nativeInstance = new (cm_alloc<ScriptGUIScrollArea>()) ScriptGUIScrollArea(guiScrollArea);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
@@ -79,21 +82,28 @@ namespace BansheeEngine
 
 
 	void ScriptGUIScrollArea::internal_destroyInstance(ScriptGUIScrollArea* nativeInstance)
 	void ScriptGUIScrollArea::internal_destroyInstance(ScriptGUIScrollArea* nativeInstance)
 	{
 	{
+		nativeInstance->destroy();
 		cm_delete(nativeInstance);
 		cm_delete(nativeInstance);
 	}
 	}
 
 
 	void ScriptGUIScrollArea::internal_destroy(ScriptGUIScrollArea* nativeInstance)
 	void ScriptGUIScrollArea::internal_destroy(ScriptGUIScrollArea* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUIScrollArea::internal_disable(ScriptGUIScrollArea* nativeInstance)
+	void ScriptGUIScrollArea::internal_setVisible(ScriptGUIScrollArea* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
 	}
 	}
 
 
-	void ScriptGUIScrollArea::internal_enable(ScriptGUIScrollArea* nativeInstance)
+	void ScriptGUIScrollArea::internal_setParent(ScriptGUIScrollArea* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 }
 }

+ 33 - 18
SBansheeEngine/Source/BsScriptGUITexture.cpp

@@ -20,7 +20,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	ScriptGUITexture::ScriptGUITexture(GUITexture* texture)
 	ScriptGUITexture::ScriptGUITexture(GUITexture* texture)
-		:mTexture(texture)
+		:mTexture(texture), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -39,14 +39,24 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_SetTexture", &ScriptGUITexture::internal_setTexture);
 		metaData.scriptClass->addInternalCall("Internal_SetTexture", &ScriptGUITexture::internal_setTexture);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUITexture::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUITexture::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUITexture::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUITexture::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUITexture::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUITexture::internal_setParent);
 	}
 	}
 
 
-	void ScriptGUITexture::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* texture, 
+	void ScriptGUITexture::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mTexture);
+			mTexture = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUITexture::internal_createInstance(MonoObject* instance, MonoObject* texture, 
 		GUIImageScaleMode scale, MonoObject* style, MonoArray* guiOptions)
 		GUIImageScaleMode scale, MonoObject* style, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
@@ -62,9 +72,7 @@ namespace BansheeEngine
 		if(texture != nullptr)
 		if(texture != nullptr)
 			nativeTexture = ScriptSpriteTexture::toNative(texture)->getInternalValue();
 			nativeTexture = ScriptSpriteTexture::toNative(texture)->getInternalValue();
 
 
-		GUITexture* guiTexture = GUITexture::create(scriptLayout->getParentWidget(), nativeTexture, scale, options, elemStyle);
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiTexture);
+		GUITexture* guiTexture = GUITexture::create(nativeTexture, scale, options, elemStyle);
 
 
 		ScriptGUITexture* nativeInstance = new (cm_alloc<ScriptGUITexture>()) ScriptGUITexture(guiTexture);
 		ScriptGUITexture* nativeInstance = new (cm_alloc<ScriptGUITexture>()) ScriptGUITexture(guiTexture);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
@@ -72,11 +80,6 @@ namespace BansheeEngine
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 	}
 	}
 
 
-	void ScriptGUITexture::internal_destroyInstance(ScriptGUITexture* nativeInstance)
-	{
-		cm_delete(nativeInstance);
-	}
-
 	void ScriptGUITexture::internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture)
 	void ScriptGUITexture::internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture)
 	{
 	{
 		HSpriteTexture nativeTexture;
 		HSpriteTexture nativeTexture;
@@ -88,16 +91,28 @@ namespace BansheeEngine
 
 
 	void ScriptGUITexture::internal_destroy(ScriptGUITexture* nativeInstance)
 	void ScriptGUITexture::internal_destroy(ScriptGUITexture* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
 	}
 	}
 
 
-	void ScriptGUITexture::internal_disable(ScriptGUITexture* nativeInstance)
+	void ScriptGUITexture::internal_destroyInstance(ScriptGUITexture* nativeInstance)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		nativeInstance->destroy();
+		cm_delete(nativeInstance);
 	}
 	}
 
 
-	void ScriptGUITexture::internal_enable(ScriptGUITexture* nativeInstance)
+	void ScriptGUITexture::internal_setVisible(ScriptGUITexture* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
+	}
+
+	void ScriptGUITexture::internal_setParent(ScriptGUITexture* nativeInstance, MonoObject* parentLayout)
+	{
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 }
 }

+ 33 - 19
SBansheeEngine/Source/BsScriptGUIToggle.cpp

@@ -28,7 +28,7 @@ namespace BansheeEngine
 	ScriptGUIToggle::OnToggledThunkDef ScriptGUIToggle::onToggledThunk;
 	ScriptGUIToggle::OnToggledThunkDef ScriptGUIToggle::onToggledThunk;
 
 
 	ScriptGUIToggle::ScriptGUIToggle(GUIToggle* toggle)
 	ScriptGUIToggle::ScriptGUIToggle(GUIToggle* toggle)
-		:mToggle(toggle)
+		:mToggle(toggle), mIsDestroyed(false)
 	{
 	{
 
 
 	}
 	}
@@ -49,8 +49,8 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_ToggleOff", &ScriptGUIToggle::internal_toggleOff);
 		metaData.scriptClass->addInternalCall("Internal_ToggleOff", &ScriptGUIToggle::internal_toggleOff);
 
 
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIToggle::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIToggle::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_Enable", &ScriptGUIToggle::internal_enable);
-		metaData.scriptClass->addInternalCall("Internal_Disable", &ScriptGUIToggle::internal_disable);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIToggle::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIToggle::internal_setParent);
 
 
 		onClickThunk = (OnClickThunkDef)metaData.scriptClass->getMethod("DoOnClick").getThunk();
 		onClickThunk = (OnClickThunkDef)metaData.scriptClass->getMethod("DoOnClick").getThunk();
 		onHoverThunk = (OnHoverThunkDef)metaData.scriptClass->getMethod("DoOnHover").getThunk();
 		onHoverThunk = (OnHoverThunkDef)metaData.scriptClass->getMethod("DoOnHover").getThunk();
@@ -58,10 +58,20 @@ namespace BansheeEngine
 		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
 		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
 	}
 	}
 
 
-	void ScriptGUIToggle::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoObject* content, 
+	void ScriptGUIToggle::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mToggle);
+			mToggle = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUIToggle::internal_createInstance(MonoObject* instance, MonoObject* content, 
 		MonoObject* toggleGroup, MonoObject* style, MonoArray* guiOptions)
 		MonoObject* toggleGroup, MonoObject* style, MonoArray* guiOptions)
 	{
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 		GUIOptions options;
 		GUIOptions options;
 
 
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
 		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
@@ -77,27 +87,19 @@ namespace BansheeEngine
 			scriptToggleGroup = ScriptGUIToggleGroup::toNative(toggleGroup);
 			scriptToggleGroup = ScriptGUIToggleGroup::toNative(toggleGroup);
 
 
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		GUIToggle* guiToggle = GUIToggle::create(scriptLayout->getParentWidget(), nativeContent, scriptToggleGroup->getInternalValue(), options, elemStyle);
+		GUIToggle* guiToggle = GUIToggle::create(nativeContent, scriptToggleGroup->getInternalValue(), options, elemStyle);
 
 
 		guiToggle->onClick.connect(std::bind(&ScriptGUIToggle::onClick, instance));
 		guiToggle->onClick.connect(std::bind(&ScriptGUIToggle::onClick, instance));
 		guiToggle->onHover.connect(std::bind(&ScriptGUIToggle::onHover, instance));
 		guiToggle->onHover.connect(std::bind(&ScriptGUIToggle::onHover, instance));
 		guiToggle->onOut.connect(std::bind(&ScriptGUIToggle::onOut, instance));
 		guiToggle->onOut.connect(std::bind(&ScriptGUIToggle::onOut, instance));
 		guiToggle->onToggled.connect(std::bind(&ScriptGUIToggle::onToggled, instance, std::placeholders::_1));
 		guiToggle->onToggled.connect(std::bind(&ScriptGUIToggle::onToggled, instance, std::placeholders::_1));
 
 
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(guiToggle);
-
 		ScriptGUIToggle* nativeInstance = new (cm_alloc<ScriptGUIToggle>()) ScriptGUIToggle(guiToggle);
 		ScriptGUIToggle* nativeInstance = new (cm_alloc<ScriptGUIToggle>()) ScriptGUIToggle(guiToggle);
 		nativeInstance->createInstance(instance);
 		nativeInstance->createInstance(instance);
 
 
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 		metaData.thisPtrField->setValue(instance, &nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIToggle::internal_destroyInstance(ScriptGUIToggle* nativeInstance)
-	{
-		cm_delete(nativeInstance);
-	}
-
 	void ScriptGUIToggle::internal_setContent(ScriptGUIToggle* nativeInstance, MonoObject* content)
 	void ScriptGUIToggle::internal_setContent(ScriptGUIToggle* nativeInstance, MonoObject* content)
 	{
 	{
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
@@ -116,17 +118,29 @@ namespace BansheeEngine
 
 
 	void ScriptGUIToggle::internal_destroy(ScriptGUIToggle* nativeInstance)
 	void ScriptGUIToggle::internal_destroy(ScriptGUIToggle* nativeInstance)
 	{
 	{
-		GUIElement::destroy(nativeInstance->getInternalValue());
+		nativeInstance->destroy();
+	}
+
+	void ScriptGUIToggle::internal_destroyInstance(ScriptGUIToggle* nativeInstance)
+	{
+		nativeInstance->destroy();
+		cm_delete(nativeInstance);
 	}
 	}
 
 
-	void ScriptGUIToggle::internal_disable(ScriptGUIToggle* nativeInstance)
+	void ScriptGUIToggle::internal_setVisible(ScriptGUIToggle* nativeInstance, bool visible)
 	{
 	{
-		nativeInstance->getInternalValue()->disableRecursively();
+		if(visible)
+			nativeInstance->getInternalValue()->enableRecursively();
+		else
+			nativeInstance->getInternalValue()->disableRecursively();
 	}
 	}
 
 
-	void ScriptGUIToggle::internal_enable(ScriptGUIToggle* nativeInstance)
+	void ScriptGUIToggle::internal_setParent(ScriptGUIToggle* nativeInstance, MonoObject* parentLayout)
 	{
 	{
-		nativeInstance->getInternalValue()->enableRecursively();
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getInternalValue());
 	}
 	}
 
 
 	void ScriptGUIToggle::onClick(MonoObject* instance)
 	void ScriptGUIToggle::onClick(MonoObject* instance)