Browse Source

Added a C# GUIList

Marko Pintera 12 years ago
parent
commit
7c0f789e39

+ 2 - 0
BansheeEngine/Include/BsGUIListBox.h

@@ -16,6 +16,8 @@ namespace BansheeEngine
 		static GUIListBox* create(GUIWidget& parent, const CM::Vector<CM::HString>::type& elements, const GUIElementStyle* style = nullptr);
 		static GUIListBox* create(GUIWidget& parent, const CM::Vector<CM::HString>::type& elements, const GUIOptions& layoutOptions, const GUIElementStyle* style = nullptr);
 
+		void setElements(const CM::Vector<CM::HString>::type& elements);
+
 		boost::signal<void(CM::UINT32)> onSelectionChanged;
 	protected:
 		~GUIListBox();

+ 17 - 0
BansheeEngine/Source/BsGUIListBox.cpp

@@ -55,6 +55,23 @@ namespace BansheeEngine
 		return new (cm_alloc<GUIListBox, PoolAlloc>()) GUIListBox(parent, style, elements, GUILayoutOptions::create(layoutOptions, style));
 	}
 
+	void GUIListBox::setElements(const CM::Vector<CM::HString>::type& elements)
+	{
+		bool wasOpen = mIsListBoxOpen;
+
+		if(mIsListBoxOpen)
+			closeListBox();
+
+		mElements = elements;
+		mSelectedIdx = 0;
+
+		if(elements.size() > 0)
+			setContent(GUIContent(mElements[mSelectedIdx]));
+
+		if(wasOpen)
+			openListBox();
+	}
+
 	bool GUIListBox::mouseEvent(const GUIMouseEvent& ev)
 	{
 		bool processed = GUIButtonBase::mouseEvent(ev);

+ 6 - 5
CSharpWrap.txt

@@ -95,15 +95,16 @@ Implement:
  - GUIListBox
   - onSelectionChanged
 
- - GUIScrollArea
-
- - GUIRenderTexture
-  - RenderTexture (?)
-
  - GUIToggle
   - onToggled
   - ToggleGroup (?)
 
+ScrollArea will likely need:
+ C#: test it
+ C++/C#: always/never show horz/vert scroll bar
+ C++/C#: optional styles for scroll bars
+ C++/C#: scrollTo(pct)
+
  - Destroy()
  - GUISkin
    - List of properties with all common styles, like .button, .label

+ 1 - 0
CamelotClient/Include/CmTestTextSprite.h

@@ -18,6 +18,7 @@ namespace CamelotFramework
 
 	private:
 		BS::GUILabel* mLabel;
+		BS::GUIListBox* mListBox;
 		HString labelString;
 
 		void dbgBtn();

+ 13 - 5
CamelotClient/Source/CmTestTextSprite.cpp

@@ -30,7 +30,7 @@ using namespace BansheeEngine;
 namespace CamelotFramework
 {
 	TestTextSprite::TestTextSprite(const HSceneObject& parent, CM::Viewport* target)
-		:GUIWidget(parent, target)
+		:GUIWidget(parent, target), mListBox(nullptr)
 	{
 	}
 
@@ -53,7 +53,8 @@ namespace CamelotFramework
 		dropDownElements.push_back(HString(L"Ejlement #1"));
 		dropDownElements.push_back(HString(L"Element #2"));
 		dropDownElements.push_back(HString(L"Element #3"));
-		area->getLayout().addElement(GUIListBox::create(*this, dropDownElements, GUIOptions(GUIOption::fixedWidth(50), GUIOption::fixedHeight(13))));
+		mListBox = GUIListBox::create(*this, dropDownElements, GUIOptions(GUIOption::fixedWidth(50), GUIOption::fixedHeight(13)));
+		area->getLayout().addElement(mListBox);
 
 		GUIButton* button = GUIButton::create(*this, HString(L"dbgBtn"));
 		button->onClick.connect(boost::bind(&TestTextSprite::dbgBtn, this));
@@ -77,12 +78,19 @@ namespace CamelotFramework
 
 		if(dbg == 0)
 		{
-			StringTable::instance().setString(L"dbgBtn", Language::Abkhazian, L"ALOALO");
-			StringTable::instance().setActiveLanguage(Language::Abkhazian);
+			Vector<HString>::type dropDownElements;
+			dropDownElements.push_back(HString(L"Element #4"));
+			dropDownElements.push_back(HString(L"Element #5"));
+			dropDownElements.push_back(HString(L"Element #6"));
+
+			mListBox->setElements(dropDownElements);
+
+			//StringTable::instance().setString(L"dbgBtn", Language::Abkhazian, L"ALOALO");
+			//StringTable::instance().setActiveLanguage(Language::Abkhazian);
 		}
 		else if(dbg == 1)
 		{
-			StringTable::instance().removeString(L"dbgBtn");
+			//StringTable::instance().removeString(L"dbgBtn");
 		}
 
 		dbg++;

+ 8 - 1
MBansheeEditor/ProjectSelectWindow.cs

@@ -10,9 +10,10 @@ namespace BansheeEditor
     internal sealed class ProjectSelectWindow : ModalWindow
     {
         private GUITextBox textBox;
+        private GUIListBox listBox;
 
         public ProjectSelectWindow()
-            :base(0, 0, 200, 200)
+            :base(0, 0, 500, 200)
         {
             //GUILabel label = GUI.main.AddLabel("Test test");
             //label.SetContent("Test2");
@@ -22,11 +23,17 @@ namespace BansheeEditor
 
             textBox = GUI.main.AddTextBox(true, GUIOption.FixedHeight(100), GUIOption.FixedWidth(100));
             textBox.text = "Supsup?";
+
+            LocString[] listElems = new LocString[] { "ListElem1", "ListElem2", "ListElem3" };
+            listBox = GUI.main.AddListBox(listElems);
         }
 
         void button_OnClick()
         {
             textBox.text = "CLICKED!";
+
+            LocString[] listElems = new LocString[] { "ListElem4", "ListElem5", "ListElem6" };
+            listBox.SetElements(listElems);
         }
     }
 }

+ 1 - 1
MBansheeEngine/Font.cs

@@ -4,7 +4,7 @@ namespace BansheeEngine
 {
     public sealed class Font : Resource // TODO - Dummy class
     {
-        public Font()
+        internal Font()
         {
             Internal_CreateInstance(this);
         }

+ 10 - 0
MBansheeEngine/GUILayout.cs

@@ -80,6 +80,16 @@ namespace BansheeEngine
             return new GUIScrollArea(this, null, options);
         }
 
+        public GUIListBox AddListBox(LocString[] elements, GUIElementStyle style, params GUIOption[] options)
+        {
+            return new GUIListBox(this, elements, style, options);
+        }
+
+        public GUIListBox AddListBox(LocString[] elements, params GUIOption[] options)
+        {
+            return new GUIListBox(this, elements, null, options);
+        }
+
         public GUIFixedSpace AddSpace(int size)
         {
             return new GUIFixedSpace(this, size);

+ 24 - 0
MBansheeEngine/GUIListBox.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Runtime.CompilerServices;
+
+namespace BansheeEngine
+{
+    public sealed class GUIListBox : ScriptObject
+    {
+        internal GUIListBox(GUILayout parentLayout, LocString[] elements, GUIElementStyle style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, parentLayout, elements, style, options);
+        }
+
+        public void SetElements(LocString[] elements)
+        {
+            Internal_SetElements(mCachedPtr, elements);
+        }
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_CreateInstance(GUIListBox instance, GUILayout parentLayout, LocString[] elements, GUIElementStyle style, params GUIOption[] options);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetElements(IntPtr nativeInstance, LocString[] elements);
+    }
+}

+ 1 - 0
MBansheeEngine/MBansheeEngine.csproj

@@ -52,6 +52,7 @@
     <Compile Include="GUIContent.cs" />
     <Compile Include="GUIElementStateStyle.cs" />
     <Compile Include="GUIElementStyle.cs" />
+    <Compile Include="GUIListBox.cs" />
     <Compile Include="GUIScrollArea.cs" />
     <Compile Include="GUITextBox.cs" />
     <Compile Include="GUILabel.cs" />

+ 29 - 0
SBansheeEngine/Include/BsScriptGUIListBox.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include "BsScriptEnginePrerequisites.h"
+#include "BsScriptObject.h"
+#include "BsGUITexture.h"
+
+namespace BansheeEngine
+{
+	class BS_SCR_BE_EXPORT ScriptGUIListBox : public ScriptObject<ScriptGUIListBox>
+	{
+	public:
+		static void initMetaData();
+
+		GUIListBox* getInternalValue() const { return mListBox; }
+		void* getNativeRaw() const { return mListBox; }
+
+	private:
+		static void internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoArray* elements, MonoObject* style, MonoArray* guiOptions);
+		static void internal_destroyInstance(ScriptGUIListBox* nativeInstance);
+
+		static void internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements);
+
+		static void initRuntimeData();
+
+		ScriptGUIListBox(GUIListBox* listBox);
+
+		GUIListBox* mListBox;
+	};
+}

+ 2 - 0
SBansheeEngine/SBansheeEngine.vcxproj

@@ -238,6 +238,7 @@
     <ClInclude Include="Include\BsScriptGUIInputBox.h" />
     <ClInclude Include="Include\BsScriptGUILabel.h" />
     <ClInclude Include="Include\BsScriptGUILayout.h" />
+    <ClInclude Include="Include\BsScriptGUIListBox.h" />
     <ClInclude Include="Include\BsScriptGUIScrollArea.h" />
     <ClInclude Include="Include\BsScriptGUITexture.h" />
     <ClInclude Include="Include\BsScriptHString.h" />
@@ -260,6 +261,7 @@
     <ClCompile Include="Source\BsScriptGUIElementStyle.cpp" />
     <ClCompile Include="Source\BsScriptGUILabel.cpp" />
     <ClCompile Include="Source\BsScriptGUILayout.cpp" />
+    <ClCompile Include="Source\BsScriptGUIListBox.cpp" />
     <ClCompile Include="Source\BsScriptGUIScrollArea.cpp" />
     <ClCompile Include="Source\BsScriptGUITexture.cpp" />
     <ClCompile Include="Source\BsScriptHString.cpp" />

+ 6 - 0
SBansheeEngine/SBansheeEngine.vcxproj.filters

@@ -78,6 +78,9 @@
     <ClInclude Include="Include\BsScriptGUIScrollArea.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsScriptGUIListBox.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsScriptTexture2D.cpp">
@@ -137,5 +140,8 @@
     <ClCompile Include="Source\BsScriptGUIScrollArea.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsScriptGUIListBox.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 104 - 0
SBansheeEngine/Source/BsScriptGUIListBox.cpp

@@ -0,0 +1,104 @@
+#include "BsScriptGUIListBox.h"
+#include "BsScriptMeta.h"
+#include "BsMonoField.h"
+#include "BsMonoClass.h"
+#include "BsMonoManager.h"
+#include "BsSpriteTexture.h"
+#include "BsMonoUtil.h"
+#include "BsGUILayout.h"
+#include "BsGUIListBox.h"
+#include "BsGUIOptions.h"
+#include "BsScriptGUIElementStyle.h"
+#include "BsScriptGUILayout.h"
+#include "BsScriptGUIArea.h"
+#include "BsScriptHString.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	ScriptGUIListBox::ScriptGUIListBox(GUIListBox* listBox)
+		:mListBox(listBox)
+	{
+
+	}
+
+	void ScriptGUIListBox::initMetaData()
+	{
+		metaData = ScriptMeta("MBansheeEngine", "BansheeEngine", "GUIListBox", &ScriptGUIListBox::initRuntimeData);
+
+		MonoManager::registerScriptType(&metaData);
+	}
+
+	void ScriptGUIListBox::initRuntimeData()
+	{
+		metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIListBox::internal_createInstance);
+		metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIListBox::internal_destroyInstance);
+		metaData.scriptClass->addInternalCall("Internal_SetElements", &ScriptGUIListBox::internal_setElements);
+	}
+
+	void ScriptGUIListBox::internal_createInstance(MonoObject* instance, MonoObject* parentLayout, MonoArray* elements, MonoObject* style, MonoArray* guiOptions)
+	{
+		ScriptGUILayout* scriptLayout = ScriptGUILayout::toNative(parentLayout);
+		GUIOptions options;
+
+		UINT32 optionsArrayLen = (UINT32)mono_array_length(guiOptions);
+		for(UINT32 i = 0; i < optionsArrayLen; i++)
+			options.addOption(mono_array_get(guiOptions, GUIOption, i));
+
+		GUIElementStyle* elemStyle = nullptr;
+
+		if(style != nullptr)
+			elemStyle = ScriptGUIElementStyle::toNative(style)->getInternalValue();
+
+		UINT32 elementsArrayLen = (UINT32)mono_array_length(elements);
+		Vector<HString>::type nativeElements;
+		for(UINT32 i = 0; i < elementsArrayLen; i++)
+		{
+			MonoObject* stringManaged = (MonoObject*)mono_array_get(elements, MonoObject*, i);
+
+			if(stringManaged == nullptr)
+				nativeElements.push_back(HString::dummy());
+			else
+			{
+				ScriptHString* textScript = ScriptHString::toNative(stringManaged);
+				nativeElements.push_back(textScript->getInternalValue());
+			}
+		}
+
+		GUIListBox* guiListBox = GUIListBox::create(scriptLayout->getParentWidget(), nativeElements, options, elemStyle);
+		GUILayout* nativeLayout = scriptLayout->getInternalValue();
+		nativeLayout->addElement(guiListBox);
+
+		ScriptGUIListBox* nativeInstance = new (cm_alloc<ScriptGUIListBox>()) ScriptGUIListBox(guiListBox);
+		nativeInstance->createInstance(instance);
+
+		metaData.thisPtrField->setValue(instance, nativeInstance);
+	}
+
+	void ScriptGUIListBox::internal_destroyInstance(ScriptGUIListBox* nativeInstance)
+	{
+		nativeInstance->destroyInstance();
+		cm_delete(nativeInstance);
+	}
+
+	void ScriptGUIListBox::internal_setElements(ScriptGUIListBox* nativeInstance, MonoArray* elements)
+	{
+		UINT32 elementsArrayLen = (UINT32)mono_array_length(elements);
+		Vector<HString>::type nativeElements;
+		for(UINT32 i = 0; i < elementsArrayLen; i++)
+		{
+			MonoObject* stringManaged = (MonoObject*)mono_array_get(elements, MonoObject*, i);
+
+			if(stringManaged == nullptr)
+				nativeElements.push_back(HString::dummy());
+			else
+			{
+				ScriptHString* textScript = ScriptHString::toNative(stringManaged);
+				nativeElements.push_back(textScript->getInternalValue());
+			}
+		}
+
+		nativeInstance->getInternalValue()->setElements(nativeElements);
+	}
+}