Browse Source

Refactor: Added script export for GUIColorGradient

BearishSun 7 years ago
parent
commit
c6b9730fd6

+ 7 - 3
Source/EditorCore/GUI/BsGUIColorGradient.h

@@ -15,7 +15,7 @@ namespace bs
 	 */
 
 	/** GUI element that displays a color gradient. */
-	class GUIColorGradient : public GUIElement
+	class BS_ED_EXPORT BS_SCRIPT_EXPORT(ed:true,m:GUIEditor) GUIColorGradient : public GUIElement
 	{
 	public:
 		/** Returns type name of the GUI element used for finding GUI element styles. */
@@ -27,6 +27,7 @@ namespace bs
 		 * @param[in]	styleName		Optional style to use for the element. Style will be retrieved from GUISkin of the
 		 *								GUIWidget the element is used on. If not specified default style is used.
 		 */
+		BS_SCRIPT_EXPORT(ec:GUIColorGradient)
 		static GUIColorGradient* create(const String& styleName = StringUtil::BLANK);
 
 		/**
@@ -39,12 +40,15 @@ namespace bs
 		 */
 		static GUIColorGradient* create(const GUIOptions& options, const String& styleName = StringUtil::BLANK);
 
-		/**	Sets the color gradient to display. */
+		/**	Color gradient to display. */
+		BS_SCRIPT_EXPORT(pr:setter,n:Gradient)
 		void setGradient(const ColorGradient& colorGradient);
 
-		/**	Returns the currently displayed color gradient. */
+		/** @copydoc setGradient */
+		BS_SCRIPT_EXPORT(pr:getter,n:Gradient)
 		ColorGradient getGradient() const { return mValue; }
 
+		BS_SCRIPT_EXPORT()
 		Event<void()> onClicked; /**< Triggered when the user clicks on the GUI element. */
 
 		/** @name Internal

+ 0 - 5
Source/EditorCore/GUI/BsGUIWindowFrameWidget.cpp

@@ -31,11 +31,6 @@ namespace bs
 		refreshNonClientAreas();
 	}
 
-	WindowFrameWidget::~WindowFrameWidget()
-	{
-
-	}
-
 	void WindowFrameWidget::ownerWindowFocusChanged()
 	{
 		mWindowFrame->setFocused(mParentWindow->getProperties().hasFocus);

+ 2 - 2
Source/EditorCore/GUI/BsGUIWindowFrameWidget.h

@@ -30,7 +30,7 @@ namespace bs
 		 */
 		WindowFrameWidget(const HSceneObject& parent, bool allowResize, const SPtr<Camera>& camera, RenderWindow* ownerWindow, 
 			const HGUISkin& skin);
-		virtual ~WindowFrameWidget();
+		virtual ~WindowFrameWidget() = default;
 
 	protected:
 		/** @copydoc GUIWidget::ownerWindowFocusChanged */
@@ -58,7 +58,7 @@ namespace bs
 	public:
 		friend class CWindowFrameWidgetRTTI;
 		static RTTITypeBase* getRTTIStatic();
-		virtual RTTITypeBase* getRTTI() const override;
+		RTTITypeBase* getRTTI() const override;
 
 		WindowFrameWidget() { } // Serialization only
 	};

+ 51 - 0
Source/Scripting/MBansheeEditor/Generated/GUIColorGradient.generated.cs

@@ -0,0 +1,51 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+	/** @addtogroup GUIEditor
+	 *  @{
+	 */
+
+	/// <summary>GUI element that displays a color gradient.</summary>
+	public partial class GUIColorGradient : GUIElement
+	{
+		private GUIColorGradient(bool __dummy0) { }
+		protected GUIColorGradient() { }
+
+		/// <summary>Creates a new GUI color gradient element.</summary>
+		/// <param name="styleName">
+		/// Optional style to use for the element. Style will be retrieved from GUISkin of the GUIWidget the element is used on. 
+		/// If not specified default style is used.
+		/// </param>
+		public GUIColorGradient(string styleName = "")
+		{
+			Internal_create(this, styleName);
+		}
+
+		/// <summary>Color gradient to display.</summary>
+		public ColorGradient Gradient
+		{
+			get { return Internal_getGradient(mCachedPtr); }
+			set { Internal_setGradient(mCachedPtr, value); }
+		}
+
+		/// <summary>Triggered when the user clicks on the GUI element.</summary>
+		public event Action OnClicked;
+
+		[MethodImpl(MethodImplOptions.InternalCall)]
+		private static extern void Internal_setGradient(IntPtr thisPtr, ColorGradient colorGradient);
+		[MethodImpl(MethodImplOptions.InternalCall)]
+		private static extern ColorGradient Internal_getGradient(IntPtr thisPtr);
+		[MethodImpl(MethodImplOptions.InternalCall)]
+		private static extern void Internal_create(GUIColorGradient managedInstance, string styleName);
+		private void Internal_onClicked()
+		{
+			OnClicked?.Invoke();
+		}
+	}
+
+	/** @} */
+}

+ 16 - 4
Source/Scripting/MBansheeEngine/Generated/ColorGradient.generated.cs

@@ -31,10 +31,20 @@ namespace BansheeEngine
 			Internal_ColorGradient1(this, keys);
 		}
 
-		/// <summary>Set of keys that control the gradient, sorted by time from first to last.</summary>
-		public void SetKeys(ColorGradientKey[] keys)
+		/// <summary>
+		/// Keys that control the gradient, sorted by time from first to last. Key times should be in range [0, 1].
+		/// </summary>
+		public void SetKeys(ColorGradientKey[] keys, float duration = 1f)
 		{
-			Internal_setKeys(mCachedPtr, keys);
+			Internal_setKeys(mCachedPtr, keys, duration);
+		}
+
+		/// <summary>
+		/// Keys that control the gradient, sorted by time from first to last. Key times should be in range [0, 1].
+		/// </summary>
+		public ColorGradientKey[] GetKeys()
+		{
+			return Internal_getKeys(mCachedPtr);
 		}
 
 		/// <summary>Specify a "gradient" that represents a single color value.</summary>
@@ -58,7 +68,9 @@ namespace BansheeEngine
 		[MethodImpl(MethodImplOptions.InternalCall)]
 		private static extern void Internal_ColorGradient1(ColorGradient managedInstance, ColorGradientKey[] keys);
 		[MethodImpl(MethodImplOptions.InternalCall)]
-		private static extern void Internal_setKeys(IntPtr thisPtr, ColorGradientKey[] keys);
+		private static extern void Internal_setKeys(IntPtr thisPtr, ColorGradientKey[] keys, float duration);
+		[MethodImpl(MethodImplOptions.InternalCall)]
+		private static extern ColorGradientKey[] Internal_getKeys(IntPtr thisPtr);
 		[MethodImpl(MethodImplOptions.InternalCall)]
 		private static extern void Internal_setConstant(IntPtr thisPtr, ref Color color);
 		[MethodImpl(MethodImplOptions.InternalCall)]

+ 59 - 0
Source/Scripting/SBansheeEditor/Generated/BsScriptGUIColorGradient.generated.cpp

@@ -0,0 +1,59 @@
+#include "BsScriptGUIColorGradient.generated.h"
+#include "BsMonoMethod.h"
+#include "BsMonoClass.h"
+#include "BsMonoUtil.h"
+#include "../../../EditorCore/GUI/BsGUIColorGradient.h"
+#include "BsScriptColorGradient.generated.h"
+#include "../../../EditorCore/GUI/BsGUIColorGradient.h"
+
+namespace bs
+{
+	ScriptGUIColorGradient::onClickedThunkDef ScriptGUIColorGradient::onClickedThunk; 
+
+	ScriptGUIColorGradient::ScriptGUIColorGradient(MonoObject* managedInstance, GUIColorGradient* value)
+		:TScriptGUIElement(managedInstance, value)
+	{
+		value->onClicked.connect(std::bind(&ScriptGUIColorGradient::onClicked, this));
+	}
+
+	void ScriptGUIColorGradient::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_setGradient", (void*)&ScriptGUIColorGradient::Internal_setGradient);
+		metaData.scriptClass->addInternalCall("Internal_getGradient", (void*)&ScriptGUIColorGradient::Internal_getGradient);
+		metaData.scriptClass->addInternalCall("Internal_create", (void*)&ScriptGUIColorGradient::Internal_create);
+
+		onClickedThunk = (onClickedThunkDef)metaData.scriptClass->getMethodExact("Internal_onClicked", "")->getThunk();
+	}
+
+	void ScriptGUIColorGradient::onClicked()
+	{
+		MonoUtil::invokeThunk(onClickedThunk, getManagedInstance());
+	}
+	void ScriptGUIColorGradient::Internal_setGradient(ScriptGUIColorGradient* thisPtr, MonoObject* colorGradient)
+	{
+		SPtr<ColorGradient> tmpcolorGradient;
+		ScriptColorGradient* scriptcolorGradient;
+		scriptcolorGradient = ScriptColorGradient::toNative(colorGradient);
+		tmpcolorGradient = scriptcolorGradient->getInternal();
+		static_cast<GUIColorGradient*>(thisPtr->getGUIElement())->setGradient(*tmpcolorGradient);
+	}
+
+	MonoObject* ScriptGUIColorGradient::Internal_getGradient(ScriptGUIColorGradient* thisPtr)
+	{
+		SPtr<ColorGradient> tmp__output = bs_shared_ptr_new<ColorGradient>();
+		*tmp__output = static_cast<GUIColorGradient*>(thisPtr->getGUIElement())->getGradient();
+
+		MonoObject* __output;
+		__output = ScriptColorGradient::create(tmp__output);
+
+		return __output;
+	}
+
+	void ScriptGUIColorGradient::Internal_create(MonoObject* managedInstance, MonoString* styleName)
+	{
+		String tmpstyleName;
+		tmpstyleName = MonoUtil::monoToString(styleName);
+		GUIColorGradient* instance = GUIColorGradient::create(tmpstyleName);
+		new (bs_alloc<ScriptGUIColorGradient>())ScriptGUIColorGradient(managedInstance, instance);
+	}
+}

+ 28 - 0
Source/Scripting/SBansheeEditor/Generated/BsScriptGUIColorGradient.generated.h

@@ -0,0 +1,28 @@
+#pragma once
+
+#include "BsScriptEditorPrerequisites.h"
+#include "Wrappers/GUI/BsScriptGUIElement.h"
+#include "../../../bsf/Source/Foundation/bsfUtility/Image/BsColorGradient.h"
+
+namespace bs
+{
+	class GUIColorGradient;
+
+	class BS_SCR_BED_EXPORT ScriptGUIColorGradient : public TScriptGUIElement<ScriptGUIColorGradient>
+	{
+	public:
+		SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "GUIColorGradient")
+
+		ScriptGUIColorGradient(MonoObject* managedInstance, GUIColorGradient* value);
+
+	private:
+		void onClicked();
+
+		typedef void(BS_THUNKCALL *onClickedThunkDef) (MonoObject*, MonoException**);
+		static onClickedThunkDef onClickedThunk;
+
+		static void Internal_setGradient(ScriptGUIColorGradient* thisPtr, MonoObject* colorGradient);
+		static MonoObject* Internal_getGradient(ScriptGUIColorGradient* thisPtr);
+		static void Internal_create(MonoObject* managedInstance, MonoString* styleName);
+	};
+}

+ 1 - 3
Source/Scripting/SBansheeEngine/Extensions/BsMeshEx.cpp

@@ -87,9 +87,7 @@ namespace bs
 
 	SPtr<RendererMeshData> MeshEx::getMeshData(const HMesh& thisPtr)
 	{
-		SPtr<MeshData> meshData = thisPtr->allocBuffer();
-		thisPtr->readCachedData(*meshData);
-
+		const SPtr<MeshData>& meshData = thisPtr->getCachedData();
 		return RendererMeshData::create(meshData);
 	}
 

+ 21 - 2
Source/Scripting/SBansheeEngine/Generated/BsScriptColorGradient.generated.cpp

@@ -20,6 +20,7 @@ namespace bs
 		metaData.scriptClass->addInternalCall("Internal_ColorGradient0", (void*)&ScriptColorGradient::Internal_ColorGradient0);
 		metaData.scriptClass->addInternalCall("Internal_ColorGradient1", (void*)&ScriptColorGradient::Internal_ColorGradient1);
 		metaData.scriptClass->addInternalCall("Internal_setKeys", (void*)&ScriptColorGradient::Internal_setKeys);
+		metaData.scriptClass->addInternalCall("Internal_getKeys", (void*)&ScriptColorGradient::Internal_getKeys);
 		metaData.scriptClass->addInternalCall("Internal_setConstant", (void*)&ScriptColorGradient::Internal_setConstant);
 		metaData.scriptClass->addInternalCall("Internal_evaluate", (void*)&ScriptColorGradient::Internal_evaluate);
 
@@ -64,7 +65,7 @@ namespace bs
 		new (bs_alloc<ScriptColorGradient>())ScriptColorGradient(managedInstance, instance);
 	}
 
-	void ScriptColorGradient::Internal_setKeys(ScriptColorGradient* thisPtr, MonoArray* keys)
+	void ScriptColorGradient::Internal_setKeys(ScriptColorGradient* thisPtr, MonoArray* keys, float duration)
 	{
 		Vector<ColorGradientKey> veckeys;
 		if(keys != nullptr)
@@ -75,8 +76,26 @@ namespace bs
 			{
 				veckeys[i] = ScriptColorGradientKey::fromInterop(arraykeys.get<__ColorGradientKeyInterop>(i));
 			}
+
+		}
+		thisPtr->getInternal()->setKeys(veckeys, duration);
+	}
+
+	MonoArray* ScriptColorGradient::Internal_getKeys(ScriptColorGradient* thisPtr)
+	{
+		Vector<ColorGradientKey> vec__output;
+		vec__output = thisPtr->getInternal()->getKeys();
+
+		MonoArray* __output;
+		int arraySize__output = (int)vec__output.size();
+		ScriptArray array__output = ScriptArray::create<ScriptColorGradientKey>(arraySize__output);
+		for(int i = 0; i < arraySize__output; i++)
+		{
+			array__output.set(i, ScriptColorGradientKey::toInterop(vec__output[i]));
 		}
-		thisPtr->getInternal()->setKeys(veckeys);
+		__output = array__output.getInternal();
+
+		return __output;
 	}
 
 	void ScriptColorGradient::Internal_setConstant(ScriptColorGradient* thisPtr, Color* color)

+ 2 - 1
Source/Scripting/SBansheeEngine/Generated/BsScriptColorGradient.generated.h

@@ -25,7 +25,8 @@ namespace bs
 		static void Internal_ColorGradient(MonoObject* managedInstance);
 		static void Internal_ColorGradient0(MonoObject* managedInstance, Color* color);
 		static void Internal_ColorGradient1(MonoObject* managedInstance, MonoArray* keys);
-		static void Internal_setKeys(ScriptColorGradient* thisPtr, MonoArray* keys);
+		static void Internal_setKeys(ScriptColorGradient* thisPtr, MonoArray* keys, float duration);
+		static MonoArray* Internal_getKeys(ScriptColorGradient* thisPtr);
 		static void Internal_setConstant(ScriptColorGradient* thisPtr, Color* color);
 		static void Internal_evaluate(ScriptColorGradient* thisPtr, float t, Color* __output);
 	};