Quellcode durchsuchen

Added tree-view scrollToElement
Fixed ScrollArea scroll* methods

Marko Pintera vor 12 Jahren
Ursprung
Commit
4d538b5d91

+ 4 - 4
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -290,7 +290,7 @@ namespace BansheeEngine
 	{
 	{
 		if(mVertScroll != nullptr)
 		if(mVertScroll != nullptr)
 		{
 		{
-			UINT32 scrollableSize = mVertScroll->getScrollableSize();
+			UINT32 scrollableSize = (UINT32)std::max(0, INT32(mContentHeight) - INT32(mClippedContentHeight));
 
 
 			float offset = 0.0f;
 			float offset = 0.0f;
 			if(scrollableSize > 0)
 			if(scrollableSize > 0)
@@ -304,7 +304,7 @@ namespace BansheeEngine
 	{
 	{
 		if(mVertScroll != nullptr)
 		if(mVertScroll != nullptr)
 		{
 		{
-			UINT32 scrollableSize = mVertScroll->getScrollableSize();
+			UINT32 scrollableSize = (UINT32)std::max(0, INT32(mContentHeight) - INT32(mClippedContentHeight));
 
 
 			float offset = 0.0f;
 			float offset = 0.0f;
 			if(scrollableSize > 0)
 			if(scrollableSize > 0)
@@ -318,7 +318,7 @@ namespace BansheeEngine
 	{
 	{
 		if(mHorzScroll != nullptr)
 		if(mHorzScroll != nullptr)
 		{
 		{
-			UINT32 scrollableSize = mHorzScroll->getScrollableSize();
+			UINT32 scrollableSize = (UINT32)std::max(0, INT32(mContentWidth) - INT32(mClippedContentWidth));
 
 
 			float offset = 0.0f;
 			float offset = 0.0f;
 			if(scrollableSize > 0)
 			if(scrollableSize > 0)
@@ -332,7 +332,7 @@ namespace BansheeEngine
 	{
 	{
 		if(mHorzScroll != nullptr)
 		if(mHorzScroll != nullptr)
 		{
 		{
-			UINT32 scrollableSize = mHorzScroll->getScrollableSize();
+			UINT32 scrollableSize = (UINT32)std::max(0, INT32(mContentWidth) - INT32(mClippedContentWidth));
 
 
 			float offset = 0.0f;
 			float offset = 0.0f;
 			if(scrollableSize > 0)
 			if(scrollableSize > 0)

+ 1 - 0
CamelotClient/Include/BsGUISceneTreeView.h

@@ -164,6 +164,7 @@ namespace BansheeEditor
 		void unselectAll();
 		void unselectAll();
 
 
 		void temporarilyExpandElement(const GUISceneTreeView::InteractableElement* mouseOverElement);
 		void temporarilyExpandElement(const GUISceneTreeView::InteractableElement* mouseOverElement);
+		void scrollToElement(TreeElement* element, bool center);
 
 
 		BS::GUIScrollArea* findParentScrollArea() const;
 		BS::GUIScrollArea* findParentScrollArea() const;
 
 

+ 43 - 2
CamelotClient/Source/BsGUISceneTreeView.cpp

@@ -667,7 +667,9 @@ namespace BansheeEditor
 					if(ev.getType() == GUICommandEventType::CursorMoveUp)
 					if(ev.getType() == GUICommandEventType::CursorMoveUp)
 						unselectAll();
 						unselectAll();
 
 
-					selectElement(topMostIter->getTreeElement());
+					TreeElement* treeElement = topMostIter->getTreeElement();
+					selectElement(treeElement);
+					scrollToElement(treeElement, false);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -689,7 +691,9 @@ namespace BansheeEditor
 					if(ev.getType() == GUICommandEventType::CursorMoveDown)
 					if(ev.getType() == GUICommandEventType::CursorMoveDown)
 						unselectAll();
 						unselectAll();
 
 
-					selectElement(bottomMostIter->getTreeElement());
+					TreeElement* treeElement = bottomMostIter->getTreeElement();
+					selectElement(treeElement);
+					scrollToElement(treeElement, false);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -1226,6 +1230,43 @@ namespace BansheeEditor
 		}
 		}
 	}
 	}
 
 
+	void GUISceneTreeView::scrollToElement(TreeElement* element, bool center)
+	{
+		if(element->mElement == nullptr)
+			return;
+
+		GUIScrollArea* scrollArea = findParentScrollArea();
+		if(scrollArea == nullptr)
+			return;
+
+		if(center)
+		{
+			RectI myBounds = _getClippedBounds();
+			INT32 clipVertCenter = myBounds.y + (INT32)Math::roundToInt(myBounds.height * 0.5f);
+			INT32 elemVertCenter = element->mElement->_getOffset().y + (INT32)Math::roundToInt(element->mElement->_getHeight() * 0.5f);
+
+			if(elemVertCenter > clipVertCenter)
+				scrollArea->scrollUpPx(elemVertCenter - clipVertCenter);
+			else
+				scrollArea->scrollDownPx(clipVertCenter - elemVertCenter);
+		}
+		else
+		{
+			RectI myBounds = _getClippedBounds();
+			INT32 elemVertTop = element->mElement->_getOffset().y;
+			INT32 elemVertBottom = element->mElement->_getOffset().y + element->mElement->_getHeight();
+
+			INT32 top = myBounds.y;
+			INT32 bottom = myBounds.y + myBounds.height;
+
+			INT32 offset = 0;
+			if(elemVertTop < top)
+				scrollArea->scrollUpPx(top - elemVertTop);
+			else if(elemVertBottom > bottom)
+				scrollArea->scrollDownPx(elemVertBottom - bottom);
+		}
+	}
+
 	GUIScrollArea* GUISceneTreeView::findParentScrollArea() const
 	GUIScrollArea* GUISceneTreeView::findParentScrollArea() const
 	{
 	{
 		GUIElementBase* parent = _getParent();
 		GUIElementBase* parent = _getParent();