Procházet zdrojové kódy

GUI _getOptimalWidth and _getOptimalHeight merged into a single method _getOptimalSize

Marko Pintera před 12 roky
rodič
revize
d38f5fd865

+ 1 - 2
BansheeEngine/Include/BsGUIButton.h

@@ -59,8 +59,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 
 		virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
 	private:

+ 1 - 2
BansheeEngine/Include/BsGUIElementBase.h

@@ -47,8 +47,7 @@ namespace BansheeEngine
 
 		void _setParent(GUIElementBase* parent) { mParentElement = parent; }
 
-		virtual CM::UINT32 _getOptimalWidth() const = 0;
-		virtual CM::UINT32 _getOptimalHeight() const = 0;
+		virtual CM::Int2 _getOptimalSize() const = 0;
 		virtual Type _getType() const = 0;
 		GUIElementBase* _getParent() const { return mParentElement; }
 

+ 1 - 2
BansheeEngine/Include/BsGUIInputBox.h

@@ -48,8 +48,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 
 		virtual CM::Int2 _getTextInputOffset() const;
 		virtual CM::Rect _getTextInputRect() const;

+ 1 - 2
BansheeEngine/Include/BsGUILabel.h

@@ -54,8 +54,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 	private:
 		TextSprite* mTextSprite;
 		GUIContent mContent;

+ 1 - 2
BansheeEngine/Include/BsGUILayout.h

@@ -33,8 +33,7 @@ namespace BansheeEngine
 		CM::UINT32 getNumChildren() const { return (CM::UINT32)mChildren.size(); }
 		void removeChildAt(CM::UINT32 idx);
 
-		CM::UINT32 _getOptimalWidth() const { return mOptimalWidth; }
-		CM::UINT32 _getOptimalHeight() const { return mOptimalHeight; }
+		CM::Int2 _getOptimalSize() const { return CM::Int2(mOptimalWidth, mOptimalHeight); }
 		Type _getType() const { return GUIElementBase::Type::Layout; }
 
 		/**

+ 1 - 2
BansheeEngine/Include/BsGUIListBox.h

@@ -51,8 +51,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 
 		virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
 	private:

+ 1 - 2
BansheeEngine/Include/BsGUIScrollArea.h

@@ -49,8 +49,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 	private:
 		GUIScrollArea(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions);
 

+ 1 - 2
BansheeEngine/Include/BsGUIScrollBar.h

@@ -58,8 +58,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 
 		virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
 	private:

+ 1 - 2
BansheeEngine/Include/BsGUIScrollBarHandle.h

@@ -59,8 +59,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 	private:
 		ImageSprite* mImageSprite;
 		CM::UINT32 mHandleSize;

+ 2 - 4
BansheeEngine/Include/BsGUISpace.h

@@ -15,8 +15,7 @@ namespace BansheeEngine
 		CM::UINT32 getSize() const { return mSize; }
 		Type _getType() const { return GUIElementBase::Type::FixedSpace; }
 
-		virtual CM::UINT32 _getOptimalWidth() const { return getSize(); }
-		virtual CM::UINT32 _getOptimalHeight() const { return getSize(); }
+		virtual CM::Int2 _getOptimalSize() const { return CM::Int2(getSize(), getSize()); }
 
 	protected:
 		CM::UINT32 mSize;
@@ -29,7 +28,6 @@ namespace BansheeEngine
 
 		Type _getType() const { return GUIElementBase::Type::FlexibleSpace; }
 
-		virtual CM::UINT32 _getOptimalWidth() const { return 0; }
-		virtual CM::UINT32 _getOptimalHeight() const { return 0; }
+		virtual CM::Int2 _getOptimalSize() const { return CM::Int2(0, 0); }
 	};
 }

+ 1 - 2
BansheeEngine/Include/BsGUITexture.h

@@ -64,7 +64,6 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 	};
 }

+ 1 - 2
BansheeEngine/Include/BsGUIToggle.h

@@ -69,8 +69,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateClippedBounds();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 
 		virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
 	protected:

+ 1 - 2
BansheeEngine/Include/BsGUIViewport.h

@@ -58,8 +58,7 @@ namespace BansheeEngine
 		 */
 		virtual void updateRenderElementsInternal();
 
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
+		virtual CM::Int2 _getOptimalSize() const;
 
 	private:
 		HCamera mCamera;

+ 9 - 10
BansheeEngine/Source/BsGUIButton.cpp

@@ -158,22 +158,21 @@ namespace BansheeEngine
 		mClippedBounds = mImageSprite->getBounds(mOffset, mClipRect);
 	}
 
-	UINT32 GUIButton::_getOptimalWidth() const
+	Int2 GUIButton::_getOptimalSize() const
 	{
 		UINT32 imageWidth = 0;
-		if(mImageDesc.texture != nullptr)
-			imageWidth = mImageDesc.texture->getTexture()->getWidth();
-
-		return std::max(imageWidth, (UINT32)GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions()).x);
-	}
-
-	UINT32 GUIButton::_getOptimalHeight() const
-	{
 		UINT32 imageHeight = 0;
 		if(mImageDesc.texture != nullptr)
+		{
+			imageWidth = mImageDesc.texture->getTexture()->getWidth();
 			imageHeight = mImageDesc.texture->getTexture()->getHeight();
+		}
+
+		Int2 contentSize = GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions());
+		UINT32 contentWidth = std::max(imageWidth, (UINT32)contentSize.x);
+		UINT32 contentHeight = std::max(imageHeight, (UINT32)contentSize.y);
 
-		return std::max(imageHeight, (UINT32)GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions()).y);
+		return Int2(contentWidth, contentHeight);
 	}
 
 	UINT32 GUIButton::_getRenderElementDepth(UINT32 renderElementIdx) const

+ 9 - 10
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -279,22 +279,21 @@ namespace BansheeEngine
 		return Rect();
 	}
 
-	UINT32 GUIInputBox::_getOptimalWidth() const
+	Int2 GUIInputBox::_getOptimalSize() const
 	{
 		UINT32 imageWidth = 0;
-		if(mImageDesc.texture != nullptr)
-			imageWidth = mImageDesc.texture->getTexture()->getWidth();
-
-		return std::max(imageWidth, (UINT32)GUIHelper::calcOptimalContentsSize(mText, *mStyle, _getLayoutOptions()).x);
-	}
-
-	UINT32 GUIInputBox::_getOptimalHeight() const
-	{
 		UINT32 imageHeight = 0;
 		if(mImageDesc.texture != nullptr)
+		{
+			imageWidth = mImageDesc.texture->getTexture()->getWidth();
 			imageHeight = mImageDesc.texture->getTexture()->getHeight();
+		}
+
+		Int2 contentSize = GUIHelper::calcOptimalContentsSize(mText, *mStyle, _getLayoutOptions());
+		UINT32 contentWidth = std::max(imageWidth, (UINT32)contentSize.x);
+		UINT32 contentHeight = std::max(imageHeight, (UINT32)contentSize.y);
 
-		return std::max(imageHeight, (UINT32)GUIHelper::calcOptimalContentsSize(mText, *mStyle, _getLayoutOptions()).y);
+		return Int2(contentWidth, contentHeight);
 	}
 
 	CM::Int2 GUIInputBox::_getTextInputOffset() const

+ 2 - 7
BansheeEngine/Source/BsGUILabel.cpp

@@ -59,14 +59,9 @@ namespace BansheeEngine
 		mClippedBounds = mTextSprite->getBounds(mOffset, mClipRect);
 	}
 
-	UINT32 GUILabel::_getOptimalWidth() const
+	Int2 GUILabel::_getOptimalSize() const
 	{
-		return GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions()).x;
-	}
-
-	UINT32 GUILabel::_getOptimalHeight() const
-	{
-		return GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions()).y;
+		return GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions());
 	}
 
 	void GUILabel::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 

+ 8 - 4
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -35,13 +35,17 @@ namespace BansheeEngine
 				GUIElement* element = static_cast<GUIElement*>(child);
 				const GUILayoutOptions& layoutOptions = element->_getLayoutOptions();
 
+				Int2 optimalSize;
+				if(!layoutOptions.fixedWidth || !layoutOptions.fixedHeight)
+					optimalSize = child->_getOptimalSize();
+
 				if(layoutOptions.fixedWidth)
 				{
 					optimalWidth = layoutOptions.width;
 				}
 				else
 				{
-					optimalWidth = child->_getOptimalWidth();
+					optimalWidth = optimalSize.x;
 
 					if(layoutOptions.minWidth > 0)
 						optimalWidth = std::max(layoutOptions.minWidth, optimalWidth);
@@ -54,7 +58,7 @@ namespace BansheeEngine
 					optimalHeight = layoutOptions.height;
 				else
 				{
-					optimalHeight = child->_getOptimalHeight();
+					optimalHeight = optimalSize.y;
 
 					if(layoutOptions.minHeight > 0)
 						optimalHeight = std::max(layoutOptions.minHeight, optimalHeight);
@@ -65,7 +69,7 @@ namespace BansheeEngine
 			}
 			else if(child->_getType() == GUIElementBase::Type::Layout)
 			{
-				optimalWidth = child->_getOptimalWidth();
+				optimalWidth = child->_getOptimalSize().x;
 			}
 
 			mOptimalSizes[childIdx].x = optimalWidth;
@@ -80,7 +84,7 @@ namespace BansheeEngine
 
 	void GUILayoutX::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect clipRect, UINT8 widgetDepth, UINT16 areaDepth)
 	{
-		UINT32 totalOptimalSize = _getOptimalWidth();
+		UINT32 totalOptimalSize = _getOptimalSize().x;
 		UINT32 totalNonClampedSize = 0;
 		UINT32 numNonClampedElements = 0;
 		UINT32 numFlexibleSpaces = 0;

+ 8 - 4
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -35,13 +35,17 @@ namespace BansheeEngine
 				GUIElement* element = static_cast<GUIElement*>(child);
 				const GUILayoutOptions& layoutOptions = element->_getLayoutOptions();
 
+				Int2 optimalSize;
+				if(!layoutOptions.fixedWidth || !layoutOptions.fixedHeight)
+					optimalSize = child->_getOptimalSize();
+
 				if(layoutOptions.fixedHeight)
 				{
 					optimalHeight = layoutOptions.height;
 				}
 				else
 				{
-					optimalHeight = element->_getOptimalHeight();
+					optimalHeight = optimalSize.y;
 
 					if(layoutOptions.minHeight > 0)
 						optimalHeight = std::max(layoutOptions.minHeight, optimalHeight);
@@ -54,7 +58,7 @@ namespace BansheeEngine
 					optimalWidth = layoutOptions.width;
 				else
 				{
-					optimalWidth = element->_getOptimalWidth();
+					optimalWidth = optimalSize.x;
 
 					if(layoutOptions.minWidth > 0)
 						optimalWidth = std::max(layoutOptions.minWidth, optimalWidth);
@@ -66,7 +70,7 @@ namespace BansheeEngine
 			else if(child->_getType() == GUIElementBase::Type::Layout)
 			{
 				GUILayout* layout = static_cast<GUILayout*>(child);
-				optimalHeight = layout->_getOptimalHeight();
+				optimalHeight = layout->_getOptimalSize().y;
 			}
 
 			mOptimalSizes[childIdx].y = optimalHeight;
@@ -81,7 +85,7 @@ namespace BansheeEngine
 
 	void GUILayoutY::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect clipRect, UINT8 widgetDepth, UINT16 areaDepth)
 	{
-		UINT32 totalOptimalSize = _getOptimalHeight();
+		UINT32 totalOptimalSize = _getOptimalSize().y;
 		UINT32 totalNonClampedSize = 0;
 		UINT32 numNonClampedElements = 0;
 		UINT32 numFlexibleSpaces = 0;

+ 9 - 10
BansheeEngine/Source/BsGUIListBox.cpp

@@ -113,22 +113,21 @@ namespace BansheeEngine
 		mClippedBounds = mImageSprite->getBounds(mOffset, mClipRect);
 	}
 
-	UINT32 GUIListBox::_getOptimalWidth() const
+	Int2 GUIListBox::_getOptimalSize() const
 	{
 		UINT32 imageWidth = 0;
-		if(mImageDesc.texture != nullptr)
-			imageWidth = mImageDesc.texture->getTexture()->getWidth();
-
-		return std::max(imageWidth, (UINT32)GUIHelper::calcOptimalContentsSize(mElements[mSelectedIdx], *mStyle, _getLayoutOptions()).x);
-	}
-
-	UINT32 GUIListBox::_getOptimalHeight() const
-	{
 		UINT32 imageHeight = 0;
 		if(mImageDesc.texture != nullptr)
+		{
+			imageWidth = mImageDesc.texture->getTexture()->getWidth();
 			imageHeight = mImageDesc.texture->getTexture()->getHeight();
+		}
+
+		Int2 contentSize = GUIHelper::calcOptimalContentsSize(mElements[mSelectedIdx], *mStyle, _getLayoutOptions());
+		UINT32 contentWidth = std::max(imageWidth, (UINT32)contentSize.x);
+		UINT32 contentHeight = std::max(imageHeight, (UINT32)contentSize.y);
 
-		return std::max(imageHeight, (UINT32)GUIHelper::calcOptimalContentsSize(mElements[mSelectedIdx], *mStyle, _getLayoutOptions()).y);
+		return Int2(contentWidth, contentHeight);
 	}
 
 	UINT32 GUIListBox::_getRenderElementDepth(UINT32 renderElementIdx) const

+ 2 - 7
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -55,14 +55,9 @@ namespace BansheeEngine
 		mClippedBounds = Rect(0, 0, 0, 0); // We don't want any mouse input for this element. This is just a container.
 	}
 
-	UINT32 GUIScrollArea::_getOptimalWidth() const
+	Int2 GUIScrollArea::_getOptimalSize() const
 	{
-		return mContentLayout->_getOptimalWidth();
-	}
-
-	UINT32 GUIScrollArea::_getOptimalHeight() const
-	{
-		return mContentLayout->_getOptimalHeight();
+		return mContentLayout->_getOptimalSize();
 	}
 
 	void GUIScrollArea::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 

+ 2 - 7
BansheeEngine/Source/BsGUIScrollBar.cpp

@@ -99,14 +99,9 @@ namespace BansheeEngine
 		mClippedBounds = Rect(0, 0, 0, 0); // We don't want any mouse input for this element. This is just a container.
 	}
 
-	UINT32 GUIScrollBar::_getOptimalWidth() const
+	Int2 GUIScrollBar::_getOptimalSize() const
 	{
-		return mLayout->_getOptimalWidth();
-	}
-
-	UINT32 GUIScrollBar::_getOptimalHeight() const
-	{
-		return mLayout->_getOptimalHeight();
+		return mLayout->_getOptimalSize();
 	}
 
 	UINT32 GUIScrollBar::_getRenderElementDepth(UINT32 renderElementIdx) const

+ 3 - 13
BansheeEngine/Source/BsGUIScrollBarHandle.cpp

@@ -129,24 +129,14 @@ namespace BansheeEngine
 		mClippedBounds.clip(localClipRect);
 	}
 
-	UINT32 GUIScrollBarHandle::_getOptimalWidth() const
+	Int2 GUIScrollBarHandle::_getOptimalSize() const
 	{
 		if(mCurTexture != nullptr)
 		{
-			return mCurTexture->getTexture()->getWidth();
+			return Int2(mCurTexture->getTexture()->getWidth(), mCurTexture->getTexture()->getHeight());
 		}
 
-		return 0;
-	}
-
-	UINT32 GUIScrollBarHandle::_getOptimalHeight() const
-	{
-		if(mCurTexture != nullptr)
-		{
-			return mCurTexture->getTexture()->getHeight();
-		}
-
-		return 0;
+		return Int2();
 	}
 
 	void GUIScrollBarHandle::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 

+ 3 - 13
BansheeEngine/Source/BsGUITexture.cpp

@@ -167,24 +167,14 @@ namespace BansheeEngine
 		mClippedBounds = mImageSprite->getBounds(mOffset, mClipRect);
 	}
 
-	UINT32 GUITexture::_getOptimalWidth() const
+	Int2 GUITexture::_getOptimalSize() const
 	{
 		if(mDesc.texture != nullptr)
 		{
-			return mDesc.texture->getTexture()->getWidth();
+			return Int2(mDesc.texture->getTexture()->getWidth(), mDesc.texture->getTexture()->getHeight());
 		}
 
-		return 0;
-	}
-
-	UINT32 GUITexture::_getOptimalHeight() const
-	{
-		if(mDesc.texture != nullptr)
-		{
-			return mDesc.texture->getTexture()->getHeight();
-		}
-
-		return 0;
+		return Int2(0, 0);
 	}
 
 	void GUITexture::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 

+ 9 - 10
BansheeEngine/Source/BsGUIToggle.cpp

@@ -257,22 +257,21 @@ namespace BansheeEngine
 		mClippedBounds = mImageSprite->getBounds(mOffset, mClipRect);
 	}
 
-	UINT32 GUIToggle::_getOptimalWidth() const
+	Int2 GUIToggle::_getOptimalSize() const
 	{
 		UINT32 imageWidth = 0;
-		if(mImageDesc.texture != nullptr)
-			imageWidth = mImageDesc.texture->getTexture()->getWidth();
-
-		return std::max(imageWidth, (UINT32)GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions()).x);
-	}
-
-	UINT32 GUIToggle::_getOptimalHeight() const
-	{
 		UINT32 imageHeight = 0;
 		if(mImageDesc.texture != nullptr)
+		{
+			imageWidth = mImageDesc.texture->getTexture()->getWidth();
 			imageHeight = mImageDesc.texture->getTexture()->getHeight();
+		}
+
+		Int2 contentSize = GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions());
+		UINT32 contentWidth = std::max(imageWidth, (UINT32)contentSize.x);
+		UINT32 contentHeight = std::max(imageHeight, (UINT32)contentSize.y);
 
-		return std::max(imageHeight, (UINT32)GUIHelper::calcOptimalContentsSize(mContent, *mStyle, _getLayoutOptions()).y);
+		return Int2(contentWidth, contentHeight);
 	}
 
 	UINT32 GUIToggle::_getRenderElementDepth(UINT32 renderElementIdx) const

+ 2 - 7
BansheeEngine/Source/BsGUIViewport.cpp

@@ -83,14 +83,9 @@ namespace BansheeEngine
 		mBounds.y += mOffset.y;
 	}
 
-	UINT32 GUIViewport::_getOptimalWidth() const
+	Int2 GUIViewport::_getOptimalSize() const
 	{
-		return 0;
-	}
-
-	UINT32 GUIViewport::_getOptimalHeight() const
-	{
-		return 0;
+		return Int2(0, 0);
 	}
 
 	void GUIViewport::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads,