Ver Fonte

Scroll bar no longer jumps a few pixels when you click on it

Marko Pintera há 12 anos atrás
pai
commit
64b516b010

+ 2 - 2
BansheeEngine/Include/BsGUIScrollArea.h

@@ -58,8 +58,8 @@ namespace BansheeEngine
 		GUIScrollBarVert* mVertScroll;
 		GUIScrollBarHorz* mHorzScroll;
 
-		CM::INT32 mVertOffset;
-		CM::INT32 mHorzOffset;
+		float mVertOffset;
+		float mHorzOffset;
 
 		CM::UINT32 mContentWidth, mContentHeight;
 

+ 1 - 1
BansheeEngine/Include/BsGUIScrollBarHandle.h

@@ -66,7 +66,7 @@ namespace BansheeEngine
 		CM::UINT32 mHandleSize;
 		SpriteTexturePtr mCurTexture;
 		bool mHorizontal; // Otherwise its vertical
-		CM::INT32 mHandlePos;
+		float mHandlePos;
 		CM::INT32 mDragStartPos;
 		bool mMouseOverHandle;
 		bool mHandleDragged;

+ 9 - 7
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -81,7 +81,8 @@ namespace BansheeEngine
 			UINT32 contentWidth = (UINT32)std::max(0, (INT32)width - (INT32)ScrollBarWidth);
 
 			Rect layoutClipRect(clipRect.x, clipRect.y, contentWidth, clipRect.height);
-			mContentLayout->_updateLayoutInternal(x, y - mVertOffset, contentWidth, height + mVertOffset, layoutClipRect, widgetDepth, areaDepth);
+			mContentLayout->_updateLayoutInternal(x, y - Math::FloorToInt(mVertOffset), contentWidth, height + Math::FloorToInt(mVertOffset), 
+				layoutClipRect, widgetDepth, areaDepth);
 			contentWidth = mContentLayout->_getActualWidth();
 			contentHeight = mContentLayout->_getActualHeight();
 
@@ -111,7 +112,7 @@ namespace BansheeEngine
 			newHandleSize = std::max(newHandleSize, MinHandleSize);
 
 			UINT32 scrollableHeight = (UINT32)std::max(0, INT32(contentHeight) - INT32(mHeight));
-			float newScrollPct = mVertOffset / (float)scrollableHeight;
+			float newScrollPct = mVertOffset / scrollableHeight;
 
 			mVertScroll->setHandleSize(newHandleSize);
 			mVertScroll->setScrollPos(newScrollPct);
@@ -127,12 +128,13 @@ namespace BansheeEngine
 
 		// Add/remove/update horizontal scrollbar as needed
 		if(contentWidth > mWidth)
-		{
+		{ 
 			// Make room for scrollbar
 			UINT32 contentHeight = (UINT32)std::max(0, (INT32)height - (INT32)ScrollBarWidth);
 
 			Rect layoutClipRect(clipRect.x, clipRect.y, clipRect.width, contentHeight);
-			mContentLayout->_updateLayoutInternal(x - mHorzOffset, y, width + mHorzOffset, contentHeight, layoutClipRect, widgetDepth, areaDepth);
+			mContentLayout->_updateLayoutInternal(x - Math::FloorToInt(mHorzOffset), y, width + Math::FloorToInt(mHorzOffset), 
+				contentHeight, layoutClipRect, widgetDepth, areaDepth);
 			contentWidth = mContentLayout->_getActualWidth();
 			contentHeight = mContentLayout->_getActualHeight();
 
@@ -162,7 +164,7 @@ namespace BansheeEngine
 			newHandleSize = std::max(newHandleSize, MinHandleSize);
 
 			UINT32 scrollableWidth = (UINT32)std::max(0, INT32(contentWidth) - INT32(mWidth));
-			float newScrollPct = mHorzOffset / (float)scrollableWidth;
+			float newScrollPct = mHorzOffset / scrollableWidth;
 
 			mHorzScroll->setHandleSize(newHandleSize);
 			mHorzScroll->setScrollPos(newScrollPct);
@@ -183,7 +185,7 @@ namespace BansheeEngine
 	void GUIScrollArea::vertScrollUpdate(float scrollPos)
 	{
 		UINT32 scrollableHeight = (UINT32)std::max(0, INT32(mContentHeight) - INT32(mHeight));
-		mVertOffset = Math::FloorToInt(scrollableHeight * scrollPos);
+		mVertOffset = scrollableHeight * scrollPos;
 
 		markContentAsDirty();
 	}
@@ -191,7 +193,7 @@ namespace BansheeEngine
 	void GUIScrollArea::horzScrollUpdate(float scrollPos)
 	{
 		UINT32 scrollableWidth = (UINT32)std::max(0, INT32(mContentWidth) - INT32(mWidth));
-		mHorzOffset = Math::FloorToInt(scrollableWidth * scrollPos);
+		mHorzOffset = scrollableWidth * scrollPos;
 
 		markContentAsDirty();
 	}

+ 22 - 19
BansheeEngine/Source/BsGUIScrollBarHandle.cpp

@@ -6,6 +6,7 @@
 #include "BsTextSprite.h"
 #include "BsGUILayoutOptions.h"
 #include "BsGUIMouseEvent.h"
+#include "CmDebug.h"
 #include "CmTexture.h"
 
 using namespace CamelotFramework;
@@ -61,8 +62,10 @@ namespace BansheeEngine
 
 	void GUIScrollBarHandle::setHandlePos(float pct)
 	{
+		pct = Math::Clamp01(pct);
+
 		UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
-		mHandlePos = Math::FloorToInt(pct * maxScrollAmount);
+		mHandlePos = pct * maxScrollAmount;
 
 		markContentAsDirty();
 	}
@@ -70,7 +73,7 @@ namespace BansheeEngine
 	float GUIScrollBarHandle::getHandlePos() const
 	{
 		UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
-		return (float)mHandlePos / maxScrollAmount;
+		return mHandlePos / maxScrollAmount;
 	}
 
 	UINT32 GUIScrollBarHandle::getScrollableSize() const
@@ -147,15 +150,15 @@ namespace BansheeEngine
 	{
 		Int2 offset = mOffset;
 		if(mHorizontal)
-			offset.x += mHandlePos;
+			offset.x += Math::FloorToInt(mHandlePos);
 		else
-			offset.y += mHandlePos;
+			offset.y += Math::FloorToInt(mHandlePos);
 
 		Rect clipRect = mClipRect;
 		if(mHorizontal)
-			clipRect.x -= mHandlePos;
+			clipRect.x -= Math::FloorToInt(mHandlePos);
 		else
-			clipRect.y -= mHandlePos;
+			clipRect.y -= Math::FloorToInt(mHandlePos);
 
 		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, 
 			vertexStride, indexStride, renderElementIdx, offset, clipRect);
@@ -198,12 +201,12 @@ namespace BansheeEngine
 
 			if(mHorizontal)
 			{
-				INT32 left = (INT32)mOffset.x + mHandlePos;
+				INT32 left = (INT32)mOffset.x + Math::FloorToInt(mHandlePos);
 				mDragStartPos = ev.getPosition().x - left;
 			}
 			else
 			{
-				INT32 top = (INT32)mOffset.y + mHandlePos;
+				INT32 top = (INT32)mOffset.y + Math::FloorToInt(mHandlePos);
 				mDragStartPos = ev.getPosition().y - top;
 			}
 
@@ -215,19 +218,19 @@ namespace BansheeEngine
 		{
 			if(mHorizontal)
 			{
-				mHandlePos = ev.getPosition().x - mDragStartPos - mOffset.x;
+				mHandlePos = (float)(ev.getPosition().x - mDragStartPos - mOffset.x);
 			}
 			else
 			{
-				mHandlePos = ev.getPosition().y - mDragStartPos - mOffset.y;
+				mHandlePos = float(ev.getPosition().y - mDragStartPos - mOffset.y);
 			}
 
-			UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
-			mHandlePos = Math::Clamp(mHandlePos, 0, (INT32)maxScrollAmount);
+			float maxScrollAmount = (float)getMaxSize() - mHandleSize;
+			mHandlePos = Math::Clamp(mHandlePos, 0.0f, maxScrollAmount);
 
 			if(!onHandleMoved.empty())
 			{
-				float pct = (float)mHandlePos / maxScrollAmount;
+				float pct = mHandlePos / maxScrollAmount;
 				onHandleMoved(pct);
 			}
 
@@ -254,7 +257,7 @@ namespace BansheeEngine
 			INT32 handleOffset = 0;
 			if(mHorizontal)
 			{
-				INT32 handleLeft = (INT32)mOffset.x + mHandlePos;
+				INT32 handleLeft = (INT32)mOffset.x + Math::FloorToInt(mHandlePos);
 				INT32 handleRight = handleLeft + mHandleSize;
 
 				if(ev.getPosition().x < handleLeft)
@@ -264,7 +267,7 @@ namespace BansheeEngine
 			}
 			else
 			{
-				INT32 handleTop = (INT32)mOffset.y + mHandlePos;
+				INT32 handleTop = (INT32)mOffset.y + Math::FloorToInt(mHandlePos);
 				INT32 handleBottom = handleTop + mHandleSize;
 
 				if(ev.getPosition().y < handleTop)
@@ -274,8 +277,8 @@ namespace BansheeEngine
 			}
 
 			mHandlePos += handleOffset;
-			UINT32 maxScrollAmount = getMaxSize() - mHandleSize;
-			mHandlePos = Math::Clamp(mHandlePos, 0, (INT32)maxScrollAmount);
+			float maxScrollAmount = (float)getMaxSize() - mHandleSize;
+			mHandlePos = Math::Clamp(mHandlePos, 0.0f, maxScrollAmount);
 
 			if(!onHandleMoved.empty())
 			{
@@ -307,7 +310,7 @@ namespace BansheeEngine
 	{
 		if(mHorizontal)
 		{
-			INT32 left = (INT32)mOffset.x + mHandlePos;
+			INT32 left = (INT32)mOffset.x + Math::FloorToInt(mHandlePos);
 			INT32 right = left + mHandleSize;
 
 			if(pos.x >= left && pos.x < right)
@@ -315,7 +318,7 @@ namespace BansheeEngine
 		}
 		else
 		{
-			INT32 top = (INT32)mOffset.y + mHandlePos;
+			INT32 top = (INT32)mOffset.y + Math::FloorToInt(mHandlePos);
 			INT32 bottom = top + mHandleSize;
 
 			if(pos.y >= top && pos.y < bottom)

+ 0 - 4
CamelotUtility/Source/CmLog.cpp

@@ -52,10 +52,6 @@ namespace CamelotFramework
 			return;
 
 		// TODO - Write to disk and throw exception if it can't
-		
-		//OGRE_EXCEPT(::Ogre::Exception::ERR_INTERNAL_ERROR, 
-		//	"Cannot create log file at " + mSaveFilePath,
-		//	"Log::save()");
 	}
 
 	void Log::doOnEntryAdded(const LogEntry& entry)

+ 3 - 1
TODO.txt

@@ -31,7 +31,9 @@ IMMEDIATE:
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
 - Test if horizontal + vert scroll works together
-- After resize scroll bar buttons don't work
+- InputBox text clip rect is probably wrong as it doesn't account parent element clip rect
+ (possibly selection and caret clip rects too)
+- Dragging a scrollbar and then releasing it offsets it a tiny bit
 - Scroll bar doesn't update its hover state properly (or its perpetually in hover state).
 - Hover colors of the scroll bar are wrong