Przeglądaj źródła

Fixed text clip rectangles

Marko Pintera 12 lat temu
rodzic
commit
fd09241095

+ 0 - 1
BansheeEngine/Include/BsGUIButton.h

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

+ 1 - 0
BansheeEngine/Include/BsGUIElement.h

@@ -114,6 +114,7 @@ namespace BansheeEngine
 		
 		CM::Rect getVisibleBounds() const;
 		CM::Rect getContentBounds() const;
+		CM::Rect getContentClipRect() const;
 
 		static GUILayoutOptions getDefaultLayoutOptions(const GUIElementStyle* style);
 

+ 0 - 1
BansheeEngine/Include/BsGUIToggle.h

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

+ 1 - 8
BansheeEngine/Source/BsGUIButton.cpp

@@ -152,7 +152,7 @@ namespace BansheeEngine
 		{
 			Rect textBounds = getContentBounds();
 			Int2 offset(textBounds.x, textBounds.y);
-			Rect textClipRect = getTextClipRect();
+			Rect textClipRect = getContentClipRect();
 
 			mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, 
 			vertexStride, indexStride, mNumImageRenderElements - renderElementIdx, offset, textClipRect);
@@ -200,11 +200,4 @@ namespace BansheeEngine
 		
 		return false;
 	}
-
-	Rect GUIButton::getTextClipRect() const
-	{
-		Rect textBounds = getContentBounds();
-
-		return Rect(0, 0, textBounds.width, textBounds.height);
-	}
 }

+ 16 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -130,6 +130,22 @@ namespace BansheeEngine
 		return bounds;
 	}
 
+	Rect GUIElement::getContentClipRect() const
+	{
+		Rect contentBounds = getContentBounds();
+		
+		// Transform into element space so we can clip it using the element clip rectangle
+		Int2 offsetDiff = Int2(contentBounds.x - mOffset.x, contentBounds.y - mOffset.y);
+		Rect contentClipRect(offsetDiff.x, offsetDiff.y, contentBounds.width, contentBounds.height);
+		contentClipRect.clip(mClipRect);
+
+		// Transform into text sprite space
+		contentClipRect.x -= offsetDiff.x;
+		contentClipRect.y -= offsetDiff.y;
+
+		return contentClipRect;
+	}
+
 	bool GUIElement::_isInBounds(const CM::Int2 position) const
 	{
 		Rect contentBounds = getVisibleBounds();

+ 1 - 8
BansheeEngine/Source/BsGUIToggle.cpp

@@ -152,7 +152,7 @@ namespace BansheeEngine
 		{
 			Rect textBounds = getContentBounds();
 			Int2 offset(textBounds.x, textBounds.y);
-			Rect textClipRect = getTextClipRect();
+			Rect textClipRect = getContentClipRect();
 
 			mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, 
 				vertexStride, indexStride, mNumImageRenderElements - renderElementIdx, offset, textClipRect);
@@ -215,11 +215,4 @@ namespace BansheeEngine
 
 		return false;
 	}
-
-	CM::Rect GUIToggle::getTextClipRect() const
-	{
-		Rect textBounds = getContentBounds();
-
-		return Rect(0, 0, textBounds.width, textBounds.height);
-	}
 }

+ 3 - 0
TODO.txt

@@ -32,6 +32,9 @@ IMMEDIATE:
 
 - Seems the mouse-over bounds aren't right on the Tab button (I can't select it if I mouse over the bottom part)
 - When clipping scrolled GUIButton the text doesn't seem to get clipped properly
+- Test if horizontal + vert scroll works together
+- After resize scroll bar buttons don't work
+- Scroll bar doesn't update its hover state properly (or its perpetually in hover state).
 - Hover colors of the scroll bar are wrong
 
 TextBox needed elements: