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

Int/Float field drag to increment/decrement works again
Drag events can now retrieve drag origin point
Fixed a minor issue where cursor could change while element is being dragged

Marko Pintera 10 лет назад
Родитель
Сommit
2b0aadfb00

+ 5 - 5
BansheeEditor/Include/BsGUIFloatField.h

@@ -22,17 +22,17 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GUIElement::setTint
 		 */
-		virtual void setTint(const Color& color);
+		virtual void setTint(const Color& color) override;
 
 		Event<void(float)> onValueChanged;
 	protected:
 		virtual ~GUIFloatField();
 
-		void updateClippedBounds();
+		void updateClippedBounds() override;
 
-		bool _hasCustomCursor(const Vector2I position, CursorType& type) const;
-		virtual bool mouseEvent(const GUIMouseEvent& ev);
-		void styleUpdated();
+		bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
+		virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
+		void styleUpdated() override;
 
 		void valueChanged(const WString& newValue);
 		void focusGained();

+ 5 - 5
BansheeEditor/Include/BsGUIIntField.h

@@ -23,17 +23,17 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GUIElement::setTint
 		 */
-		virtual void setTint(const Color& color);
+		virtual void setTint(const Color& color) override;
 
 		Event<void(INT32)> onValueChanged;
 	protected:
 		virtual ~GUIIntField();
 
-		void updateClippedBounds();
+		void updateClippedBounds() override;
 
-		bool _hasCustomCursor(const Vector2I position, CursorType& type) const;
-		virtual bool mouseEvent(const GUIMouseEvent& ev);
-		void styleUpdated();
+		bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
+		bool _mouseEvent(const GUIMouseEvent& ev)  override;
+		void styleUpdated() override;
 
 		void valueChanged(const WString& newValue);
 		void focusGained();

+ 2 - 2
BansheeEditor/Source/BsGUIFloatField.cpp

@@ -57,7 +57,7 @@ namespace BansheeEngine
 		return false;
 	}
 
-	bool GUIFloatField::mouseEvent(const GUIMouseEvent& event)
+	bool GUIFloatField::_mouseEvent(const GUIMouseEvent& event)
 	{
 		GUIElementContainer::_mouseEvent(event);
 
@@ -68,7 +68,7 @@ namespace BansheeEngine
 
 		if(event.getType() == GUIMouseEventType::MouseDragStart)
 		{
-			if(draggableArea.contains(event.getPosition()))
+			if(draggableArea.contains(event.getDragStartPosition()))
 			{
 				mLastDragPos = event.getPosition().x;
 				mIsDragging = true;

+ 2 - 2
BansheeEditor/Source/BsGUIIntField.cpp

@@ -59,7 +59,7 @@ namespace BansheeEngine
 		return false;
 	}
 
-	bool GUIIntField::mouseEvent(const GUIMouseEvent& event)
+	bool GUIIntField::_mouseEvent(const GUIMouseEvent& event)
 	{
 		GUIElementContainer::_mouseEvent(event);
 
@@ -70,7 +70,7 @@ namespace BansheeEngine
 
 		if(event.getType() == GUIMouseEventType::MouseDragStart)
 		{
-			if(draggableArea.contains(event.getPosition()))
+			if(draggableArea.contains(event.getDragStartPosition()))
 			{
 				mLastDragPos = event.getPosition().x;
 				mIsDragging = true;

+ 1 - 0
BansheeEngine/Include/BsGUIManager.h

@@ -386,6 +386,7 @@ namespace BansheeEngine
 
 		DragState mDragState;
 		Vector2I mLastPointerClickPos;
+		Vector2I mDragStartPos;
 
 		GUIMouseEvent mMouseEvent;
 		GUITextInputEvent mTextInputEvent;

+ 8 - 2
BansheeEngine/Include/BsGUIMouseEvent.h

@@ -66,6 +66,11 @@ namespace BansheeEngine
 		 */
 		Vector2I getDragAmount() const { return mDragAmount; }
 
+		/**
+		 * @brief	Returns the position where the drag was started from, if event is drag related.
+		 */
+		Vector2I getDragStartPosition() const { return mDragStartPosition; }
+
 		/**
 		 * @brief	Returns amount of mouse wheel scroll, if event is scroll wheel related.
 		 */
@@ -141,12 +146,12 @@ namespace BansheeEngine
 		/**
 		 * @brief	Initializes the event with MouseDrag event data.
 		 */
-		void setMouseDragData(const Vector2I& position, const Vector2I& dragAmount);
+		void setMouseDragData(const Vector2I& position, const Vector2I& dragStartPosition);
 
 		/**
 		 * @brief	Initializes the event with MouseDragStart event data.
 		 */
-		void setMouseDragStartData(const Vector2I& position);
+		void setMouseDragStartData(const Vector2I& position, const Vector2I& dragStartPosition);
 		/**
 		 * @brief	Initializes the event with MouseDragEnd event data.
 		 */
@@ -169,6 +174,7 @@ namespace BansheeEngine
 
 		bool mButtonStates[(int)GUIMouseButton::Count];
 		Vector2I mPosition;
+		Vector2I mDragStartPosition;
 		Vector2I mDragAmount;
 		float mWheelScrollAmount;
 		GUIMouseEventType mType;

+ 13 - 10
BansheeEngine/Source/BsGUIManager.cpp

@@ -680,13 +680,15 @@ namespace BansheeEngine
 				for(auto& activeElement : mActiveElements)
 				{
 					Vector2I localPos = getWidgetRelativePos(*activeElement.widget, event.screenPos);
+					Vector2I localDragStartPos = getWidgetRelativePos(*activeElement.widget, mLastPointerClickPos);
 
-					mMouseEvent.setMouseDragStartData(localPos);
+					mMouseEvent.setMouseDragStartData(localPos, localDragStartPos);
 					if(sendMouseEvent(activeElement.widget, activeElement.element, mMouseEvent))
 						event.markAsUsed();
 				}
 
 				mDragState = DragState::Dragging;
+				mDragStartPos = event.screenPos;
 			}
 		}
 
@@ -699,7 +701,7 @@ namespace BansheeEngine
 				{
 					Vector2I localPos = getWidgetRelativePos(*activeElement.widget, event.screenPos);
 
-					mMouseEvent.setMouseDragData(localPos, localPos - mLastPointerScreenPos);
+					mMouseEvent.setMouseDragData(localPos, event.screenPos - mDragStartPos);
 					if(sendMouseEvent(activeElement.widget, activeElement.element, mMouseEvent))
 						event.markAsUsed();
 				}
@@ -767,13 +769,10 @@ namespace BansheeEngine
 						moveProcessed = sendMouseEvent(elementInfo.widget, elementInfo.element, mMouseEvent);
 
 						if(moveProcessed)
-						{
 							event.markAsUsed();
-							break;
-						}
 					}
 
-					if(!hasCustomCursor)
+					if (!hasCustomCursor && mDragState == DragState::NoDrag)
 					{
 						CursorType newCursor = CursorType::Arrow;
 						if(elementInfo.element->_hasCustomCursor(localPos, newCursor))
@@ -792,12 +791,16 @@ namespace BansheeEngine
 						break;
 				}
 
-				if(!hasCustomCursor)
+				// While dragging we don't want to modify the cursor
+				if (mDragState == DragState::NoDrag)
 				{
-					if(mActiveCursor != CursorType::Arrow)
+					if (!hasCustomCursor)
 					{
-						Cursor::instance().setCursor(CursorType::Arrow);
-						mActiveCursor = CursorType::Arrow;
+						if (mActiveCursor != CursorType::Arrow)
+						{
+							Cursor::instance().setCursor(CursorType::Arrow);
+							mActiveCursor = CursorType::Arrow;
+						}
 					}
 				}
 			}

+ 14 - 1
BansheeEngine/Source/BsGUIMouseEvent.cpp

@@ -22,6 +22,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -31,6 +32,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -40,6 +42,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -49,6 +52,7 @@ namespace BansheeEngine
 		mPosition = Vector2I();
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = scrollAmount;
 	}
 
@@ -58,6 +62,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = button;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -67,6 +72,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = button;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -76,6 +82,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = button;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -85,15 +92,17 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = dragAmount;
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
-	void GUIMouseEvent::setMouseDragStartData(const Vector2I& position)
+	void GUIMouseEvent::setMouseDragStartData(const Vector2I& position, const Vector2I& dragStartPosition)
 	{
 		mType = GUIMouseEventType::MouseDragStart;
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = dragStartPosition;
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -103,6 +112,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 	}
 
@@ -112,6 +122,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 		mDragTypeId = dragTypeId;
 		mDragData = dragData;
@@ -123,6 +134,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 		mDragTypeId = dragTypeId;
 		mDragData = dragData;
@@ -134,6 +146,7 @@ namespace BansheeEngine
 		mPosition = position;
 		mButton = GUIMouseButton::Left;
 		mDragAmount = Vector2I();
+		mDragStartPosition = Vector2I();
 		mWheelScrollAmount = 0.0f;
 		mDragTypeId = dragTypeId;
 		mDragData = dragData;

+ 3 - 3
TODO.txt

@@ -56,7 +56,8 @@ Code quality improvements:
 ----------------------------------------------------------------------
 Polish stage 1
 
-Int/Float field mouse scrolling doesn't work
+Int/Float field mouse scrolling doesn't work unless clicked on a specific spot
+ - Additionally the scroll value doesn't seem to persist when it comes to the inspector window
 Fix DX11 (and possibly DX9) rendering
 After undocking ProjectWindow the auto-scroll seems to be stuck in up position
 Decent looking default layout
@@ -74,8 +75,7 @@ Add ping to SceneTreeView
  - Hook up ping effect so it triggers when I select a resource or sceneobject
 
 Finish up inspector
- - Missing name + transform fields (+ possible local/global toggle)
- - Add Prefab buttons (Apply, Break, Revert)
+ - Do I handle the case of updating the inspector when component is added or removed?
  - Hook it up to Selection changes so it shows inspector for current component/resource
 
 Need a way to add scene objects and components (and remove them)