Browse Source

Added Foldout GUI component

Marko Pintera 11 years ago
parent
commit
9f2663102e

+ 2 - 0
BansheeEditor/BansheeEditor.vcxproj

@@ -278,6 +278,7 @@
     <ClInclude Include="Include\BsGUIColor.h" />
     <ClInclude Include="Include\BsGUIColorField.h" />
     <ClInclude Include="Include\BsGUIFloatField.h" />
+    <ClInclude Include="Include\BsGUIFoldout.h" />
     <ClInclude Include="Include\BsGUIIntField.h" />
     <ClInclude Include="Include\BsGUITextField.h" />
     <ClInclude Include="Include\BsGUIToggleField.h" />
@@ -331,6 +332,7 @@
     <ClCompile Include="Source\BsGUIColorField.cpp" />
     <ClCompile Include="Source\BsGUIDockSlider.cpp" />
     <ClCompile Include="Source\BsGUIFloatField.cpp" />
+    <ClCompile Include="Source\BsGUIFoldout.cpp" />
     <ClCompile Include="Source\BsGUIIntField.cpp" />
     <ClCompile Include="Source\BsGUIMenuBar.cpp" />
     <ClCompile Include="Source\BsGUIResourceTreeView.cpp" />

+ 6 - 0
BansheeEditor/BansheeEditor.vcxproj.filters

@@ -180,6 +180,9 @@
     <ClInclude Include="Include\BsGUIColorField.h">
       <Filter>Header Files\Editor</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUIFoldout.h">
+      <Filter>Header Files\Editor</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsEditorWidgetContainer.cpp">
@@ -311,5 +314,8 @@
     <ClCompile Include="Source\BsGUIColorField.cpp">
       <Filter>Source Files\Editor</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGUIFoldout.cpp">
+      <Filter>Source Files\Editor</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 6 - 0
BansheeEditor/Include/BsEditorGUI.h

@@ -50,6 +50,12 @@ namespace BansheeEditor
 		static const CM::WString ToggleHoverOnTex;
 		static const CM::WString ToggleActiveOnTex;
 
+		static const CM::WString FoldoutOpenNormalTex;
+		static const CM::WString FoldoutOpenHoverTex;
+		static const CM::WString FoldoutClosedNormalTex;
+		static const CM::WString FoldoutClosedHoverTex;
+		static const CM::WString FoldoutBackgroundTex;
+
 		static const CM::WString InputBoxNormalTex;
 		static const CM::WString InputBoxHoverTex;
 		static const CM::WString InputBoxFocusedTex;

+ 42 - 0
BansheeEditor/Include/BsGUIFoldout.h

@@ -0,0 +1,42 @@
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsGUIElementContainer.h"
+
+namespace BansheeEditor
+{
+	class BS_ED_EXPORT GUIFoldout : public BS::GUIElementContainer
+	{
+		struct PrivatelyConstruct {};
+
+	public:
+		static const CM::String& getGUITypeName();
+
+		static GUIFoldout* create(BS::GUIWidget& parent, const BS::GUIOptions& layoutOptions, 
+			BS::GUIElementStyle* buttonStyle = nullptr, BS::GUIElementStyle* backgroundStyle = nullptr);
+
+		static GUIFoldout* create(BS::GUIWidget& parent, BS::GUIElementStyle* labelStyle = nullptr,
+			BS::GUIElementStyle* backgroundStyle = nullptr);
+
+		GUIFoldout(const PrivatelyConstruct& dummy, BS::GUIWidget& parent, BS::GUIElementStyle* buttonStyle, 
+			BS::GUIElementStyle* backgroundStyle, const BS::GUILayoutOptions& layoutOptions);
+
+		bool isExpanded() const { return mIsExpanded; }
+		void setExpanded(bool expanded);
+
+		void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
+			CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
+
+		CM::Vector2I _getOptimalSize() const;
+
+		boost::signal<void(bool)> onStateChanged;
+	protected:
+		virtual ~GUIFoldout();
+
+	protected:
+		BS::GUIToggle* mToggle;
+		BS::GUITexture* mBackground;
+
+		bool mIsExpanded;
+	};
+}

+ 26 - 0
BansheeEditor/Source/BsEditorGUI.cpp

@@ -38,6 +38,12 @@ namespace BansheeEditor
 	const WString EditorGUI::ToggleHoverOnTex = L"ToggleOnHover.psd";
 	const WString EditorGUI::ToggleActiveOnTex = L"ToggleOnActive.psd";
 
+	const WString EditorGUI::FoldoutOpenNormalTex = L"FoldoutOpenNormal.psd";
+	const WString EditorGUI::FoldoutOpenHoverTex = L"FoldoutOpenHover.psd";
+	const WString EditorGUI::FoldoutClosedNormalTex = L"FoldoutClosedNormal.psd";
+	const WString EditorGUI::FoldoutClosedHoverTex = L"FoldoutClosedHover.psd";
+	const WString EditorGUI::FoldoutBackgroundTex = L"FoldoutBackground.psd";
+
 	const WString EditorGUI::WindowFrameNormal = L"WindowFrameNormal.psd";
 	const WString EditorGUI::WindowFrameFocused = L"WindowFrameFocused.psd";
 
@@ -326,6 +332,26 @@ namespace BansheeEditor
 
 		mSkin.setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
 
+		// Foldout
+		GUIElementStyle foldoutBtnStyle;
+		foldoutBtnStyle.normal.texture = getTexture(FoldoutClosedNormalTex);
+		foldoutBtnStyle.hover.texture = getTexture(FoldoutClosedHoverTex);
+		foldoutBtnStyle.active.texture = foldoutBtnStyle.hover.texture;
+		foldoutBtnStyle.normalOn.texture = getTexture(FoldoutOpenNormalTex);
+		foldoutBtnStyle.hoverOn.texture = getTexture(FoldoutOpenHoverTex);
+		foldoutBtnStyle.activeOn.texture = foldoutBtnStyle.hoverOn.texture;
+		foldoutBtnStyle.fixedHeight = true;
+		foldoutBtnStyle.fixedWidth = true;
+		foldoutBtnStyle.height = 8;
+		foldoutBtnStyle.width = 8;
+
+		mSkin.setStyle("FoldoutButton", foldoutBtnStyle);
+
+		GUIElementStyle foldoutBackgroundStyle;
+		foldoutBackgroundStyle.normal.texture = getTexture(FoldoutBackgroundTex);
+
+		mSkin.setStyle("FoldoutBackground", foldoutBackgroundStyle);
+
 		/************************************************************************/
 		/* 								SCROLL BAR                      		*/
 		/************************************************************************/

+ 122 - 0
BansheeEditor/Source/BsGUIFoldout.cpp

@@ -0,0 +1,122 @@
+#include "BsGUIFoldout.h"
+#include "BsGUIArea.h"
+#include "BsGUILayout.h"
+#include "BsGUIToggle.h"
+#include "BsGUITexture.h"
+#include "BsBuiltinResources.h"
+#include "BsGUIWidget.h"
+#include "BsGUIMouseEvent.h"
+#include "BsGUIWidget.h"
+
+using namespace CamelotFramework;
+using namespace BansheeEngine;
+
+namespace BansheeEditor
+{
+	GUIFoldout::GUIFoldout(const PrivatelyConstruct& dummy, GUIWidget& parent, BS::GUIElementStyle* buttonStyle, 
+		BS::GUIElementStyle* backgroundStyle, const BS::GUILayoutOptions& layoutOptions)
+		:GUIElementContainer(parent, layoutOptions), mToggle(nullptr), mBackground(nullptr), mIsExpanded(false)
+	{
+		const GUIElementStyle* curButtonStyle = buttonStyle;
+		const GUIElementStyle* curBackgroundStyle = backgroundStyle;
+
+		if(curButtonStyle == nullptr)
+			curButtonStyle = parent.getSkin().getStyle("FoldoutButton");
+
+		if(curBackgroundStyle == nullptr)
+			curBackgroundStyle = parent.getSkin().getStyle("FoldoutBackground");
+
+		mToggle = GUIToggle::create(parent, HString(L""), curButtonStyle);
+		mBackground = GUITexture::create(parent, curBackgroundStyle);
+
+		_registerChildElement(mToggle);
+		_registerChildElement(mBackground);
+	}
+
+	GUIFoldout::~GUIFoldout()
+	{
+
+	}
+
+	GUIFoldout* GUIFoldout::create(GUIWidget& parent, const GUIOptions& layoutOptions, 
+		GUIElementStyle* buttonStyle, GUIElementStyle* backgroundStyle)
+	{
+		return cm_new<GUIFoldout>(PrivatelyConstruct(), parent, buttonStyle, backgroundStyle, 
+			GUILayoutOptions::create(layoutOptions, &GUISkin::DefaultStyle));
+	}
+
+	GUIFoldout* GUIFoldout::create(GUIWidget& parent, GUIElementStyle* buttonStyle, 
+		GUIElementStyle* backgroundStyle)
+	{
+		return cm_new<GUIFoldout>(PrivatelyConstruct(), parent, buttonStyle, backgroundStyle, 
+			GUILayoutOptions::create(&GUISkin::DefaultStyle));
+	}
+
+	void GUIFoldout::setExpanded(bool expanded)
+	{
+		if(mIsExpanded != expanded)
+		{
+			mIsExpanded = expanded;
+
+			if(mIsExpanded)
+				mToggle->toggleOn();
+			else
+				mToggle->toggleOff();
+
+			markContentAsDirty();
+
+			if(!onStateChanged.empty())
+				onStateChanged(mIsExpanded);
+		}
+	}
+
+	void GUIFoldout::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
+		RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
+	{
+		{
+			Vector2I optimalSize = mToggle->_getOptimalSize();
+			INT32 yOffset = Math::roundToInt((height - optimalSize.y) * 0.5f);
+
+			Vector2I offset(x, y + yOffset);
+			mToggle->_setOffset(offset);
+			mToggle->_setWidth(optimalSize.x);
+			mToggle->_setHeight(optimalSize.y);
+			mToggle->_setAreaDepth(areaDepth);
+			mToggle->_setWidgetDepth(widgetDepth);
+
+			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
+			mToggle->_setClipRect(elemClipRect);
+		}
+
+		{
+			Vector2I offset(x, y);
+			mBackground->_setOffset(offset);
+			mBackground->_setWidth(mWidth);
+			mBackground->_setHeight(mHeight);
+			mBackground->_setAreaDepth(areaDepth + 1);
+			mBackground->_setWidgetDepth(widgetDepth);
+
+			RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
+			mBackground->_setClipRect(elemClipRect);
+		}
+	}
+
+	Vector2I GUIFoldout::_getOptimalSize() const
+	{
+		Vector2I optimalsize = mToggle->_getOptimalSize();
+
+		if(mBackground != nullptr)
+		{
+			optimalsize.x = std::max(optimalsize.x, mBackground->_getOptimalSize().x);
+			optimalsize.y = std::max(optimalsize.y, mBackground->_getOptimalSize().y);
+		}
+
+		return optimalsize;
+	}
+
+	const String& GUIFoldout::getGUITypeName()
+	{
+		static String typeName = "GUIFoldout";
+		return typeName;
+	}
+}

+ 3 - 0
BansheeEditor/Source/DbgEditorWidget2.cpp

@@ -14,6 +14,7 @@
 #include "BsGUIVector4Field.h"
 #include "BsGUIToggleField.h"
 #include "BsGUIColorField.h"
+#include "BsGUIFoldout.h"
 #include "BsGUISpace.h"
 #include "CmHString.h"
 
@@ -37,6 +38,7 @@ namespace BansheeEditor
 		GUIVector2Field* vec2Field = GUIVector2Field::create(getParentWidget(), HString(L"Vec2 Field"), GUIOptions(GUIOption::fixedWidth(200)));
 		GUIToggleField* toggleField = GUIToggleField::create(getParentWidget(), HString(L"Toggle Field"), GUIOptions(GUIOption::fixedWidth(200)));
 		GUIColorField* colorField = GUIColorField::create(getParentWidget(), HString(L"Color Field"), GUIOptions(GUIOption::fixedWidth(200)));
+		GUIFoldout* foldout = GUIFoldout::create(getParentWidget(), GUIOptions(GUIOption::fixedWidth(200)));
 		colorField->setValue(Color::Red);
 
 		layout.addElement(intField);
@@ -47,6 +49,7 @@ namespace BansheeEditor
 		layout.addElement(vec2Field);
 		layout.addElement(toggleField);
 		layout.addElement(colorField);
+		layout.addElement(foldout);
 
 		layout.addFlexibleSpace();
 	}

+ 1 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -247,6 +247,7 @@
     <ClInclude Include="Include\BsGUIDropDownBoxManager.h" />
     <ClInclude Include="Include\BsGUIDropDownHitBox.h" />
     <ClInclude Include="Include\BsGUIElementContainer.h" />
+    <ClInclude Include="Include\BsGUIFoldout.h" />
     <ClInclude Include="Include\BsGUIHelper.h" />
     <ClInclude Include="Include\BsGUIListBox.h" />
     <ClInclude Include="Include\BsGUIElementBase.h" />

+ 3 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -267,6 +267,9 @@
     <ClInclude Include="Include\BsBuiltinResources.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUIFoldout.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">

+ 56 - 0
BansheeEngine/Include/BsGUIFoldout.h

@@ -0,0 +1,56 @@
+#pragma once
+
+#include "BsEditorPrerequisites.h"
+#include "BsGUIElementContainer.h"
+
+namespace BansheeEditor
+{
+	class BS_ED_EXPORT GUIColorField : public BS::GUIElementContainer
+	{
+		struct PrivatelyConstruct {};
+
+	public:
+		static const CM::String& getGUITypeName();
+
+		static GUIColorField* create(BS::GUIWidget& parent, const BS::GUIContent& labelContent, 
+			const BS::GUIOptions& layoutOptions, BS::GUIElementStyle* labelStyle = nullptr, BS::GUIElementStyle* toggleStyle = nullptr);
+
+		static GUIColorField* create(BS::GUIWidget& parent, const CM::HString& labelText, 
+			const BS::GUIOptions& layoutOptions, BS::GUIElementStyle* labelStyle = nullptr, BS::GUIElementStyle* toggleStyle = nullptr);
+
+		static GUIColorField* create(BS::GUIWidget& parent, 
+			const BS::GUIOptions& layoutOptions, BS::GUIElementStyle* labelStyle = nullptr, BS::GUIElementStyle* toggleStyle = nullptr);
+
+		static GUIColorField* create(BS::GUIWidget& parent, const BS::GUIContent& labelContent, 
+			BS::GUIElementStyle* labelStyle = nullptr, BS::GUIElementStyle* toggleStyle = nullptr);
+
+		static GUIColorField* create(BS::GUIWidget& parent, const CM::HString& labelText, 
+			BS::GUIElementStyle* labelStyle = nullptr, BS::GUIElementStyle* toggleStyle = nullptr);
+
+		static GUIColorField* create(BS::GUIWidget& parent, 
+			BS::GUIElementStyle* labelStyle = nullptr, BS::GUIElementStyle* toggleStyle = nullptr);
+
+		GUIColorField(const PrivatelyConstruct& dummy, BS::GUIWidget& parent, const BS::GUIContent& labelContent, 
+			BS::GUIElementStyle* labelStyle, BS::GUIElementStyle* toggleStyle, const BS::GUILayoutOptions& layoutOptions);
+
+		GUIColorField(const PrivatelyConstruct& dummy, BS::GUIWidget& parent, 
+			BS::GUIElementStyle* labelStyle, BS::GUIElementStyle* toggleStyle, const BS::GUILayoutOptions& layoutOptions);
+
+		CM::Color getValue() const;
+		void setValue(const CM::Color& value);
+
+		void setLabelWidth(CM::UINT32 width);
+
+		void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
+			CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
+
+		CM::Vector2I _getOptimalSize() const;
+	protected:
+		virtual ~GUIColorField();
+
+	protected:
+		CM::UINT32 mLabelWidth;
+		BS::GUILabel* mLabel;
+		GUIColor* mColor;
+	};
+}

+ 1 - 1
BansheeEngine/Source/BsGUIButtonBase.cpp

@@ -147,7 +147,7 @@ namespace BansheeEngine
 	{
 		UINT32 imageWidth = 0;
 		UINT32 imageHeight = 0;
-		if(mActiveTexture != nullptr)
+		if(mActiveTexture != nullptr && mActiveTexture.isLoaded())
 		{
 			imageWidth = mActiveTexture->getTexture()->getWidth();
 			imageHeight = mActiveTexture->getTexture()->getHeight();

+ 3 - 8
Inspector.txt

@@ -1,6 +1,4 @@
 Needed controls:
-Toggle field
-Color field
 Array field/List field/Dictionary field
 Matrix3 field
 Matrix4 field
@@ -34,13 +32,10 @@ Layouts/Areas/Elements need SetVisible(true/false) toggle
 
 -------------
 Implementation order:
-
-Today:
- - Ensure color and toggle compile correctly
- - Add normal toggle icon (I think I already have the graphic)
  - Component foldout
-
-Then:
+ - Color picker modular window
+   - Possibly a generic ModularWindow class
+   - EditorUtility::showColorPicker
  - GameObject/resource field
  - Matrix fields
  - Refactor C# GUI