Browse Source

Fixed GUITexture::_getOptimalSize so it properly considers active layout options
Made EditorWidgetContainer use a GUIArea for managing GUITabbedTitleBar instead of calling its method directly

Marko Pintera 12 years ago
parent
commit
b0f96e2da7

+ 20 - 3
BansheeEngine/Source/BsGUITexture.cpp

@@ -221,12 +221,29 @@ namespace BansheeEngine
 
 
 	Vector2I GUITexture::_getOptimalSize() const
 	Vector2I GUITexture::_getOptimalSize() const
 	{
 	{
-		if(mActiveTexture != nullptr && mActiveTexture.isLoaded())
+		Vector2I optimalSize;
+
+		if(_getLayoutOptions().fixedWidth)
+			optimalSize.x = _getLayoutOptions().width;
+		else
 		{
 		{
-			return Vector2I(mActiveTexture->getTexture()->getWidth(), mActiveTexture->getTexture()->getHeight());
+			if(mActiveTexture != nullptr && mActiveTexture.isLoaded())
+				optimalSize.x = mActiveTexture->getTexture()->getWidth();
+			else
+				optimalSize.x = _getLayoutOptions().maxWidth;
+		}
+
+		if(_getLayoutOptions().fixedHeight)
+			optimalSize.y = _getLayoutOptions().height;
+		else
+		{
+			if(mActiveTexture != nullptr && mActiveTexture.isLoaded())
+				optimalSize.y = mActiveTexture->getTexture()->getHeight();
+			else
+				optimalSize.y = _getLayoutOptions().maxHeight;
 		}
 		}
 
 
-		return Vector2I(0, 0);
+		return optimalSize;
 	}
 	}
 
 
 	void GUITexture::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
 	void GUITexture::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 

+ 1 - 0
CamelotClient/Include/BsEditorWidgetContainer.h

@@ -28,6 +28,7 @@ namespace BansheeEditor
 		boost::signal<void()> onWidgetClosed;
 		boost::signal<void()> onWidgetClosed;
 	private:
 	private:
 		GUITabbedTitleBar* mTitleBar;
 		GUITabbedTitleBar* mTitleBar;
+		BS::GUIArea* mTitleBarArea;
 		BS::GUIWidget* mParent;
 		BS::GUIWidget* mParent;
 		CM::INT32 mX, mY;
 		CM::INT32 mX, mY;
 		CM::UINT32 mWidth, mHeight;
 		CM::UINT32 mWidth, mHeight;

+ 3 - 3
CamelotClient/Include/BsGUITabbedTitleBar.h

@@ -25,9 +25,6 @@ namespace BansheeEditor
 		void insertTab(CM::UINT32 idx, const CM::HString& name);
 		void insertTab(CM::UINT32 idx, const CM::HString& name);
 		void removeTab(CM::UINT32 idx);
 		void removeTab(CM::UINT32 idx);
 
 
-		void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
-			CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
-
 		boost::signal<void(CM::UINT32)> onTabActivated;
 		boost::signal<void(CM::UINT32)> onTabActivated;
 		boost::signal<void(CM::UINT32)> onTabClosed;
 		boost::signal<void(CM::UINT32)> onTabClosed;
 		boost::signal<void(CM::UINT32)> onTabDraggedOff;
 		boost::signal<void(CM::UINT32)> onTabDraggedOff;
@@ -61,6 +58,9 @@ namespace BansheeEditor
 		 * @copydoc GUIElement::updateBounds()
 		 * @copydoc GUIElement::updateBounds()
 		 */
 		 */
 		virtual void updateClippedBounds();
 		virtual void updateClippedBounds();
+
+		void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
+			CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
 	protected:
 	protected:
 		static const CM::UINT32 TAB_SPACING;
 		static const CM::UINT32 TAB_SPACING;
 		static const CM::UINT32 OPTION_BTN_SPACING;
 		static const CM::UINT32 OPTION_BTN_SPACING;

+ 11 - 29
CamelotClient/Source/BsEditorWidgetContainer.cpp

@@ -3,9 +3,11 @@
 #include "BsEditorWidget.h"
 #include "BsEditorWidget.h"
 #include "BsDragAndDropManager.h"
 #include "BsDragAndDropManager.h"
 #include "BsEditorWindow.h"
 #include "BsEditorWindow.h"
+#include "BsGUIArea.h"
 #include "CmMath.h"
 #include "CmMath.h"
 #include "CmInput.h"
 #include "CmInput.h"
 #include "BsGUIWidget.h"
 #include "BsGUIWidget.h"
+#include "BsGUILayout.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 using namespace BansheeEngine;
 using namespace BansheeEngine;
@@ -15,17 +17,23 @@ namespace BansheeEditor
 	const CM::UINT32 EditorWidgetContainer::TitleBarHeight = 13;
 	const CM::UINT32 EditorWidgetContainer::TitleBarHeight = 13;
 
 
 	EditorWidgetContainer::EditorWidgetContainer(BS::GUIWidget* parent, RenderWindow* renderWindow)
 	EditorWidgetContainer::EditorWidgetContainer(BS::GUIWidget* parent, RenderWindow* renderWindow)
-		:mParent(parent), mX(0), mY(0), mWidth(0), mHeight(0), mTitleBar(nullptr), mActiveWidget(-1)
+		:mParent(parent), mX(0), mY(0), mWidth(0), mHeight(0), mTitleBar(nullptr), mActiveWidget(-1),
+		mTitleBarArea(nullptr)
 	{
 	{
+		mTitleBarArea = GUIArea::create(*parent, 0, 0, 0, 0, 9900);
+
 		mTitleBar = GUITabbedTitleBar::create(*parent, renderWindow);
 		mTitleBar = GUITabbedTitleBar::create(*parent, renderWindow);
 		mTitleBar->onTabActivated.connect(boost::bind(&EditorWidgetContainer::tabActivated, this, _1));
 		mTitleBar->onTabActivated.connect(boost::bind(&EditorWidgetContainer::tabActivated, this, _1));
 		mTitleBar->onTabClosed.connect(boost::bind(&EditorWidgetContainer::tabClosed, this, _1));
 		mTitleBar->onTabClosed.connect(boost::bind(&EditorWidgetContainer::tabClosed, this, _1));
 		mTitleBar->onTabDraggedOff.connect(boost::bind(&EditorWidgetContainer::tabDraggedOff, this, _1));
 		mTitleBar->onTabDraggedOff.connect(boost::bind(&EditorWidgetContainer::tabDraggedOff, this, _1));
 		mTitleBar->onTabDraggedOn.connect(boost::bind(&EditorWidgetContainer::tabDraggedOn, this, _1));
 		mTitleBar->onTabDraggedOn.connect(boost::bind(&EditorWidgetContainer::tabDraggedOn, this, _1));
+
+		mTitleBarArea->getLayout().addElement(mTitleBar);
 	}
 	}
 
 
 	EditorWidgetContainer::~EditorWidgetContainer()
 	EditorWidgetContainer::~EditorWidgetContainer()
 	{
 	{
+		GUIArea::destroy(mTitleBarArea);
 		GUIElement::destroy(mTitleBar);
 		GUIElement::destroy(mTitleBar);
 
 
 		for(auto& widget : mWidgets)
 		for(auto& widget : mWidgets)
@@ -93,20 +101,7 @@ namespace BansheeEditor
 	void EditorWidgetContainer::setSize(UINT32 width, UINT32 height)
 	void EditorWidgetContainer::setSize(UINT32 width, UINT32 height)
 	{
 	{
 		// TODO - Title bar is always TitleBarHeight size, so what happens when the container area is smaller than that?
 		// TODO - Title bar is always TitleBarHeight size, so what happens when the container area is smaller than that?
-		RectI clipRect(mX, mY, width, TitleBarHeight);
-
-		// TODO - Consider making EditorWidgetContainer a GUIElement so this gets called automatically
-		Vector2I offset(mX, mY);
-		mTitleBar->_setOffset(offset);
-		mTitleBar->_setWidth(width);
-		mTitleBar->_setHeight(TitleBarHeight);
-		mTitleBar->_setAreaDepth(9900);
-		mTitleBar->_setWidgetDepth(mParent->getDepth());
-
-		RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-		mTitleBar->_setClipRect(elemClipRect);
-
-		mTitleBar->_updateLayoutInternal(mX, mY, width, TitleBarHeight, clipRect, mParent->getDepth(), 9900);
+		mTitleBarArea->setSize(width, TitleBarHeight);
 
 
 		if(mActiveWidget >= 0)
 		if(mActiveWidget >= 0)
 		{
 		{
@@ -122,20 +117,7 @@ namespace BansheeEditor
 
 
 	void EditorWidgetContainer::setPosition(INT32 x, INT32 y)
 	void EditorWidgetContainer::setPosition(INT32 x, INT32 y)
 	{
 	{
-		RectI clipRect(x, y, mWidth, mHeight);
-
-		// TODO - Consider making EditorWidgetContainer a GUIElement so this gets called automatically
-		Vector2I offset(x, y);
-		mTitleBar->_setOffset(offset);
-		mTitleBar->_setWidth(mWidth);
-		mTitleBar->_setHeight(mHeight);
-		mTitleBar->_setAreaDepth(9900);
-		mTitleBar->_setWidgetDepth(mParent->getDepth());
-
-		RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-		mTitleBar->_setClipRect(elemClipRect);
-
-		mTitleBar->_updateLayoutInternal(x, y, mWidth, mHeight, clipRect, mParent->getDepth(), 9900);
+		mTitleBarArea->setPosition(x, y);
 
 
 		if(mActiveWidget >= 0)
 		if(mActiveWidget >= 0)
 		{
 		{

+ 0 - 5
CamelotClient/Source/BsGUITabbedTitleBar.cpp

@@ -350,11 +350,6 @@ namespace BansheeEditor
 		mDraggedBtn = nullptr;
 		mDraggedBtn = nullptr;
 
 
 		markContentAsDirty();
 		markContentAsDirty();
-
-		// HACK - Remove once EditorWidgetContainer is a proper GUI object
-		RectI bounds = getBounds();
-		_updateLayoutInternal(bounds.x, bounds.y, bounds.width, bounds.height,
-			_getClipRect(), mParent->getDepth(), 9900);
 	}
 	}
 
 
 	void GUITabbedTitleBar::tabDraggedOn(CM::UINT32 tabIdx)
 	void GUITabbedTitleBar::tabDraggedOn(CM::UINT32 tabIdx)