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

Added a wrapper for GUIPanelContainer

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

+ 5 - 1
BansheeEngine/Include/BsGUILayoutUtility.h

@@ -22,6 +22,10 @@ namespace BansheeEngine
 		* Calculates position and size of a GUI element in its current layout.
 		* Returned position is relative to layout origin.
 		*/
-		static RectI calcArea(const GUIElementBase* elem);
+		// TODO - This method might fail if element is part of a more complex hierarchy
+		// other than just GUILayouts and base elements (e.g. a tree view) because for a lot
+		// of such custom container elements like tree view don't have method for calculating 
+		// element bounds implemented
+		static RectI calcBounds(const GUIElementBase* elem);
 	};
 }

+ 2 - 2
BansheeEngine/Source/BsGUILayoutUtility.cpp

@@ -10,13 +10,13 @@ namespace BansheeEngine
 		return elem->_calculateOptimalLayoutSize();
 	}
 
-	RectI GUILayoutUtility::calcArea(const GUIElementBase* elem)
+	RectI GUILayoutUtility::calcBounds(const GUIElementBase* elem)
 	{
 		RectI parentArea;
 
 		GUIElementBase* parent = elem->_getParent();
 		if (parent != nullptr)
-			parentArea = calcArea(parent);
+			parentArea = calcBounds(parent);
 		else
 		{
 			assert(elem->_getType() == GUIElementBase::Type::Layout);

+ 30 - 0
MBansheeEditor/GUI/GUIPanelContainer.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Runtime.CompilerServices;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    public sealed class GUIPanelContainer : GUIElement
+    {
+        public GUIPanelContainer(GUIPanel panel, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, panel, options);
+        }
+
+        public GUIPanelContainer(GUIPanel panel)
+        {
+            Internal_CreateInstance(this, panel, new GUIOption[0]);
+        }
+
+        public void SetPanel(GUIPanel panel)
+        {
+            Internal_SetPanel(mCachedPtr, panel);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(GUIPanelContainer instance, GUIPanel panel, GUIOption[] options);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetPanel(IntPtr nativeInstance, GUIPanel panel);
+    }
+}

+ 1 - 0
MBansheeEditor/MBansheeEditor.csproj

@@ -47,6 +47,7 @@
     <Compile Include="EditorWindow.cs" />
     <Compile Include="GUI\GUIFoldout.cs" />
     <Compile Include="GUI\GUIIntField.cs" />
+    <Compile Include="GUI\GUIPanelContainer.cs" />
     <Compile Include="Inspector\CustomInspector.cs" />
     <Compile Include="Inspector\GenericInspector.cs" />
     <Compile Include="Inspector\InspectableArray.cs" />

+ 23 - 0
SBansheeEditor/Include/BsScriptGUIPanelContainer.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsGUIPanelContainer.h"
+#include "BsScriptGUIPanel.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BED_EXPORT ScriptGUIPanelContainer : public ScriptObject<ScriptGUIPanelContainer>
+	{
+	public:
+		SCRIPT_OBJ(BansheeEditorAssemblyName, "BansheeEditor", "GUIPanelContainer")
+
+	private:
+		static void internal_createInstance(MonoObject* instance, MonoObject* panel, MonoArray* guiOptions);
+		static void internal_setPanel(ScriptGUIPanelContainer* nativeInstance, MonoObject* panel);
+
+		ScriptGUIPanelContainer(MonoObject* instance, GUIPanelContainer* panelContainer);
+
+		GUIPanelContainer* mGUIPanelContainer;
+	};
+}

+ 2 - 0
SBansheeEditor/SBansheeEditor.vcxproj

@@ -231,6 +231,7 @@
     <ClInclude Include="Include\BsScriptEditorWindow.h" />
     <ClInclude Include="Include\BsScriptGUIFoldout.h" />
     <ClInclude Include="Include\BsScriptGUIIntField.h" />
+    <ClInclude Include="Include\BsScriptGUIPanelContainer.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIPanelContainer.cpp" />
@@ -238,6 +239,7 @@
     <ClCompile Include="Source\BsScriptEditorWindow.cpp" />
     <ClCompile Include="Source\BsScriptGUIFoldout.cpp" />
     <ClCompile Include="Source\BsScriptGUIIntField.cpp" />
+    <ClCompile Include="Source\BsScriptGUIPanelContainer.cpp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 6 - 0
SBansheeEditor/SBansheeEditor.vcxproj.filters

@@ -30,6 +30,9 @@
     <ClInclude Include="Include\BsGUIPanelContainer.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIPanelContainer.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptEditorPlugin.cpp">
@@ -47,5 +50,8 @@
     <ClCompile Include="Source\BsGUIPanelContainer.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIPanelContainer.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 44 - 0
SBansheeEditor/Source/BsScriptGUIPanelContainer.cpp

@@ -0,0 +1,44 @@
+#include "BsScriptGUIPanelContainer.h"
+#include "BsGUIPanelContainer.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsMonoMethod.h"
+#include "BsGUIOptions.h"
+
+namespace BansheeEngine
+{
+	ScriptGUIPanelContainer::ScriptGUIPanelContainer(MonoObject* instance, GUIPanelContainer* panelContainer)
+		:ScriptObject(instance), mGUIPanelContainer(panelContainer)
+	{
+
+	}
+
+	void ScriptGUIPanelContainer::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIPanelContainer::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_SetPanel", &ScriptGUIPanelContainer::internal_setPanel);
+	}
+
+	void ScriptGUIPanelContainer::internal_createInstance(MonoObject* instance, MonoObject* panel, MonoArray* guiOptions)
+	{
+		GUIOptions options;
+
+		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
+		for (UINT32 i = 0; i < arrayLen; i++)
+			options.addOption(mono_array_get(guiOptions, GUIOption, i));
+
+		ScriptGUIPanel* guiPanel = ScriptGUIPanel::toNative(panel);
+		GUIPanelContainer* guiPanelContainer = GUIPanelContainer::create(*guiPanel, options);
+
+		ScriptGUIPanelContainer* nativeInstance = new (bs_alloc<ScriptGUIPanelContainer>()) ScriptGUIPanelContainer(instance, guiPanelContainer);
+	}
+
+	void ScriptGUIPanelContainer::internal_setPanel(ScriptGUIPanelContainer* nativeInstance, MonoObject* panel)
+	{
+		ScriptGUIPanel* guiPanel = ScriptGUIPanel::toNative(panel);
+
+		nativeInstance->mGUIPanelContainer->setPanel(*guiPanel);
+	}
+}

+ 1 - 1
SBansheeEngine/Source/BsScriptGUILayoutUtility.cpp

@@ -26,6 +26,6 @@ namespace BansheeEngine
 
 	RectI ScriptGUILayoutUtility::internal_CalculateBounds(ScriptGUIElementBaseTBase* guiElement)
 	{
-		return GUILayoutUtility::calcArea(guiElement->getGUIElement());
+		return GUILayoutUtility::calcBounds(guiElement->getGUIElement());
 	}
 }