Browse Source

Text bounds no longer rely on clipped visual bounds

Marko Pintera 12 years ago
parent
commit
14540bb162

+ 0 - 1
BansheeEngine/Include/BsGUIButton.h

@@ -57,7 +57,6 @@ namespace BansheeEngine
 		GUIButton(GUIWidget& parent, const GUIElementStyle* style, const CM::WString& text, const GUILayoutOptions& layoutOptions);
 
 		virtual bool mouseEvent(const GUIMouseEvent& ev);
-		CM::Rect getTextBounds() const;
 		CM::Rect getTextClipRect() const;
 	};
 }

+ 1 - 0
BansheeEngine/Include/BsGUIElement.h

@@ -130,6 +130,7 @@ namespace BansheeEngine
 		 */
 		void markMeshAsDirty();
 
+		CM::Rect getVisibleBounds() const;
 		CM::Rect getContentBounds() const;
 
 		static GUILayoutOptions getDefaultLayoutOptions(const GUIElementStyle* style);

+ 0 - 1
BansheeEngine/Include/BsGUIInputBox.h

@@ -91,7 +91,6 @@ namespace BansheeEngine
 
 		CM::Int2 getTextOffset() const;
 		CM::Rect getTextClipRect() const;
-		CM::Rect getTextBounds() const;
 		TEXT_SPRITE_DESC getTextDesc() const;
 	};
 }

+ 0 - 1
BansheeEngine/Include/BsGUIToggle.h

@@ -58,7 +58,6 @@ namespace BansheeEngine
 		GUIToggle(GUIWidget& parent, const GUIElementStyle* style, const CM::WString& text, const GUILayoutOptions& layoutOptions);
 
 		virtual bool mouseEvent(const GUIMouseEvent& ev);
-		CM::Rect getTextBounds() const;
 		CM::Rect getTextClipRect() const;
 	};
 }

+ 3 - 17
BansheeEngine/Source/BsGUIButton.cpp

@@ -107,7 +107,7 @@ namespace BansheeEngine
 		textDesc.font = mStyle->font;
 		textDesc.fontSize = mStyle->fontSize;
 
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 
 		textDesc.width = textBounds.width;
 		textDesc.height = textBounds.height;
@@ -150,7 +150,7 @@ namespace BansheeEngine
 	{
 		if(renderElementIdx >= mNumImageRenderElements)
 		{
-			Rect textBounds = getTextBounds();
+			Rect textBounds = getContentBounds();
 			Int2 offset(textBounds.x, textBounds.y);
 			Rect textClipRect = getTextClipRect();
 
@@ -198,23 +198,9 @@ namespace BansheeEngine
 		return false;
 	}
 
-	Rect GUIButton::getTextBounds() const
-	{
-		Rect textBounds = mBounds;
-
-		textBounds.x += mStyle->margins.left + mStyle->contentOffset.left;
-		textBounds.y += mStyle->margins.top + mStyle->contentOffset.top;
-		textBounds.width = (UINT32)std::max(0, (INT32)textBounds.width - 
-			(INT32)(mStyle->margins.left + mStyle->margins.right + mStyle->contentOffset.left + mStyle->contentOffset.right));
-		textBounds.height = (UINT32)std::max(0, (INT32)textBounds.height - 
-			(INT32)(mStyle->margins.top + mStyle->margins.bottom + mStyle->contentOffset.top + mStyle->contentOffset.bottom));
-
-		return textBounds;
-	}
-
 	Rect GUIButton::getTextClipRect() const
 	{
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 
 		return Rect(0, 0, textBounds.width, textBounds.height);
 	}

+ 16 - 2
BansheeEngine/Source/BsGUIElement.cpp

@@ -104,7 +104,7 @@ namespace BansheeEngine
 		mClipRect = clipRect; 
 	}
 
-	Rect GUIElement::getContentBounds() const
+	Rect GUIElement::getVisibleBounds() const
 	{
 		Rect bounds = _getBounds();
 		
@@ -116,9 +116,23 @@ namespace BansheeEngine
 		return bounds;
 	}
 
+	Rect GUIElement::getContentBounds() const
+	{
+		Rect bounds;
+
+		bounds.x = mOffset.x + mStyle->margins.left + mStyle->contentOffset.left;
+		bounds.y = mOffset.y + mStyle->margins.top + mStyle->contentOffset.top;
+		bounds.width = (UINT32)std::max(0, (INT32)mWidth - 
+			(INT32)(mStyle->margins.left + mStyle->margins.right + mStyle->contentOffset.left + mStyle->contentOffset.right));
+		bounds.height = (UINT32)std::max(0, (INT32)mHeight - 
+			(INT32)(mStyle->margins.top + mStyle->margins.bottom + mStyle->contentOffset.top + mStyle->contentOffset.bottom));
+
+		return bounds;
+	}
+
 	bool GUIElement::_isInBounds(const CM::Int2 position) const
 	{
-		Rect contentBounds = getContentBounds();
+		Rect contentBounds = getVisibleBounds();
 
 		return contentBounds.contains(position);
 	}

+ 3 - 18
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -394,7 +394,6 @@ namespace BansheeEngine
 		}
 		else if(ev.getType() == GUIMouseEventType::MouseDrag)
 		{
-			Rect bounds = getTextBounds();
 			if(mText.size() > 0)
 				gGUIManager().getInputCaretTool()->moveCaretToPos(ev.getPosition());
 			else
@@ -734,30 +733,16 @@ namespace BansheeEngine
 
 	CM::Int2 GUIInputBox::getTextOffset() const
 	{
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 		return Int2(textBounds.x, textBounds.y) + mTextOffset;
 	}
 
 	CM::Rect GUIInputBox::getTextClipRect() const
 	{
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 		return Rect(-mTextOffset.x, -mTextOffset.y, textBounds.width, textBounds.height);
 	}
 
-	CM::Rect GUIInputBox::getTextBounds() const
-	{
-		Rect textBounds;
-
-		textBounds.x = mOffset.x + mStyle->margins.left + mStyle->contentOffset.left;
-		textBounds.y = mOffset.y + mStyle->margins.top + mStyle->contentOffset.top;
-		textBounds.width = (UINT32)std::max(0, (INT32)mWidth - 
-			(INT32)(mStyle->margins.left + mStyle->margins.right + mStyle->contentOffset.left + mStyle->contentOffset.right));
-		textBounds.height = (UINT32)std::max(0, (INT32)mHeight - 
-			(INT32)(mStyle->margins.top + mStyle->margins.bottom + mStyle->contentOffset.top + mStyle->contentOffset.bottom));
-
-		return textBounds;
-	}
-
 	TEXT_SPRITE_DESC GUIInputBox::getTextDesc() const
 	{
 		TEXT_SPRITE_DESC textDesc;
@@ -765,7 +750,7 @@ namespace BansheeEngine
 		textDesc.font = mStyle->font;
 		textDesc.fontSize = mStyle->fontSize;
 
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 		textDesc.width = textBounds.width;
 		textDesc.height = textBounds.height;
 		textDesc.horzAlign = mStyle->textHorzAlign;

+ 3 - 17
BansheeEngine/Source/BsGUIToggle.cpp

@@ -107,7 +107,7 @@ namespace BansheeEngine
 		textDesc.font = mStyle->font;
 		textDesc.fontSize = mStyle->fontSize;
 
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 
 		textDesc.width = textBounds.width;
 		textDesc.height = textBounds.height;
@@ -150,7 +150,7 @@ namespace BansheeEngine
 	{
 		if(renderElementIdx >= mNumImageRenderElements)
 		{
-			Rect textBounds = getTextBounds();
+			Rect textBounds = getContentBounds();
 			Int2 offset(textBounds.x, textBounds.y);
 			Rect textClipRect = getTextClipRect();
 
@@ -212,23 +212,9 @@ namespace BansheeEngine
 		return false;
 	}
 
-	CM::Rect GUIToggle::getTextBounds() const
-	{
-		Rect textBounds = mBounds;
-
-		textBounds.x += mStyle->margins.left + mStyle->contentOffset.left;
-		textBounds.y += mStyle->margins.top + mStyle->contentOffset.top;
-		textBounds.width = (UINT32)std::max(0, (INT32)textBounds.width - 
-			(INT32)(mStyle->margins.left + mStyle->margins.right + mStyle->contentOffset.left + mStyle->contentOffset.right));
-		textBounds.height = (UINT32)std::max(0, (INT32)textBounds.height - 
-			(INT32)(mStyle->margins.top + mStyle->margins.bottom + mStyle->contentOffset.top + mStyle->contentOffset.bottom));
-
-		return textBounds;
-	}
-
 	CM::Rect GUIToggle::getTextClipRect() const
 	{
-		Rect textBounds = getTextBounds();
+		Rect textBounds = getContentBounds();
 
 		return Rect(0, 0, textBounds.width, textBounds.height);
 	}

+ 3 - 3
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -189,7 +189,7 @@ namespace BansheeEngine
 
 	bool GUIWindowFrame::_isInBounds(const CM::Int2 position) const
 	{
-		Rect contentBounds = getContentBounds();
+		Rect contentBounds = getVisibleBounds();
 
 		if(!contentBounds.contains(position))
 			return false;
@@ -221,7 +221,7 @@ namespace BansheeEngine
 	{
 		if(ev.getType() == GUIMouseEventType::MouseMove || ev.getType() == GUIMouseEventType::MouseDrag)
 		{
-			Rect contentBounds = getContentBounds();
+			Rect contentBounds = getVisibleBounds();
 
 			FrameSubArea subArea = getFrameSubArea(ev.getPosition(), contentBounds);
 			if(subArea != FrameSubArea::None && subArea != FrameSubArea::Middle)
@@ -262,7 +262,7 @@ namespace BansheeEngine
 
 		if(ev.getType() == GUIMouseEventType::MouseDown)
 		{
-			Rect contentBounds = getContentBounds();
+			Rect contentBounds = getVisibleBounds();
 
 			FrameSubArea subArea = getFrameSubArea(ev.getPosition(), contentBounds);
 			if(subArea != FrameSubArea::None && subArea != FrameSubArea::Middle)

+ 1 - 4
TODO.txt

@@ -31,10 +31,7 @@ TextBox needed elements:
  - Cut/Copy/Paste
  - All classes dealing with text (Button, Toggle, Label, InputBox) determine text field size based on mBounds which is calculated from 
     clipped mImageSprite coordinates. Which is wrong because text word wrap will change depending how clipped the sprite is.
- - Don't forget to make the classes input/selection singletons
- - Elements need TWO different dirty flags. Right now setting dirty causes both content update and fillBuffer update.
-   - But I'd like only fillBuffer update when element is moved, or clipped as content update may be expensive
-   - I added separate clip/offset params to sprites but haven't added these dirty flags yet!
+
 
  - LATER
   - TAB between input elements