Просмотр исходного кода

Script GUI elements now share a common base class

Marko Pintera 11 лет назад
Родитель
Сommit
785f60e078

+ 2 - 2
Inspector.txt

@@ -1,6 +1,6 @@
 
-Port all remaining Script* classes to new ScriptObject system
-GUIElement script objects need to be fixed to have a common base class. Currently I'm trying to implement an internal method in specific Script  types, but that method only exists on GUIElement.
+Test new ScriptObject* system
+
 When I change an object in InspectableObject field I probably need to rebuild entire GUI hierarchy for that object. Right now I'm not.
 
 -----------------------------------------------

+ 2 - 14
SBansheeEditor/Include/BsScriptGUIFoldout.h

@@ -1,35 +1,23 @@
 #pragma once
 
 #include "BsScriptEditorPrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BED_EXPORT ScriptGUIFoldout : public ScriptObject<ScriptGUIFoldout>
+	class BS_SCR_BED_EXPORT ScriptGUIFoldout : public TScriptGUIElement<ScriptGUIFoldout>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "GUIFoldout")
 
-		GUIFoldout* getInternalValue() const { return mFoldout; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions);
 		static void internal_setContent(ScriptGUIFoldout* nativeInstance, MonoObject* content);
 
-		static void internal_destroy(ScriptGUIFoldout* nativeInstance);
-		static void internal_setVisible(ScriptGUIFoldout* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUIFoldout* nativeInstance, MonoObject* parentLayout);
-
 		static void onToggled(MonoObject* instance, bool expanded);
 
 		ScriptGUIFoldout(MonoObject* instance, GUIFoldout* foldout);
 
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUIFoldout* mFoldout;
-		bool mIsDestroyed;
-
 		typedef void (__stdcall *OnToggledThunkDef) (MonoObject*, bool, MonoException**);
 
 		static OnToggledThunkDef onToggledThunk;

+ 1 - 44
SBansheeEditor/Source/BsScriptGUIFoldout.cpp

@@ -23,7 +23,7 @@ namespace BansheeEngine
 	ScriptGUIFoldout::OnToggledThunkDef ScriptGUIFoldout::onToggledThunk;
 
 	ScriptGUIFoldout::ScriptGUIFoldout(MonoObject* instance, GUIFoldout* foldout)
-		:ScriptObject(instance), mFoldout(foldout), mIsDestroyed(false)
+		:TScriptGUIElement(instance, foldout)
 	{
 
 	}
@@ -33,31 +33,9 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIFoldout::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIFoldout::internal_setContent);
 
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIFoldout::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIFoldout::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIFoldout::internal_setParent);
-
 		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
 	}
 
-	void ScriptGUIFoldout::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mFoldout);
-			mFoldout = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUIFoldout::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
-	}
-
 	void ScriptGUIFoldout::internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions)
 	{
 		GUIOptions options;
@@ -81,27 +59,6 @@ namespace BansheeEngine
 		// TODO - Update GUIFoldout once it has a label
 	}
 
-	void ScriptGUIFoldout::internal_destroy(ScriptGUIFoldout* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUIFoldout::internal_setVisible(ScriptGUIFoldout* nativeInstance, bool visible)
-	{
-		if(visible)
-			nativeInstance->getInternalValue()->enableRecursively();
-		else
-			nativeInstance->getInternalValue()->disableRecursively();
-	}
-
-	void ScriptGUIFoldout::internal_setParent(ScriptGUIFoldout* nativeInstance, MonoObject* parentLayout)
-	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
-
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(nativeInstance->getInternalValue());
-	}
-
 	void ScriptGUIFoldout::onToggled(MonoObject* instance, bool expanded)
 	{
 		MonoException* exception = nullptr;

+ 2 - 15
SBansheeEngine/Include/BsScriptGUIButton.h

@@ -1,38 +1,25 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUIButton : public ScriptObject<ScriptGUIButton>
+	class BS_SCR_BE_EXPORT ScriptGUIButton : public TScriptGUIElement<ScriptGUIButton>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIButton")
 
-		GUIButton* getInternalValue() const { return mButton; }
-		void* getNativeRaw() const { return mButton; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions);
 		static void internal_setContent(ScriptGUIButton* nativeInstance, MonoObject* content);
 
-		static void internal_destroy(ScriptGUIButton* nativeInstance);
-		static void internal_setVisible(ScriptGUIButton* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUIButton* nativeInstance, MonoObject* parentLayout);
-
 		static void onClick(MonoObject* instance);
 		static void onHover(MonoObject* instance);
 		static void onOut(MonoObject* instance);
 
 		ScriptGUIButton(MonoObject* instance, GUIButton* button);
 
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUIButton* mButton;
-		bool mIsDestroyed;
-
 		typedef void (__stdcall *OnClickThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnHoverThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnOutThunkDef) (MonoObject*, MonoException**);

+ 56 - 0
SBansheeEngine/Include/BsScriptGUIElement.h

@@ -0,0 +1,56 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptGUIElementBase
+	{
+	public:
+		ScriptGUIElementBase(GUIElement* element);
+		virtual ~ScriptGUIElementBase() {}
+
+		GUIElement* getGUIElement() const { return mElement; }
+
+		virtual void destroy();
+
+	private:
+		bool mIsDestroyed;
+		GUIElement* mElement;
+	};
+
+	template <class Type>
+	class TScriptGUIElement : public ScriptGUIElementBase, public ScriptObject<Type>
+	{
+	public:
+		virtual ~TScriptGUIElement() {}
+
+	protected:
+		TScriptGUIElement(MonoObject* instance, GUIElement* element)
+			:ScriptGUIElementBase(element), ScriptObject(instance)
+		{ }
+
+		void _onManagedInstanceDeleted()
+		{
+			destroy();
+
+			ScriptObject::_onManagedInstanceDeleted();
+		}
+	};
+
+	class BS_SCR_BE_EXPORT ScriptGUIElement : public ScriptObject<ScriptGUIElement>
+	{
+	public:
+		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIElement")
+
+	private:
+		static void internal_destroy(ScriptGUIElementBase* nativeInstance);
+		static void internal_setVisible(ScriptGUIElementBase* nativeInstance, bool visible);
+		static void internal_setParent(ScriptGUIElementBase* nativeInstance, MonoObject* parentLayout);
+
+		ScriptGUIElement(MonoObject* instance);
+	};
+
+
+}

+ 2 - 15
SBansheeEngine/Include/BsScriptGUIInputBox.h

@@ -1,35 +1,22 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 #include "BsGUITexture.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUIInputBox : public ScriptObject<ScriptGUIInputBox>
+	class BS_SCR_BE_EXPORT ScriptGUIInputBox : public TScriptGUIElement<ScriptGUIInputBox>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIInputBox")
 
-		GUIInputBox* getInternalValue() const { return mInputBox; }
-		void* getNativeRaw() const { return mInputBox; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, bool multiline, MonoString* style, MonoArray* guiOptions);
 
 		static void internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text);
 		static void internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text);
 
-		static void internal_destroy(ScriptGUIInputBox* nativeInstance);
-		static void internal_setVisible(ScriptGUIInputBox* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUIInputBox* nativeInstance, MonoObject* parentLayout);
-
 		ScriptGUIInputBox(MonoObject* instance, GUIInputBox* inputBox);
-
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUIInputBox* mInputBox;
-		bool mIsDestroyed;
 	};
 }

+ 2 - 15
SBansheeEngine/Include/BsScriptGUILabel.h

@@ -1,32 +1,19 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUILabel : public ScriptObject<ScriptGUILabel>
+	class BS_SCR_BE_EXPORT ScriptGUILabel : public TScriptGUIElement<ScriptGUILabel>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUILabel")
 
-		GUILabel* getInternalValue() const { return mLabel; }
-		void* getNativeRaw() const { return mLabel; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions);
 		static void internal_setContent(ScriptGUILabel* nativeInstance, MonoObject* content);
 
-		static void internal_destroy(ScriptGUILabel* nativeInstance);
-		static void internal_setVisible(ScriptGUILabel* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUILabel* nativeInstance, MonoObject* parentLayout);
-
 		ScriptGUILabel(MonoObject* instance, GUILabel* label);
-
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUILabel* mLabel;
-		bool mIsDestroyed;
 	};
 }

+ 2 - 15
SBansheeEngine/Include/BsScriptGUIListBox.h

@@ -1,37 +1,24 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 #include "BsGUITexture.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUIListBox : public ScriptObject<ScriptGUIListBox>
+	class BS_SCR_BE_EXPORT ScriptGUIListBox : public TScriptGUIElement<ScriptGUIListBox>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIListBox")
 
-		GUIListBox* getInternalValue() const { return mListBox; }
-		void* getNativeRaw() const { return mListBox; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoArray* elements, MonoString* style, MonoArray* guiOptions);
 		static void internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements);
 
-		static void internal_destroy(ScriptGUIListBox* nativeInstance);
-		static void internal_setVisible(ScriptGUIListBox* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUIListBox* nativeInstance, MonoObject* parentLayout);
-
 		static void onSelectionChanged(MonoObject* instance, UINT32 index);
 
 		ScriptGUIListBox(MonoObject* instance, GUIListBox* listBox);
 
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUIListBox* mListBox;
-		bool mIsDestroyed;
-
 		typedef void (__stdcall *OnSelectionChangedThunkDef) (MonoObject*, UINT32, MonoException**);
 		static OnSelectionChangedThunkDef onSelectionChangedThunk;
 	};

+ 2 - 15
SBansheeEngine/Include/BsScriptGUIScrollArea.h

@@ -1,33 +1,20 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 #include "BsGUIScrollArea.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUIScrollArea : public ScriptObject<ScriptGUIScrollArea>
+	class BS_SCR_BE_EXPORT ScriptGUIScrollArea : public TScriptGUIElement<ScriptGUIScrollArea>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIScrollArea")
 
-		GUIScrollArea* getInternalValue() const { return mScrollArea; }
-		void* getNativeRaw() const { return mScrollArea; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, ScrollBarType vertBarType, ScrollBarType horzBarType, 
 			MonoString* scrollBarStyle, MonoString* scrollAreaStyle, MonoArray* guiOptions);
 
-		static void internal_destroy(ScriptGUIScrollArea* nativeInstance);
-		static void internal_setVisible(ScriptGUIScrollArea* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUIScrollArea* nativeInstance, MonoObject* parentLayout);
-
 		ScriptGUIScrollArea(MonoObject* instance, GUIScrollArea* scrollArea);
-
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUIScrollArea* mScrollArea;
-		bool mIsDestroyed;
 	};
 }

+ 2 - 15
SBansheeEngine/Include/BsScriptGUITexture.h

@@ -1,34 +1,21 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 #include "BsGUITexture.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUITexture : public ScriptObject<ScriptGUITexture>
+	class BS_SCR_BE_EXPORT ScriptGUITexture : public TScriptGUIElement<ScriptGUITexture>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUITexture")
 
-		GUITexture* getInternalValue() const { return mTexture; }
-		void* getNativeRaw() const { return mTexture; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* texture, 
 			GUIImageScaleMode scale, MonoString* style, MonoArray* guiOptions);
 		static void internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture);
 
-		static void internal_destroy(ScriptGUITexture* nativeInstance);
-		static void internal_setVisible(ScriptGUITexture* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUITexture* nativeInstance, MonoObject* parentLayout);
-
 		ScriptGUITexture(MonoObject* instance, GUITexture* texture);
-
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUITexture* mTexture;
-		bool mIsDestroyed;
 	};
 }

+ 2 - 15
SBansheeEngine/Include/BsScriptGUIToggle.h

@@ -1,18 +1,15 @@
 #pragma once
 
 #include "BsScriptEnginePrerequisites.h"
-#include "BsScriptObject.h"
+#include "BsScriptGUIElement.h"
 
 namespace BansheeEngine
 {
-	class BS_SCR_BE_EXPORT ScriptGUIToggle : public ScriptObject<ScriptGUIToggle>
+	class BS_SCR_BE_EXPORT ScriptGUIToggle : public TScriptGUIElement<ScriptGUIToggle>
 	{
 	public:
 		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIToggle")
 
-		GUIToggle* getInternalValue() const { return mToggle; }
-		void* getNativeRaw() const { return mToggle; }
-
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* content, 
 			MonoObject* toggleGroup, MonoString* style, MonoArray* guiOptions);
@@ -20,10 +17,6 @@ namespace BansheeEngine
 		static void internal_toggleOn(ScriptGUIToggle* nativeInstance);
 		static void internal_toggleOff(ScriptGUIToggle* nativeInstance);
 
-		static void internal_destroy(ScriptGUIToggle* nativeInstance);
-		static void internal_setVisible(ScriptGUIToggle* nativeInstance, bool visible);
-		static void internal_setParent(ScriptGUIToggle* nativeInstance, MonoObject* parentLayout);
-
 		static void onClick(MonoObject* instance);
 		static void onHover(MonoObject* instance);
 		static void onOut(MonoObject* instance);
@@ -31,12 +24,6 @@ namespace BansheeEngine
 
 		ScriptGUIToggle(MonoObject* instance, GUIToggle* toggle);
 
-		void destroy();
-		void _onManagedInstanceDeleted();
-
-		GUIToggle* mToggle;
-		bool mIsDestroyed;
-
 		typedef void (__stdcall *OnClickThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnHoverThunkDef) (MonoObject*, MonoException**);
 		typedef void (__stdcall *OnOutThunkDef) (MonoObject*, MonoException**);

+ 2 - 0
SBansheeEngine/SBansheeEngine.vcxproj

@@ -244,6 +244,7 @@
     <ClInclude Include="Include\BsScriptGameObject.h" />
     <ClInclude Include="Include\BsScriptGameObjectManager.h" />
     <ClInclude Include="Include\BsScriptGUIButton.h" />
+    <ClInclude Include="Include\BsScriptGUIElement.h" />
     <ClInclude Include="Include\BsScriptGUIFixedSpace.h" />
     <ClInclude Include="Include\BsScriptGUIFlexibleSpace.h" />
     <ClInclude Include="Include\BsScriptFont.h" />
@@ -286,6 +287,7 @@
     <ClCompile Include="Source\BsScriptEnginePlugin.cpp" />
     <ClCompile Include="Source\BsScriptGameObjectManager.cpp" />
     <ClCompile Include="Source\BsScriptGUIButton.cpp" />
+    <ClCompile Include="Source\BsScriptGUIElement.cpp" />
     <ClCompile Include="Source\BsScriptGUIFixedSpace.cpp" />
     <ClCompile Include="Source\BsScriptGUIFlexibleSpace.cpp" />
     <ClCompile Include="Source\BsScriptFont.cpp" />

+ 6 - 0
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -183,6 +183,9 @@
     <ClInclude Include="Include\BsScriptObjectImpl.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIElement.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -308,5 +311,8 @@
     <ClCompile Include="Source\BsScriptObject.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIElement.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 3 - 44
SBansheeEngine/Source/BsScriptGUIButton.cpp

@@ -22,7 +22,7 @@ namespace BansheeEngine
 	ScriptGUIButton::OnOutThunkDef ScriptGUIButton::onOutThunk;
 
 	ScriptGUIButton::ScriptGUIButton(MonoObject* instance, GUIButton* button)
-		:ScriptObject(instance), mButton(button), mIsDestroyed(false)
+		:TScriptGUIElement(instance, button)
 	{
 
 	}
@@ -32,33 +32,11 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIButton::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUIButton::internal_setContent);
 
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIButton::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIButton::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIButton::internal_setParent);
-
 		onClickThunk = (OnClickThunkDef)metaData.scriptClass->getMethod("DoOnClick").getThunk();
 		onHoverThunk = (OnHoverThunkDef)metaData.scriptClass->getMethod("DoOnHover").getThunk();
 		onOutThunk = (OnOutThunkDef)metaData.scriptClass->getMethod("DoOnOut").getThunk();
 	}
 
-	void ScriptGUIButton::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mButton);
-			mButton = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUIButton::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
-	}
-
 	void ScriptGUIButton::internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions)
 	{
 		GUIOptions options;
@@ -80,28 +58,9 @@ namespace BansheeEngine
 	void ScriptGUIButton::internal_setContent(ScriptGUIButton* nativeInstance, MonoObject* content)
 	{
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		nativeInstance->getInternalValue()->setContent(nativeContent);
-	}
-
-	void ScriptGUIButton::internal_destroy(ScriptGUIButton* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUIButton::internal_setVisible(ScriptGUIButton* nativeInstance, bool visible)
-	{
-		if(visible)
-			nativeInstance->getInternalValue()->enableRecursively();
-		else
-			nativeInstance->getInternalValue()->disableRecursively();
-	}
-
-	void ScriptGUIButton::internal_setParent(ScriptGUIButton* nativeInstance, MonoObject* parentLayout)
-	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(nativeInstance->getInternalValue());
+		GUIButton* button = (GUIButton*)nativeInstance->getGUIElement();
+		button->setContent(nativeContent);
 	}
 
 	void ScriptGUIButton::onClick(MonoObject* instance)

+ 62 - 0
SBansheeEngine/Source/BsScriptGUIElement.cpp

@@ -0,0 +1,62 @@
+#include "BsScriptGUIElement.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoMethod.h"
+#include "BsMonoUtil.h"
+#include "BsGUIElement.h"
+#include "BsScriptGUILayout.h"
+#include "BsGUILayout.h"
+
+namespace BansheeEngine
+{
+	ScriptGUIElementBase::ScriptGUIElementBase(GUIElement* element)
+		:mIsDestroyed(false), mElement(element)
+	{ }
+
+	ScriptGUIElement::ScriptGUIElement(MonoObject* instance)
+		:ScriptObject(instance)
+	{
+
+	}
+
+	void ScriptGUIElementBase::destroy()
+	{
+		if(!mIsDestroyed)
+		{
+			GUIElement::destroy(mElement);
+			mElement = nullptr;
+
+			mIsDestroyed = true;
+		}
+	}
+
+	void ScriptGUIElement::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
+		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIElement::internal_setParent);
+	}
+
+	void ScriptGUIElement::internal_destroy(ScriptGUIElementBase* nativeInstance)
+	{
+		nativeInstance->destroy();
+	}
+
+	void ScriptGUIElement::internal_setVisible(ScriptGUIElementBase* nativeInstance, bool visible)
+	{
+		if(visible)
+			nativeInstance->getGUIElement()->enableRecursively();
+		else
+			nativeInstance->getGUIElement()->disableRecursively();
+	}
+
+	void ScriptGUIElement::internal_setParent(ScriptGUIElementBase* nativeInstance, MonoObject* parentLayout)
+	{
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(nativeInstance->getGUIElement());
+	}
+}

+ 6 - 45
SBansheeEngine/Source/BsScriptGUIInputBox.cpp

@@ -18,7 +18,7 @@
 namespace BansheeEngine
 {
 	ScriptGUIInputBox::ScriptGUIInputBox(MonoObject* instance, GUIInputBox* inputBox)
-		:ScriptObject(instance), mInputBox(inputBox), mIsDestroyed(false)
+		:TScriptGUIElement(instance, inputBox)
 	{
 
 	}
@@ -28,28 +28,6 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIInputBox::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_GetText", &ScriptGUIInputBox::internal_getText);
 		metaData.scriptClass->addInternalCall("Internal_SetText", &ScriptGUIInputBox::internal_setText);
-
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIInputBox::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIInputBox::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIInputBox::internal_setParent);
-	}
-
-	void ScriptGUIInputBox::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mInputBox);
-			mInputBox = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUIInputBox::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
 	}
 
 	void ScriptGUIInputBox::internal_createInstance(MonoObject* instance, bool multiline, MonoString* style, MonoArray* guiOptions)
@@ -67,32 +45,15 @@ namespace BansheeEngine
 
 	void ScriptGUIInputBox::internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text)
 	{
-		*text = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), nativeInstance->getInternalValue()->getText());
-	}
+		GUIInputBox* inputBox = (GUIInputBox*)nativeInstance->getGUIElement();
 
-	void ScriptGUIInputBox::internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text)
-	{
-		nativeInstance->getInternalValue()->setText(MonoUtil::monoToWString(text));
-	}
-
-	void ScriptGUIInputBox::internal_destroy(ScriptGUIInputBox* nativeInstance)
-	{
-		nativeInstance->destroy();
+		*text = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), inputBox->getText());
 	}
 
-	void ScriptGUIInputBox::internal_setVisible(ScriptGUIInputBox* nativeInstance, bool visible)
-	{
-		if(visible)
-			nativeInstance->getInternalValue()->enableRecursively();
-		else
-			nativeInstance->getInternalValue()->disableRecursively();
-	}
-
-	void ScriptGUIInputBox::internal_setParent(ScriptGUIInputBox* nativeInstance, MonoObject* parentLayout)
+	void ScriptGUIInputBox::internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text)
 	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+		GUIInputBox* inputBox = (GUIInputBox*)nativeInstance->getGUIElement();
 
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(nativeInstance->getInternalValue());
+		inputBox->setText(MonoUtil::monoToWString(text));
 	}
 }

+ 3 - 44
SBansheeEngine/Source/BsScriptGUILabel.cpp

@@ -17,7 +17,7 @@
 namespace BansheeEngine
 {
 	ScriptGUILabel::ScriptGUILabel(MonoObject* instance, GUILabel* label)
-		:ScriptObject(instance), mLabel(label), mIsDestroyed(false)
+		:TScriptGUIElement(instance, label)
 	{
 
 	}
@@ -26,28 +26,6 @@ namespace BansheeEngine
 	{
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUILabel::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_SetContent", &ScriptGUILabel::internal_setContent);
-
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUILabel::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUILabel::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUILabel::internal_setParent);
-	}
-
-	void ScriptGUILabel::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mLabel);
-			mLabel = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUILabel::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
 	}
 
 	void ScriptGUILabel::internal_createInstance(MonoObject* instance, MonoObject* content, MonoString* style, MonoArray* guiOptions)
@@ -67,27 +45,8 @@ namespace BansheeEngine
 	void ScriptGUILabel::internal_setContent(ScriptGUILabel* nativeInstance, MonoObject* content)
 	{
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		nativeInstance->getInternalValue()->setContent(nativeContent);
-	}
-
-	void ScriptGUILabel::internal_destroy(ScriptGUILabel* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUILabel::internal_setVisible(ScriptGUILabel* nativeInstance, bool visible)
-	{
-		if(visible)
-			nativeInstance->getInternalValue()->enableRecursively();
-		else
-			nativeInstance->getInternalValue()->disableRecursively();
-	}
-
-	void ScriptGUILabel::internal_setParent(ScriptGUILabel* nativeInstance, MonoObject* parentLayout)
-	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
 
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(nativeInstance->getInternalValue());
+		GUILabel* label = (GUILabel*)nativeInstance->getGUIElement();
+		label->setContent(nativeContent);
 	}
 }

+ 3 - 1
SBansheeEngine/Source/BsScriptGUILayout.cpp

@@ -82,7 +82,9 @@ namespace BansheeEngine
 	void ScriptGUILayout::internal_createInstanceYFromScrollArea(MonoObject* instance, MonoObject* parentScrollArea)
 	{
 		ScriptGUIScrollArea* scriptScrollArea = ScriptGUIScrollArea::toNative(parentScrollArea);
-		GUILayout* nativeLayout = &scriptScrollArea->getInternalValue()->getLayout();
+		GUIScrollArea* scrollArea = (GUIScrollArea*)scriptScrollArea->getGUIElement();
+
+		GUILayout* nativeLayout = &scrollArea->getLayout();
 
 		ScriptGUILayout* nativeInstance = new (cm_alloc<ScriptGUILayout>()) 
 			ScriptGUILayout(instance, nativeLayout, nativeLayout);

+ 3 - 45
SBansheeEngine/Source/BsScriptGUIListBox.cpp

@@ -21,7 +21,7 @@ namespace BansheeEngine
 	ScriptGUIListBox::OnSelectionChangedThunkDef ScriptGUIListBox::onSelectionChangedThunk;
 
 	ScriptGUIListBox::ScriptGUIListBox(MonoObject* instance, GUIListBox* listBox)
-		:ScriptObject(instance), mListBox(listBox), mIsDestroyed(false)
+		:TScriptGUIElement(instance, listBox)
 	{
 
 	}
@@ -31,31 +31,9 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIListBox::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_SetElements", &ScriptGUIListBox::internal_setElements);
 
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIListBox::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIListBox::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIListBox::internal_setParent);
-
 		onSelectionChangedThunk = (OnSelectionChangedThunkDef)metaData.scriptClass->getMethod("DoOnSelectionChanged", 1).getThunk();
 	}
 
-	void ScriptGUIListBox::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mListBox);
-			mListBox = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUIListBox::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
-	}
-
 	void ScriptGUIListBox::internal_createInstance(MonoObject* instance, MonoArray* elements, MonoString* style, MonoArray* guiOptions)
 	{
 		GUIOptions options;
@@ -102,28 +80,8 @@ namespace BansheeEngine
 			}
 		}
 
-		nativeInstance->getInternalValue()->setElements(nativeElements);
-	}
-
-	void ScriptGUIListBox::internal_destroy(ScriptGUIListBox* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUIListBox::internal_setVisible(ScriptGUIListBox* nativeInstance, bool visible)
-	{
-		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());
+		GUIListBox* listBox = (GUIListBox*)nativeInstance->getGUIElement();
+		listBox->setElements(nativeElements);
 	}
 
 	void ScriptGUIListBox::onSelectionChanged(MonoObject* instance, UINT32 index)

+ 1 - 44
SBansheeEngine/Source/BsScriptGUIScrollArea.cpp

@@ -18,7 +18,7 @@
 namespace BansheeEngine
 {
 	ScriptGUIScrollArea::ScriptGUIScrollArea(MonoObject* instance, GUIScrollArea* scrollArea)
-		:ScriptObject(instance), mScrollArea(scrollArea), mIsDestroyed(false)
+		:TScriptGUIElement(instance, scrollArea)
 	{
 
 	}
@@ -26,28 +26,6 @@ namespace BansheeEngine
 	void ScriptGUIScrollArea::initRuntimeData()
 	{
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIScrollArea::internal_createInstance);
-
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIScrollArea::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIScrollArea::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIScrollArea::internal_setParent);
-	}
-
-	void ScriptGUIScrollArea::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mScrollArea);
-			mScrollArea = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUIScrollArea::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
 	}
 
 	void ScriptGUIScrollArea::internal_createInstance(MonoObject* instance, ScrollBarType vertBarType, ScrollBarType horzBarType, 
@@ -64,25 +42,4 @@ namespace BansheeEngine
 
 		ScriptGUIScrollArea* nativeInstance = new (cm_alloc<ScriptGUIScrollArea>()) ScriptGUIScrollArea(instance, guiScrollArea);
 	}
-
-	void ScriptGUIScrollArea::internal_destroy(ScriptGUIScrollArea* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUIScrollArea::internal_setVisible(ScriptGUIScrollArea* nativeInstance, bool visible)
-	{
-		if(visible)
-			nativeInstance->getInternalValue()->enableRecursively();
-		else
-			nativeInstance->getInternalValue()->disableRecursively();
-	}
-
-	void ScriptGUIScrollArea::internal_setParent(ScriptGUIScrollArea* nativeInstance, MonoObject* parentLayout)
-	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
-
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(nativeInstance->getInternalValue());
-	}
 }

+ 3 - 45
SBansheeEngine/Source/BsScriptGUITexture.cpp

@@ -18,7 +18,7 @@
 namespace BansheeEngine
 {
 	ScriptGUITexture::ScriptGUITexture(MonoObject* instance, GUITexture* texture)
-		:ScriptObject(instance), mTexture(texture), mIsDestroyed(false)
+		:TScriptGUIElement(instance, texture)
 	{
 
 	}
@@ -27,28 +27,6 @@ namespace BansheeEngine
 	{
 		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUITexture::internal_createInstance);
 		metaData.scriptClass->addInternalCall("Internal_SetTexture", &ScriptGUITexture::internal_setTexture);
-
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUITexture::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUITexture::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUITexture::internal_setParent);
-	}
-
-	void ScriptGUITexture::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mTexture);
-			mTexture = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUITexture::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
 	}
 
 	void ScriptGUITexture::internal_createInstance(MonoObject* instance, MonoObject* texture, 
@@ -75,27 +53,7 @@ namespace BansheeEngine
 		if(texture != nullptr)
 			nativeTexture = ScriptSpriteTexture::toNative(texture)->getInternalValue();
 
-		nativeInstance->getInternalValue()->setTexture(nativeTexture);
-	}
-
-	void ScriptGUITexture::internal_destroy(ScriptGUITexture* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUITexture::internal_setVisible(ScriptGUITexture* nativeInstance, bool visible)
-	{
-		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());
+		GUITexture* guiTexture = (GUITexture*)nativeInstance->getGUIElement();
+		guiTexture->setTexture(nativeTexture);
 	}
 }

+ 8 - 47
SBansheeEngine/Source/BsScriptGUIToggle.cpp

@@ -27,7 +27,7 @@ namespace BansheeEngine
 	ScriptGUIToggle::OnToggledThunkDef ScriptGUIToggle::onToggledThunk;
 
 	ScriptGUIToggle::ScriptGUIToggle(MonoObject* instance, GUIToggle* toggle)
-		:ScriptObject(instance), mToggle(toggle), mIsDestroyed(false)
+		:TScriptGUIElement(instance, toggle)
 	{
 
 	}
@@ -39,34 +39,12 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_ToggleOn", &ScriptGUIToggle::internal_toggleOn);
 		metaData.scriptClass->addInternalCall("Internal_ToggleOff", &ScriptGUIToggle::internal_toggleOff);
 
-		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIToggle::internal_destroy);
-		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIToggle::internal_setVisible);
-		metaData.scriptClass->addInternalCall("Internal_SetParent", &ScriptGUIToggle::internal_setParent);
-
 		onClickThunk = (OnClickThunkDef)metaData.scriptClass->getMethod("DoOnClick").getThunk();
 		onHoverThunk = (OnHoverThunkDef)metaData.scriptClass->getMethod("DoOnHover").getThunk();
 		onOutThunk = (OnOutThunkDef)metaData.scriptClass->getMethod("DoOnOut").getThunk();
 		onToggledThunk = (OnToggledThunkDef)metaData.scriptClass->getMethod("DoOnToggled", 1).getThunk();
 	}
 
-	void ScriptGUIToggle::destroy()
-	{
-		if(!mIsDestroyed)
-		{
-			GUIElement::destroy(mToggle);
-			mToggle = nullptr;
-
-			mIsDestroyed = true;
-		}
-	}
-
-	void ScriptGUIToggle::_onManagedInstanceDeleted()
-	{
-		destroy();
-
-		ScriptObject::_onManagedInstanceDeleted();
-	}
-
 	void ScriptGUIToggle::internal_createInstance(MonoObject* instance, MonoObject* content, 
 		MonoObject* toggleGroup, MonoString* style, MonoArray* guiOptions)
 	{
@@ -94,38 +72,21 @@ namespace BansheeEngine
 	void ScriptGUIToggle::internal_setContent(ScriptGUIToggle* nativeInstance, MonoObject* content)
 	{
 		GUIContent nativeContent(ScriptGUIContent::getText(content), ScriptGUIContent::getImage(content), ScriptGUIContent::getTooltip(content));
-		nativeInstance->getInternalValue()->setContent(nativeContent);
+
+		GUIToggle* toggle = (GUIToggle*)nativeInstance->getGUIElement();
+		toggle->setContent(nativeContent);
 	}
 
 	void ScriptGUIToggle::internal_toggleOn(ScriptGUIToggle* nativeInstance)
 	{
-		nativeInstance->getInternalValue()->toggleOn();
+		GUIToggle* toggle = (GUIToggle*)nativeInstance->getGUIElement();
+		toggle->toggleOn();
 	}
 
 	void ScriptGUIToggle::internal_toggleOff(ScriptGUIToggle* nativeInstance)
 	{
-		nativeInstance->getInternalValue()->toggleOff();
-	}
-
-	void ScriptGUIToggle::internal_destroy(ScriptGUIToggle* nativeInstance)
-	{
-		nativeInstance->destroy();
-	}
-
-	void ScriptGUIToggle::internal_setVisible(ScriptGUIToggle* nativeInstance, bool visible)
-	{
-		if(visible)
-			nativeInstance->getInternalValue()->enableRecursively();
-		else
-			nativeInstance->getInternalValue()->disableRecursively();
-	}
-
-	void ScriptGUIToggle::internal_setParent(ScriptGUIToggle* nativeInstance, MonoObject* parentLayout)
-	{
-		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
-
-		GUILayout* nativeLayout = scriptLayout->getInternalValue();
-		nativeLayout->addElement(nativeInstance->getInternalValue());
+		GUIToggle* toggle = (GUIToggle*)nativeInstance->getGUIElement();
+		toggle->toggleOff();
 	}
 
 	void ScriptGUIToggle::onClick(MonoObject* instance)