Quellcode durchsuchen

Fixed a few minor issues with the layouts:
- Calculated Offset in X layout was wrong
- Layouts were never being marked as clean and were always updated

Marko Pintera vor 12 Jahren
Ursprung
Commit
6eede6eebd

+ 118 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -248,6 +248,124 @@ namespace BansheeEngine
 		inputBoxStyle.textVertAlign = TVA_Top;
 		inputBoxStyle.textVertAlign = TVA_Top;
 
 
 		mSkin.setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
 		mSkin.setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
+
+		/************************************************************************/
+		/* 								SCROLL BAR                      		*/
+		/************************************************************************/
+
+		// Up button
+		HTexture scrollUpBtnNormal = static_resource_cast<Texture>(Importer::instance().import(ScrollBarUpNormalTex));
+		HTexture scrollUpBtnHover = static_resource_cast<Texture>(Importer::instance().import(ScrollBarUpHoverTex));
+		HTexture scrollUpBtnActive = static_resource_cast<Texture>(Importer::instance().import(ScrollBarUpActiveTex));
+
+		GUIElementStyle scrollUpBtnStyle;
+		scrollUpBtnStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollUpBtnNormal));
+		scrollUpBtnStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollUpBtnHover));
+		scrollUpBtnStyle.active.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollUpBtnActive));
+		scrollUpBtnStyle.fixedHeight = true;
+		scrollUpBtnStyle.fixedWidth = true;
+		scrollUpBtnStyle.height = 4;
+		scrollUpBtnStyle.width = 8;
+
+		mSkin.setStyle("ScrollUpBtn", scrollUpBtnStyle);
+
+		// Down button
+		HTexture scrollDownBtnNormal = static_resource_cast<Texture>(Importer::instance().import(ScrollBarDownNormalTex));
+		HTexture scrollDownBtnHover = static_resource_cast<Texture>(Importer::instance().import(ScrollBarDownHoverTex));
+		HTexture scrollDownBtnActive = static_resource_cast<Texture>(Importer::instance().import(ScrollBarDownActiveTex));
+
+		GUIElementStyle scrollDownBtnStyle;
+		scrollDownBtnStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollDownBtnNormal));
+		scrollDownBtnStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollDownBtnHover));
+		scrollDownBtnStyle.active.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollDownBtnActive));
+		scrollDownBtnStyle.fixedHeight = true;
+		scrollDownBtnStyle.fixedWidth = true;
+		scrollDownBtnStyle.height = 4;
+		scrollDownBtnStyle.width = 8;
+
+		mSkin.setStyle("ScrollDownBtn", scrollDownBtnStyle);
+
+		// Left button
+		HTexture scrollLeftBtnNormal = static_resource_cast<Texture>(Importer::instance().import(ScrollBarLeftNormalTex));
+		HTexture scrollLeftBtnHover = static_resource_cast<Texture>(Importer::instance().import(ScrollBarLeftHoverTex));
+		HTexture scrollLeftBtnActive = static_resource_cast<Texture>(Importer::instance().import(ScrollBarLeftActiveTex));
+
+		GUIElementStyle scrollLeftBtnStyle;
+		scrollLeftBtnStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollLeftBtnNormal));
+		scrollLeftBtnStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollLeftBtnHover));
+		scrollLeftBtnStyle.active.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollLeftBtnActive));
+		scrollLeftBtnStyle.fixedHeight = true;
+		scrollLeftBtnStyle.fixedWidth = true;
+		scrollLeftBtnStyle.height = 8;
+		scrollLeftBtnStyle.width = 4;
+
+		mSkin.setStyle("ScrollLeftBtn", scrollLeftBtnStyle);
+
+		// Right button
+		HTexture scrollRightBtnNormal = static_resource_cast<Texture>(Importer::instance().import(ScrollBarRightNormalTex));
+		HTexture scrollRightBtnHover = static_resource_cast<Texture>(Importer::instance().import(ScrollBarRightHoverTex));
+		HTexture scrollRightBtnActive = static_resource_cast<Texture>(Importer::instance().import(ScrollBarRightActiveTex));
+
+		GUIElementStyle scrollRightBtnStyle;
+		scrollRightBtnStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollRightBtnNormal));
+		scrollRightBtnStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollRightBtnHover));
+		scrollRightBtnStyle.active.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollRightBtnActive));
+		scrollRightBtnStyle.fixedHeight = true;
+		scrollRightBtnStyle.fixedWidth = true;
+		scrollRightBtnStyle.height = 8;
+		scrollRightBtnStyle.width = 4;
+
+		mSkin.setStyle("ScrollRightBtn", scrollRightBtnStyle);
+
+		// Horizontal handle
+		HTexture scrollBarHorzBtnNormal = static_resource_cast<Texture>(Importer::instance().import(ScrollBarHandleHorzNormalTex));
+		HTexture scrollBarHorzBtnHover = static_resource_cast<Texture>(Importer::instance().import(ScrollBarHandleHorzHoverTex));
+		HTexture scrollBarHorzBtnActive = static_resource_cast<Texture>(Importer::instance().import(ScrollBarHandleHorzActiveTex));
+
+		GUIElementStyle scrollBarHorzBtnStyle;
+		scrollBarHorzBtnStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarHorzBtnNormal));
+		scrollBarHorzBtnStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarHorzBtnHover));
+		scrollBarHorzBtnStyle.active.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarHorzBtnActive));
+		scrollBarHorzBtnStyle.fixedHeight = true;
+		scrollBarHorzBtnStyle.fixedWidth = true;
+		scrollBarHorzBtnStyle.height = 6;
+		scrollBarHorzBtnStyle.width = 4;
+
+		mSkin.setStyle("ScrollBarHorzBtn", scrollBarHorzBtnStyle);
+
+		// Vertical handle
+		HTexture scrollBarVertBtnNormal = static_resource_cast<Texture>(Importer::instance().import(ScrollBarHandleVertNormalTex));
+		HTexture scrollBarVertBtnHover = static_resource_cast<Texture>(Importer::instance().import(ScrollBarHandleVertHoverTex));
+		HTexture scrollBarVertBtnActive = static_resource_cast<Texture>(Importer::instance().import(ScrollBarHandleVertActiveTex));
+
+		GUIElementStyle scrollBarVertBtnStyle;
+		scrollBarVertBtnStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarVertBtnNormal));
+		scrollBarVertBtnStyle.hover.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarVertBtnHover));
+		scrollBarVertBtnStyle.active.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarVertBtnActive));
+		scrollBarVertBtnStyle.fixedHeight = true;
+		scrollBarVertBtnStyle.fixedWidth = true;
+		scrollBarVertBtnStyle.height = 4;
+		scrollBarVertBtnStyle.width = 6;
+
+		mSkin.setStyle("ScrollBarVertBtn", scrollBarVertBtnStyle);
+
+		// Vertical scroll bar
+		GUIElementStyle vertScrollBarStyle;
+		vertScrollBarStyle.fixedHeight = false;
+		vertScrollBarStyle.fixedWidth = true;
+		vertScrollBarStyle.minHeight = 16;
+		vertScrollBarStyle.width = 8;
+
+		mSkin.setStyle("ScrollBarVert", vertScrollBarStyle);
+
+		// Horizontal scroll bar
+		GUIElementStyle horzScrollBarStyle;
+		horzScrollBarStyle.fixedHeight = true;
+		horzScrollBarStyle.fixedWidth = false;
+		horzScrollBarStyle.minWidth = 16;
+		horzScrollBarStyle.height = 8;
+
+		mSkin.setStyle("ScrollBarHorz", horzScrollBarStyle);
 	}
 	}
 
 
 }
 }

+ 2 - 4
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -62,8 +62,7 @@ namespace BansheeEngine
 	{
 	{
 		for(auto& child : mChildren)
 		for(auto& child : mChildren)
 		{
 		{
-			if(child->_getType() == Type::Layout)
-				child->_updateOptimalLayoutSizes();
+			child->_updateOptimalLayoutSizes();
 		}
 		}
 	}
 	}
 
 
@@ -71,8 +70,7 @@ namespace BansheeEngine
 	{
 	{
 		for(auto& child : mChildren)
 		for(auto& child : mChildren)
 		{
 		{
-			if(child->_getType() == Type::Layout)
-				child->_updateLayout(x, y, width, height, widgetDepth, areaDepth);
+			child->_updateLayoutInternal(x, y, width, height, widgetDepth, areaDepth);
 		}
 		}
 	}
 	}
 
 

+ 8 - 9
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -11,11 +11,7 @@ namespace BansheeEngine
 	void GUILayoutX::_updateOptimalLayoutSizes()
 	void GUILayoutX::_updateOptimalLayoutSizes()
 	{
 	{
 		// Update all children first, otherwise we can't determine out own optimal size
 		// Update all children first, otherwise we can't determine out own optimal size
-		for(auto& child : mChildren)
-		{
-			if(child->_getType() == GUIElementBase::Type::Layout)
-				child->_updateOptimalLayoutSizes();
-		}
+		GUIElementBase::_updateOptimalLayoutSizes();
 
 
 		if(mChildren.size() != mOptimalSizes.size())
 		if(mChildren.size() != mOptimalSizes.size())
 			mOptimalSizes.resize(mChildren.size());
 			mOptimalSizes.resize(mChildren.size());
@@ -333,12 +329,12 @@ namespace BansheeEngine
 		childIdx = 0;
 		childIdx = 0;
 		for(auto& child : mChildren)
 		for(auto& child : mChildren)
 		{
 		{
-			UINT32 elementWidth = elementSizes[childIdx];
+			UINT32 elemWidth = elementSizes[childIdx];
 
 
 			if(child->_getType() == GUIElementBase::Type::Element)
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
 			{
 				GUIElement* element = static_cast<GUIElement*>(child);
 				GUIElement* element = static_cast<GUIElement*>(child);
-				element->_setWidth(elementWidth);
+				element->_setWidth(elemWidth);
 
 
 				UINT32 elemHeight = mOptimalSizes[childIdx].y;
 				UINT32 elemHeight = mOptimalSizes[childIdx].y;
 				const GUILayoutOptions& layoutOptions = element->_getLayoutOptions();
 				const GUILayoutOptions& layoutOptions = element->_getLayoutOptions();
@@ -365,19 +361,22 @@ namespace BansheeEngine
 				UINT32 clippedHeight = (UINT32)std::min((INT32)element->_getHeight(), (INT32)height - (INT32)yOffset);
 				UINT32 clippedHeight = (UINT32)std::min((INT32)element->_getHeight(), (INT32)height - (INT32)yOffset);
 
 
 				element->_setClipRect(Rect(0, 0, clippedWidth, clippedHeight));
 				element->_setClipRect(Rect(0, 0, clippedWidth, clippedHeight));
+				element->_updateLayoutInternal(offset.x, offset.y, elemWidth, elemHeight, widgetDepth, areaDepth);
 			}
 			}
 			else if(child->_getType() == GUIElementBase::Type::Layout)
 			else if(child->_getType() == GUIElementBase::Type::Layout)
 			{
 			{
 				GUILayout* layout = static_cast<GUILayout*>(child);
 				GUILayout* layout = static_cast<GUILayout*>(child);
-				layout->_updateLayout(x + xOffset, y, elementWidth, height, widgetDepth, areaDepth);
+				layout->_updateLayoutInternal(x + xOffset, y, elemWidth, height, widgetDepth, areaDepth);
 			}
 			}
 
 
-			xOffset += elementWidth;
+			xOffset += elemWidth;
 			childIdx++;
 			childIdx++;
 		}
 		}
 
 
 		stackDeallocLast(elementScaleWeights, HID_Main);
 		stackDeallocLast(elementScaleWeights, HID_Main);
 		stackDeallocLast(elementSizes, HID_Main);
 		stackDeallocLast(elementSizes, HID_Main);
 		stackDeallocLast(processedElements, HID_Main);
 		stackDeallocLast(processedElements, HID_Main);
+
+		_markAsClean();
 	}
 	}
 }
 }

+ 9 - 10
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -11,11 +11,7 @@ namespace BansheeEngine
 	void GUILayoutY::_updateOptimalLayoutSizes()
 	void GUILayoutY::_updateOptimalLayoutSizes()
 	{
 	{
 		// Update all children first, otherwise we can't determine out own optimal size
 		// Update all children first, otherwise we can't determine out own optimal size
-		for(auto& child : mChildren)
-		{
-			if(child->_getType() == GUIElementBase::Type::Layout)
-				child->_updateOptimalLayoutSizes();
-		}
+		GUIElementBase::_updateOptimalLayoutSizes();
 
 
 		if(mChildren.size() != mOptimalSizes.size())
 		if(mChildren.size() != mOptimalSizes.size())
 			mOptimalSizes.resize(mChildren.size());
 			mOptimalSizes.resize(mChildren.size());
@@ -334,7 +330,7 @@ namespace BansheeEngine
 		childIdx = 0;
 		childIdx = 0;
 		for(auto& child : mChildren)
 		for(auto& child : mChildren)
 		{
 		{
-			UINT32 elementHeight = elementSizes[childIdx];
+			UINT32 elemHeight = elementSizes[childIdx];
 
 
 			if(child->_getType() == GUIElementBase::Type::Element)
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
 			{
@@ -352,9 +348,9 @@ namespace BansheeEngine
 				}
 				}
 
 
 				element->_setWidth(elemWidth);
 				element->_setWidth(elemWidth);
-				element->_setHeight(elementHeight);
+				element->_setHeight(elemHeight);
 
 
-				UINT32 xOffset = (UINT32)Math::CeilToInt((width - element->_getHeight()) * 0.5f);
+				UINT32 xOffset = (UINT32)Math::CeilToInt((width - element->_getWidth()) * 0.5f);
 
 
 				Int2 offset(x + xOffset, y + yOffset);
 				Int2 offset(x + xOffset, y + yOffset);
 				element->_setOffset(offset);
 				element->_setOffset(offset);
@@ -365,19 +361,22 @@ namespace BansheeEngine
 				UINT32 clippedHeight = (UINT32)std::min((INT32)element->_getHeight(), (INT32)height - (INT32)yOffset);
 				UINT32 clippedHeight = (UINT32)std::min((INT32)element->_getHeight(), (INT32)height - (INT32)yOffset);
 
 
 				element->_setClipRect(Rect(0, 0, clippedWidth, clippedHeight));
 				element->_setClipRect(Rect(0, 0, clippedWidth, clippedHeight));
+				element->_updateLayoutInternal(offset.x, offset.y, elemWidth, elemHeight, widgetDepth, areaDepth);
 			}
 			}
 			else if(child->_getType() == GUIElementBase::Type::Layout)
 			else if(child->_getType() == GUIElementBase::Type::Layout)
 			{
 			{
 				GUILayout* layout = static_cast<GUILayout*>(child);
 				GUILayout* layout = static_cast<GUILayout*>(child);
-				layout->_updateLayout(x, y + yOffset, width, elementHeight, widgetDepth, areaDepth);
+				layout->_updateLayoutInternal(x, y + yOffset, width, elemHeight, widgetDepth, areaDepth);
 			}
 			}
 
 
-			yOffset += elementHeight;
+			yOffset += elemHeight;
 			childIdx++;
 			childIdx++;
 		}
 		}
 
 
 		stackDeallocLast(elementScaleWeights, HID_Main);
 		stackDeallocLast(elementScaleWeights, HID_Main);
 		stackDeallocLast(elementSizes, HID_Main);
 		stackDeallocLast(elementSizes, HID_Main);
 		stackDeallocLast(processedElements, HID_Main);
 		stackDeallocLast(processedElements, HID_Main);
+
+		_markAsClean();
 	}
 	}
 }
 }

+ 11 - 1
BansheeEngine/Source/BsGUIScrollBarVert.cpp

@@ -4,6 +4,8 @@
 #include "BsGUIWidget.h"
 #include "BsGUIWidget.h"
 #include "BsGUILayoutOptions.h"
 #include "BsGUILayoutOptions.h"
 #include "BsGUILayout.h"
 #include "BsGUILayout.h"
+#include "BsGUISkin.h"
+#include "BsGUIButton.h"
 #include "CmException.h"
 #include "CmException.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
@@ -13,7 +15,15 @@ namespace BansheeEngine
 	GUIScrollBarVert::GUIScrollBarVert(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
 	GUIScrollBarVert::GUIScrollBarVert(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, style, layoutOptions), mLayout(nullptr)
 		:GUIElement(parent, style, layoutOptions), mLayout(nullptr)
 	{
 	{
-		// TODO - Init mLayout
+		mLayout = &addLayoutYInternal();
+
+		GUIButton* upBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollUpBtn"));
+		GUIButton* downBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollDownBtn"));
+		GUIButton* handleBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollBarVertBtn"));
+
+		mLayout->addElement(upBtn);
+		mLayout->addElement(handleBtn); // We might want a special element for this?
+		mLayout->addElement(downBtn);
 	}
 	}
 
 
 	GUIScrollBarVert::~GUIScrollBarVert()
 	GUIScrollBarVert::~GUIScrollBarVert()

+ 3 - 1
CamelotClient/CmEditorWindow.cpp

@@ -18,6 +18,7 @@
 #include "BsEngineGUI.h"
 #include "BsEngineGUI.h"
 #include "BsGUIArea.h"
 #include "BsGUIArea.h"
 #include "BsGUITabbedTitleBar.h"
 #include "BsGUITabbedTitleBar.h"
+#include "BsGUIScrollBarVert.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 using namespace BansheeEngine;
 using namespace BansheeEngine;
@@ -65,7 +66,7 @@ namespace BansheeEditor
 
 
 		//// DEBUG
 		//// DEBUG
 		
 		
-		GUIArea* dbgArea = GUIArea::create(*mGUI, 0, 13, 0, 0, 475);
+		GUIArea* dbgArea = GUIArea::create(*mGUI, 5, 13, 190, 0, 475);
 		GUILayout& layout = dbgArea->getLayout();
 		GUILayout& layout = dbgArea->getLayout();
 		//
 		//
 		//mDbgLabel = GUILabel::create(*mGUI, "Testing test");
 		//mDbgLabel = GUILabel::create(*mGUI, "Testing test");
@@ -73,6 +74,7 @@ namespace BansheeEditor
 
 
 		layout.addElement(GUIInputBox::create(*mGUI));
 		layout.addElement(GUIInputBox::create(*mGUI));
 		layout.addElement(GUIInputBox::create(*mGUI, GUILayoutOptions::fixed(100, 100), true));
 		layout.addElement(GUIInputBox::create(*mGUI, GUILayoutOptions::fixed(100, 100), true));
+		layout.addElement(GUIScrollBarVert::create(*mGUI));
 		
 		
 		//GUIFlexibleSpace& space4 = otherLayout.addFlexibleSpace();
 		//GUIFlexibleSpace& space4 = otherLayout.addFlexibleSpace();
 		//otherLayout.addElement(mDbgLabel);
 		//otherLayout.addElement(mDbgLabel);