Просмотр исходного кода

Auto-expand elements we're dragging over

Marko Pintera 12 лет назад
Родитель
Сommit
646beef809
3 измененных файлов с 38 добавлено и 2 удалено
  1. 4 0
      CamelotClient/Include/BsGUISceneTreeView.h
  2. 33 1
      CamelotClient/Source/BsGUISceneTreeView.cpp
  3. 1 1
      TreeView.txt

+ 4 - 0
CamelotClient/Include/BsGUISceneTreeView.h

@@ -93,6 +93,7 @@ namespace BansheeEditor
 		static const CM::UINT32 INDENT_SIZE;
 		static const CM::UINT32 INDENT_SIZE;
 		static const CM::UINT32 INITIAL_INDENT_OFFSET;
 		static const CM::UINT32 INITIAL_INDENT_OFFSET;
 		static const CM::UINT32 DRAG_MIN_DISTANCE;
 		static const CM::UINT32 DRAG_MIN_DISTANCE;
+		static const float AUTO_EXPAND_DELAY_SEC;
 
 
 		const BS::GUIElementStyle* mBackgroundStyle;
 		const BS::GUIElementStyle* mBackgroundStyle;
 		const BS::GUIElementStyle* mElementBtnStyle;
 		const BS::GUIElementStyle* mElementBtnStyle;
@@ -120,6 +121,9 @@ namespace BansheeEditor
 		BS::GUITexture* mDragHighlight;
 		BS::GUITexture* mDragHighlight;
 		BS::GUITexture* mDragSepHighlight;
 		BS::GUITexture* mDragSepHighlight;
 
 
+		TreeElement* mMouseOverDragElement;
+		float mMouseOverDragElementTime;
+
 		GUISceneTreeView(BS::GUIWidget& parent, BS::GUIElementStyle* backgroundStyle, BS::GUIElementStyle* elementBtnStyle, 
 		GUISceneTreeView(BS::GUIWidget& parent, BS::GUIElementStyle* backgroundStyle, BS::GUIElementStyle* elementBtnStyle, 
 			BS::GUIElementStyle* foldoutBtnStyle, BS::GUIElementStyle* selectionBackgroundStyle, BS::GUIElementStyle* editBoxStyle, 
 			BS::GUIElementStyle* foldoutBtnStyle, BS::GUIElementStyle* selectionBackgroundStyle, BS::GUIElementStyle* editBoxStyle, 
 			BS::GUIElementStyle* dragHighlightStyle, BS::GUIElementStyle* dragSepHighlightStyle, const BS::GUILayoutOptions& layoutOptions);
 			BS::GUIElementStyle* dragHighlightStyle, BS::GUIElementStyle* dragSepHighlightStyle, const BS::GUILayoutOptions& layoutOptions);

+ 33 - 1
CamelotClient/Source/BsGUISceneTreeView.cpp

@@ -16,6 +16,7 @@
 #include "BsCmdEditPlainFieldGO.h"
 #include "BsCmdEditPlainFieldGO.h"
 #include "BsDragAndDropManager.h"
 #include "BsDragAndDropManager.h"
 #include "BsCmdReparentSO.h"
 #include "BsCmdReparentSO.h"
+#include "CmTime.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 using namespace BansheeEngine;
 using namespace BansheeEngine;
@@ -26,6 +27,7 @@ namespace BansheeEditor
 	const UINT32 GUISceneTreeView::INDENT_SIZE = 10;
 	const UINT32 GUISceneTreeView::INDENT_SIZE = 10;
 	const UINT32 GUISceneTreeView::INITIAL_INDENT_OFFSET = 16;
 	const UINT32 GUISceneTreeView::INITIAL_INDENT_OFFSET = 16;
 	const UINT32 GUISceneTreeView::DRAG_MIN_DISTANCE = 3;
 	const UINT32 GUISceneTreeView::DRAG_MIN_DISTANCE = 3;
+	const float GUISceneTreeView::AUTO_EXPAND_DELAY_SEC = 0.5f;
 
 
 	GUISceneTreeView::DraggedSceneObjects::DraggedSceneObjects(UINT32 numObjects)
 	GUISceneTreeView::DraggedSceneObjects::DraggedSceneObjects(UINT32 numObjects)
 		:numObjects(numObjects)
 		:numObjects(numObjects)
@@ -64,7 +66,7 @@ namespace BansheeEditor
 		:GUIElementContainer(parent, layoutOptions), mBackgroundStyle(backgroundStyle),
 		:GUIElementContainer(parent, layoutOptions), mBackgroundStyle(backgroundStyle),
 		mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr), mIsElementSelected(false),
 		mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr), mIsElementSelected(false),
 		mNameEditBox(nullptr), mSelectionBackgroundStyle(selectionBackgroundStyle), mDragInProgress(nullptr), mDragHighlightStyle(dragHighlightStyle),
 		mNameEditBox(nullptr), mSelectionBackgroundStyle(selectionBackgroundStyle), mDragInProgress(nullptr), mDragHighlightStyle(dragHighlightStyle),
-		mDragSepHighlightStyle(dragSepHighlightStyle), mDragHighlight(nullptr), mDragSepHighlight(nullptr)
+		mDragSepHighlightStyle(dragSepHighlightStyle), mDragHighlight(nullptr), mDragSepHighlight(nullptr), mMouseOverDragElement(nullptr), mMouseOverDragElementTime(0.0f)
 	{
 	{
 		if(mBackgroundStyle == nullptr)
 		if(mBackgroundStyle == nullptr)
 			mBackgroundStyle = parent.getSkin().getStyle("TreeViewBackground");
 			mBackgroundStyle = parent.getSkin().getStyle("TreeViewBackground");
@@ -129,6 +131,36 @@ namespace BansheeEditor
 
 
 	void GUISceneTreeView::update()
 	void GUISceneTreeView::update()
 	{
 	{
+		// Attempt to auto-expand elements we are dragging over
+		if(DragAndDropManager::instance().isDragInProgress() && DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::SceneObject)
+		{
+			const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(mDragPosition);
+			if(element == nullptr || !element->isTreeElement())
+			{
+				mMouseOverDragElementTime = gTime().getTime();
+				mMouseOverDragElement = nullptr;
+			}
+			else
+			{
+				TreeElement* treeElement = element->getTreeElement();
+
+				if(mMouseOverDragElement == treeElement)
+				{
+					float timeDiff = gTime().getTime() - mMouseOverDragElementTime;
+					if(timeDiff >= AUTO_EXPAND_DELAY_SEC)
+					{
+						if(mMouseOverDragElement != nullptr)
+							mMouseOverDragElement->mIsExpanded = true;
+					}
+				}
+				else
+				{
+					mMouseOverDragElementTime = gTime().getTime();
+					mMouseOverDragElement = treeElement;
+				}
+			}
+		}
+
 		// NOTE - Instead of iterating through every visible element and comparing it with internal values,
 		// NOTE - Instead of iterating through every visible element and comparing it with internal values,
 		// I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
 		// I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
 		// update if anything is actually dirty
 		// update if anything is actually dirty

+ 1 - 1
TreeView.txt

@@ -1,7 +1,7 @@
 TODO:
 TODO:
  - Callback on tree item select
  - Callback on tree item select
  - When dragging in tree view automatically expand mouse over elements
  - When dragging in tree view automatically expand mouse over elements
- - Ability to move selection via arrow keys
+ - When I select elements in tree view via arrow keys, make sure to automatically scroll the scroll-area so that element becomes visible
  - Context menu with rename/copy/paste/duplicate
  - Context menu with rename/copy/paste/duplicate
  - Delete with Undo/Redo support
  - Delete with Undo/Redo support
  - Auto scroll
  - Auto scroll