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

Fixed GUIManager widget grouping because it sometimes didn't merge different depth layers correctly
C#: GUITextBox

Marko Pintera 12 лет назад
Родитель
Сommit
ba0da03489

+ 3 - 1
BansheeEngine/Include/BsGUIInputBox.h

@@ -13,9 +13,11 @@ namespace BansheeEngine
 		static const CM::String& getGUITypeName();
 
 		static GUIInputBox* create(GUIWidget& parent, bool multiline = false, const GUIElementStyle* style = nullptr);
-		static GUIInputBox* create(GUIWidget& parent, const GUIOptions& layoutOptions, bool multiline = false, const GUIElementStyle* style = nullptr);
+		static GUIInputBox* create(GUIWidget& parent, bool multiline, const GUIOptions& layoutOptions, const GUIElementStyle* style = nullptr);
+		static GUIInputBox* create(GUIWidget& parent, const GUIOptions& layoutOptions, const GUIElementStyle* style = nullptr);
 
 		const CM::WString& getText() const { return mText; }
+		void setText(const CM::WString& text);
 	protected:
 		~GUIInputBox();
 

+ 32 - 1
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -67,7 +67,7 @@ namespace BansheeEngine
 		return new (cm_alloc<GUIInputBox, PoolAlloc>()) GUIInputBox(parent, style, GUILayoutOptions::create(style), multiline);
 	}
 
-	GUIInputBox* GUIInputBox::create(GUIWidget& parent, const GUIOptions& layoutOptions, bool multiline, const GUIElementStyle* style)
+	GUIInputBox* GUIInputBox::create(GUIWidget& parent, bool multiline, const GUIOptions& layoutOptions, const GUIElementStyle* style)
 	{
 		if(style == nullptr)
 		{
@@ -78,6 +78,37 @@ namespace BansheeEngine
 		return new (cm_alloc<GUIInputBox, PoolAlloc>()) GUIInputBox(parent, style, GUILayoutOptions::create(layoutOptions, style), multiline);
 	}
 
+	GUIInputBox* GUIInputBox::create(GUIWidget& parent, const GUIOptions& layoutOptions, const GUIElementStyle* style)
+	{
+		if(style == nullptr)
+		{
+			const GUISkin& skin = parent.getSkin();
+			style = skin.getStyle(getGUITypeName());
+		}
+
+		return new (cm_alloc<GUIInputBox, PoolAlloc>()) GUIInputBox(parent, style, GUILayoutOptions::create(layoutOptions, style), false);
+	}
+
+	void GUIInputBox::setText(const CM::WString& text)
+	{
+		mText = text;
+
+		TEXT_SPRITE_DESC textDesc = getTextDesc();
+		Vector2I offset = getTextOffset();
+
+		gGUIManager().getInputCaretTool()->updateText(this, textDesc);
+		gGUIManager().getInputSelectionTool()->updateText(this, textDesc);
+
+		if(mText.size() > 0)
+			gGUIManager().getInputCaretTool()->moveCaretToChar((UINT32)mText.size() - 1, CARET_AFTER);
+		else
+			gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
+
+		scrollTextToCaret();
+
+		markContentAsDirty();
+	}
+
 	UINT32 GUIInputBox::getNumRenderElements() const
 	{
 		UINT32 numElements = mImageSprite->getNumRenderElements();

+ 1 - 0
BansheeEngine/Source/BsGUIManager.cpp

@@ -441,6 +441,7 @@ namespace BansheeEngine
 				{
 					foundGroup->bounds.encapsulate(tfrmedBounds);
 					foundGroup->elements.push_back(GUIGroupElement(guiElem, renderElemIdx));
+					foundGroup->depth = std::min(foundGroup->depth, elemDepth);
 					foundGroup->numQuads += guiElem->getNumQuads(renderElemIdx);
 				}
 			}

+ 2 - 2
CamelotClient/Source/BsEditorApplication.cpp

@@ -217,8 +217,8 @@ namespace BansheeEditor
 
 		gApplication().mainLoopCallback.connect(boost::bind(&EditorApplication::update, this));
 
-		DbgEditorWidget1::open(); // DEBUG ONLY
-		DbgEditorWidget2::open(); // DEBUG ONLY
+		//DbgEditorWidget1::open(); // DEBUG ONLY
+		//DbgEditorWidget2::open(); // DEBUG ONLY
 
 		gBansheeApp().runMainLoop();
 

+ 3 - 3
CamelotClient/Source/DbgEditorWidget1.cpp

@@ -55,9 +55,9 @@ namespace BansheeEditor
 		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test K"));
 		//scrollLayout.addElement(GUIButton::create(*mGUI, L"Test L"));
 
-		scrollLayout.addElement(GUIInputBox::create(getParentWidget(), GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100)), true));
-		scrollLayout.addElement(GUIInputBox::create(getParentWidget(), GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100)), true));
-		scrollLayout.addElement(GUIInputBox::create(getParentWidget(), GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100)), true));
+		scrollLayout.addElement(GUIInputBox::create(getParentWidget(), true, GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100))));
+		scrollLayout.addElement(GUIInputBox::create(getParentWidget(), true, GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100))));
+		scrollLayout.addElement(GUIInputBox::create(getParentWidget(), true, GUIOptions(GUIOption::fixedWidth(100), GUIOption::fixedHeight(100))));
 
 		//GUIFlexibleSpace& space4 = otherLayout.addFlexibleSpace();
 		//otherLayout.addElement(mDbgLabel);

+ 8 - 3
MBansheeEditor/ProjectSelectWindow.cs

@@ -9,19 +9,24 @@ namespace BansheeEditor
 {
     internal sealed class ProjectSelectWindow : ModalWindow
     {
+        private GUITextBox textBox;
+
         public ProjectSelectWindow()
             :base(0, 0, 200, 200)
         {
-            GUILabel label = GUI.main.AddLabel("Test test");
-            label.SetContent("Test2");
+            //GUILabel label = GUI.main.AddLabel("Test test");
+            //label.SetContent("Test2");
 
             GUIButton button = GUI.main.AddButton("CLICK ME");
             button.OnClick += button_OnClick;
+
+            textBox = GUI.main.AddTextBox(true, GUIOption.FixedHeight(100), GUIOption.FixedWidth(100));
+            textBox.text = "Supsup?";
         }
 
         void button_OnClick()
         {
-            throw new NotImplementedException();
+            textBox.text = "CLICKED!";
         }
     }
 }

+ 11 - 11
MBansheeEngine/GUIContent.cs

@@ -4,12 +4,12 @@ namespace BansheeEngine
 {
     public sealed class GUIContent
     {
-		public GUIContent(HString text)
+		public GUIContent(LocString text)
 		{
 		    _text = text;
 		}
 
-        public GUIContent(HString text, HString tooltip)
+        public GUIContent(LocString text, LocString tooltip)
         {
             _text = text;
             _tooltip = tooltip;
@@ -20,36 +20,36 @@ namespace BansheeEngine
             _image = image;
         }
 
-        public GUIContent(SpriteTexture image, HString tooltip)
+        public GUIContent(SpriteTexture image, LocString tooltip)
         {
             _image = image;
             _tooltip = tooltip;
         }
 
-        public GUIContent(HString text, SpriteTexture image)
+        public GUIContent(LocString text, SpriteTexture image)
         {
             _text = text;
             _image = image;
         }
 
-        public GUIContent(HString text, SpriteTexture image, HString tooltip)
+        public GUIContent(LocString text, SpriteTexture image, LocString tooltip)
         {
             _text = text;
             _image = image;
             _tooltip = tooltip;
         }
 
-        public static implicit operator GUIContent(HString text)
+        public static implicit operator GUIContent(LocString text)
         {
             return new GUIContent(text);
         }
 
         public static implicit operator GUIContent(string text)
         {
-            return new GUIContent(new HString(text));
+            return new GUIContent(new LocString(text));
         }
 
-        public HString text
+        public LocString text
         {
             get { return _text; }
         }
@@ -59,13 +59,13 @@ namespace BansheeEngine
             get { return _image; }
         }
 
-        public HString getTooltip
+        public LocString getTooltip
         {
             get { return _tooltip; }
         }
 
-        private HString _text;
-        private HString _tooltip;
+        private LocString _text;
+        private LocString _tooltip;
         private SpriteTexture _image;
     }
 }

+ 20 - 0
MBansheeEngine/GUILayout.cs

@@ -50,6 +50,26 @@ namespace BansheeEngine
             return new GUITexture(this, texture, GUIImageScaleMode.StretchToFit, null, options);
         }
 
+        public GUITextBox AddTextBox(bool multiline, GUIElementStyle style, params GUIOption[] options)
+        {
+            return new GUITextBox(this, multiline, style, options);
+        }
+
+        public GUITextBox AddTextBox(bool multiline, params GUIOption[] options)
+        {
+            return new GUITextBox(this, multiline, null, options);
+        }
+
+        public GUITextBox AddTextBox(GUIElementStyle style, params GUIOption[] options)
+        {
+            return new GUITextBox(this, false, style, options);
+        }
+
+        public GUITextBox AddTextBox(params GUIOption[] options)
+        {
+            return new GUITextBox(this, false, null, options);
+        }
+
         public GUIFixedSpace AddSpace(int size)
         {
             return new GUIFixedSpace(this, size);

+ 28 - 0
MBansheeEngine/GUITextBox.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    public sealed class GUITextBox : ScriptObject
+    {
+        internal GUITextBox(GUILayout parentLayout, bool multiline, GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, parentLayout, multiline, style, options);
+        }
+
+        public string text
+        {
+            get { string value; Internal_GetText(mCachedPtr, out value); return value; }
+            set { Internal_SetText(mCachedPtr, value); }
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(GUITextBox instance, GUILayout layout, bool multiline, GUIElementStyle style, GUIOption[] options);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetText(IntPtr nativeInstance, string text);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_GetText(IntPtr nativeInstance, out string text);
+    }
+}

+ 6 - 6
MBansheeEngine/HString.cs → MBansheeEngine/LocString.cs

@@ -3,19 +3,19 @@ using System.Runtime.CompilerServices;
 
 namespace BansheeEngine
 {
-    public sealed class HString : ScriptObject
+    public sealed class LocString : ScriptObject
     {
-        public HString(string identifier)
+        public LocString(string identifier)
         {
             Internal_CreateInstance(this, identifier);
         }
 
-        public static implicit operator HString(string identifier)
+        public static implicit operator LocString(string identifier)
         {
-            return new HString(identifier);
+            return new LocString(identifier);
         }
 
-        public static implicit operator string(HString text)
+        public static implicit operator string(LocString text)
         {
             string value;
             Internal_GetValue(text.mCachedPtr, out value);
@@ -28,7 +28,7 @@ namespace BansheeEngine
         }
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_CreateInstance(HString instance, string identifier);
+        private static extern void Internal_CreateInstance(LocString instance, string identifier);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetParameter(IntPtr nativeInstance, int idx, string identifier);

+ 2 - 1
MBansheeEngine/MBansheeEngine.csproj

@@ -52,6 +52,7 @@
     <Compile Include="GUIContent.cs" />
     <Compile Include="GUIElementStateStyle.cs" />
     <Compile Include="GUIElementStyle.cs" />
+    <Compile Include="GUITextBox.cs" />
     <Compile Include="GUILabel.cs" />
     <Compile Include="GUILayout.cs" />
     <Compile Include="GUILayoutX.cs" />
@@ -61,7 +62,7 @@
     <Compile Include="GUISpace.cs" />
     <Compile Include="GUITexture.cs" />
     <Compile Include="GUIWidget.cs" />
-    <Compile Include="HString.cs" />
+    <Compile Include="LocString.cs" />
     <Compile Include="MathEx.cs" />
     <Compile Include="Matrix3.cs" />
     <Compile Include="Matrix4.cs" />

+ 1 - 0
SBansheeEditor/Source/BsScriptEditorGUI.cpp

@@ -39,6 +39,7 @@ namespace BansheeEditor
 		HSceneObject sceneObj = nativeParentWindow->getSceneObject();
 		HGUIWidget widget = sceneObj->addComponent<GUIWidget>(nativeParentWindow->getCamera()->getViewport().get());
 		widget->setSkin(EngineGUI::instance().getSkin());
+		widget->setDepth(128);
 
 		ScriptEditorGUI* nativeInstance = new (cm_alloc<ScriptEditorGUI>()) ScriptEditorGUI(*widget.get(), nativeParentWindow);
 		nativeInstance->createInstance(instance);

+ 30 - 0
SBansheeEngine/Include/BsScriptGUIInputBox.h

@@ -0,0 +1,30 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsGUITexture.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptGUIInputBox : public ScriptObject<ScriptGUIInputBox>
+	{
+	public:
+		static void initMetaData();
+
+		GUIInputBox* getInternalValue() const { return mInputBox; }
+		void* getNativeRaw() const { return mInputBox; }
+
+	private:
+		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, bool multiline, MonoObject* style, MonoArray* guiOptions);
+		static void internal_destroyInstance(ScriptGUIInputBox* nativeInstance);
+
+		static void internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text);
+		static void internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text);
+
+		static void initRuntimeData();
+
+		ScriptGUIInputBox(GUIInputBox* inputBox);
+
+		GUIInputBox* mInputBox;
+	};
+}

+ 2 - 0
SBansheeEngine/SBansheeEngine.vcxproj

@@ -235,6 +235,7 @@
     <ClInclude Include="Include\BsScriptGUIBase.h" />
     <ClInclude Include="Include\BsScriptGUIElementStateStyle.h" />
     <ClInclude Include="Include\BsScriptGUIElementStyle.h" />
+    <ClInclude Include="Include\BsScriptGUIInputBox.h" />
     <ClInclude Include="Include\BsScriptGUILabel.h" />
     <ClInclude Include="Include\BsScriptGUILayout.h" />
     <ClInclude Include="Include\BsScriptGUITexture.h" />
@@ -260,6 +261,7 @@
     <ClCompile Include="Source\BsScriptGUILayout.cpp" />
     <ClCompile Include="Source\BsScriptGUITexture.cpp" />
     <ClCompile Include="Source\BsScriptHString.cpp" />
+    <ClCompile Include="Source\BsScriptGUIInputBox.cpp" />
     <ClCompile Include="Source\BsScriptSpriteTexture.cpp" />
     <ClCompile Include="Source\BsScriptStringTable.cpp" />
     <ClCompile Include="Source\BsScriptTexture2D.cpp" />

+ 6 - 0
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -72,6 +72,9 @@
     <ClInclude Include="Include\BsScriptGUITexture.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIInputBox.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -125,5 +128,8 @@
     <ClCompile Include="Source\BsScriptGUIButton.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIInputBox.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 82 - 0
SBansheeEngine/Source/BsScriptGUIInputBox.cpp

@@ -0,0 +1,82 @@
+#include "BsScriptGUIInputBox.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsSpriteTexture.h"
+#include "BsMonoUtil.h"
+#include "BsGUILayout.h"
+#include "BsGUIInputBox.h"
+#include "BsGUIOptions.h"
+#include "BsScriptSpriteTexture.h"
+#include "BsScriptGUIElementStyle.h"
+#include "BsScriptGUILayout.h"
+#include "BsScriptGUIArea.h"
+#include "BsScriptHString.h"
+#include "BsScriptGUIContent.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	ScriptGUIInputBox::ScriptGUIInputBox(GUIInputBox* inputBox)
+		:mInputBox(inputBox)
+	{
+
+	}
+
+	void ScriptGUIInputBox::initMetaData()
+	{
+		metaData = ScriptMeta("MBansheeEngine", "BansheeEngine", "GUITextBox", &ScriptGUIInputBox::initRuntimeData);
+
+		MonoManager::registerScriptType(&metaData);
+	}
+
+	void ScriptGUIInputBox::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIInputBox::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIInputBox::internal_destroyInstance);
+		metaData.scriptClass->addInternalCall("Internal_GetText", &ScriptGUIInputBox::internal_getText);
+		metaData.scriptClass->addInternalCall("Internal_SetText", &ScriptGUIInputBox::internal_setText);
+	}
+
+	void ScriptGUIInputBox::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, bool multiline, MonoObject* style, MonoArray* guiOptions)
+	{
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+		GUIOptions options;
+
+		UINT32 arrayLen = (UINT32)mono_array_length(guiOptions);
+		for(UINT32 i = 0; i < arrayLen; i++)
+			options.addOption(mono_array_get(guiOptions, GUIOption, i));
+
+		GUIElementStyle* elemStyle = nullptr;
+
+		if(style != nullptr)
+			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
+
+		GUIInputBox* guiInputBox = GUIInputBox::create(scriptLayout->getParentArea()->getParentWidget(), multiline, options, elemStyle);
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(guiInputBox);
+
+		ScriptGUIInputBox* nativeInstance = new (cm_alloc<ScriptGUIInputBox>()) ScriptGUIInputBox(guiInputBox);
+		nativeInstance->createInstance(instance);
+
+		metaData.thisPtrField->setValue(instance, nativeInstance);
+	}
+
+	void ScriptGUIInputBox::internal_destroyInstance(ScriptGUIInputBox* nativeInstance)
+	{
+		nativeInstance->destroyInstance();
+		cm_delete(nativeInstance);
+	}
+
+	void ScriptGUIInputBox::internal_getText(ScriptGUIInputBox* nativeInstance, MonoString** text)
+	{
+		*text = MonoUtil::wstringToMono(MonoManager::instance().getDomain(), nativeInstance->getInternalValue()->getText());
+	}
+
+	void ScriptGUIInputBox::internal_setText(ScriptGUIInputBox* nativeInstance, MonoString* text)
+	{
+		nativeInstance->getInternalValue()->setText(MonoUtil::monoToWString(text));
+	}
+}

+ 1 - 1
SBansheeEngine/Source/BsScriptHString.cpp

@@ -15,7 +15,7 @@ namespace BansheeEngine
 
 	void ScriptHString::initMetaData()
 	{
-		metaData = ScriptMeta("MBansheeEngine", "BansheeEngine", "HString", &ScriptHString::initRuntimeData);
+		metaData = ScriptMeta("MBansheeEngine", "BansheeEngine", "LocString", &ScriptHString::initRuntimeData);
 
 		MonoManager::registerScriptType(&metaData);
 	}