Browse Source

Added C# GUIRenderTexture

Marko Pintera 11 years ago
parent
commit
e9e4405246

+ 42 - 0
MBansheeEngine/GUI/GUIRenderTexture.cs

@@ -0,0 +1,42 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    public sealed class GUIRenderTexture : GUIElement
+    {
+        public GUIRenderTexture(RenderTexture2D texture, string style, params GUIOption[] options)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (texture != null)
+                texturePtr = texture.GetCachedPtr();
+
+            Internal_CreateInstance(this, texturePtr, style, options);
+        }
+
+        public GUIRenderTexture(RenderTexture2D texture, params GUIOption[] options)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (texture != null)
+                texturePtr = texture.GetCachedPtr();
+
+            Internal_CreateInstance(this, texturePtr, "", options);
+        }
+
+        public void SetTexture(RenderTexture2D texture)
+        {
+            IntPtr texturePtr = IntPtr.Zero;
+            if (texture != null)
+                texturePtr = texture.GetCachedPtr();
+
+            Internal_SetTexture(mCachedPtr, texturePtr);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(GUIRenderTexture instance, IntPtr texture,
+            string style, GUIOption[] options);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetTexture(IntPtr nativeInstance, IntPtr texture);
+    }
+}

+ 1 - 0
MBansheeEngine/MBansheeEngine.csproj

@@ -65,6 +65,7 @@
     <Compile Include="GUI\GUIElementStateStyle.cs" />
     <Compile Include="GUI\GUIElementStyle.cs" />
     <Compile Include="GUI\GUIListBox.cs" />
+    <Compile Include="GUI\GUIRenderTexture.cs" />
     <Compile Include="GUI\GUIScrollArea.cs" />
     <Compile Include="GUI\GUITextBox.cs" />
     <Compile Include="GUI\GUILabel.cs" />

+ 1 - 0
SBansheeEngine/Include/BsScriptEnginePrerequisites.h

@@ -38,6 +38,7 @@ namespace BansheeEngine
 	class ScriptComponent;
 	class ScriptManagedResource;
 	class ScriptRenderTarget;
+	class ScriptRenderTexture2D;
 	class ManagedComponent;
 	class ManagedSerializableFieldData;
 	class ManagedSerializableFieldKey;

+ 20 - 0
SBansheeEngine/Include/BsScriptGUIRenderTexture.h

@@ -0,0 +1,20 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptGUIElement.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptGUIRenderTexture : public TScriptGUIElement < ScriptGUIRenderTexture >
+	{
+	public:
+		SCRIPT_OBJ(BansheeEngineAssemblyName, "BansheeEngine", "GUIRenderTexture")
+
+	private:
+		static void internal_createInstance(MonoObject* instance, ScriptRenderTexture2D* texture,
+			MonoString* style, MonoArray* guiOptions);
+		static void internal_setTexture(ScriptGUIRenderTexture* nativeInstance, ScriptRenderTexture2D* texture);
+
+		ScriptGUIRenderTexture(MonoObject* instance, GUIRenderTexture* texture);
+	};
+}

+ 2 - 0
SBansheeEngine/SBansheeEngine.vcxproj

@@ -272,6 +272,7 @@
     <ClInclude Include="Include\BsScriptGUILabel.h" />
     <ClInclude Include="Include\BsScriptGUILayout.h" />
     <ClInclude Include="Include\BsScriptGUIListBox.h" />
+    <ClInclude Include="Include\BsScriptGUIRenderTexture.h" />
     <ClInclude Include="Include\BsScriptGUIScrollArea.h" />
     <ClInclude Include="Include\BsScriptGUITexture.h" />
     <ClInclude Include="Include\BsScriptGUIToggle.h" />
@@ -339,6 +340,7 @@
     <ClCompile Include="Source\BsScriptGUILabel.cpp" />
     <ClCompile Include="Source\BsScriptGUILayout.cpp" />
     <ClCompile Include="Source\BsScriptGUIListBox.cpp" />
+    <ClCompile Include="Source\BsScriptGUIRenderTexture.cpp" />
     <ClCompile Include="Source\BsScriptGUIScrollArea.cpp" />
     <ClCompile Include="Source\BsScriptGUITexture.cpp" />
     <ClCompile Include="Source\BsScriptGUIToggle.cpp" />

+ 6 - 0
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -270,6 +270,9 @@
     <ClInclude Include="Include\BsScriptTime.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIRenderTexture.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -473,5 +476,8 @@
     <ClCompile Include="Source\BsScriptTime.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIRenderTexture.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 59 - 0
SBansheeEngine/Source/BsScriptGUIRenderTexture.cpp

@@ -0,0 +1,59 @@
+#include "BsScriptGUIRenderTexture.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsSpriteTexture.h"
+#include "BsMonoUtil.h"
+#include "BsGUILayout.h"
+#include "BsGUIRenderTexture.h"
+#include "BsGUIOptions.h"
+#include "BsScriptGUIElementStyle.h"
+#include "BsScriptGUILayout.h"
+#include "BsScriptGUIArea.h"
+#include "BsScriptHString.h"
+#include "BsScriptGUIContent.h"
+#include "BsScriptRenderTexture2D.h"
+
+namespace BansheeEngine
+{
+	ScriptGUIRenderTexture::ScriptGUIRenderTexture(MonoObject* instance, GUIRenderTexture* texture)
+		:TScriptGUIElement(instance, texture)
+	{
+
+	}
+
+	void ScriptGUIRenderTexture::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIRenderTexture::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_SetTexture", &ScriptGUIRenderTexture::internal_setTexture);
+	}
+
+	void ScriptGUIRenderTexture::internal_createInstance(MonoObject* instance, 
+		ScriptRenderTexture2D* texture, MonoString* style, 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));
+
+		RenderTexturePtr renderTexture;
+		if (texture != nullptr)
+			renderTexture = texture->getRenderTexture();
+
+		GUIRenderTexture* guiTexture = GUIRenderTexture::create(renderTexture, options, toString(MonoUtil::monoToWString(style)));
+
+		ScriptGUIRenderTexture* nativeInstance = new (bs_alloc<ScriptGUIRenderTexture>()) ScriptGUIRenderTexture(instance, guiTexture);
+	}
+
+	void ScriptGUIRenderTexture::internal_setTexture(ScriptGUIRenderTexture* nativeInstance, ScriptRenderTexture2D* texture)
+	{
+		RenderTexturePtr renderTexture;
+		if (texture != nullptr)
+			renderTexture = texture->getRenderTexture();
+
+		GUIRenderTexture* guiTexture = (GUIRenderTexture*)nativeInstance->getGUIElement();
+		guiTexture->setRenderTexture(renderTexture);
+	}
+}