Browse Source

Merge pull request #671 from AtomicGameEngine/JME-ATOMIC-HIERARCHYDRAGDROPFIX

Fix issue when drag/drop on same widget (fixes hierarchy node drag/drop), add pixel tolerance on initializing drag/drop operation
JoshEngebretson 9 years ago
parent
commit
be72d75c62
2 changed files with 15 additions and 9 deletions
  1. 13 8
      Source/Atomic/UI/UIDragDrop.cpp
  2. 2 1
      Source/Atomic/UI/UIDragDrop.h

+ 13 - 8
Source/Atomic/UI/UIDragDrop.cpp

@@ -95,7 +95,7 @@ void UIDragDrop::DragEnd()
     dragSourceWidget_ = 0;
     dragLayout_->SetVisibility(UI_WIDGET_VISIBILITY_GONE);
 
-    if (currentTargetWidget.Null() || dragSourceWidget == currentTargetWidget)
+    if (currentTargetWidget.Null())
     {
         return;
     }
@@ -146,6 +146,7 @@ void UIDragDrop::HandleMouseDown(StringHash eventType, VariantMap& eventData)
 
         currentTargetWidget_ = widget;
         dragSourceWidget_ = widget;
+        mouseDownPosition_ = input->GetMousePosition();
 
     }
 
@@ -171,8 +172,6 @@ void UIDragDrop::HandleMouseUp(StringHash eventType, VariantMap& eventData)
 
 void UIDragDrop::HandleMouseMove(StringHash eventType, VariantMap& eventData)
 {
-    Input* input = GetSubsystem<Input>();
-
     if (dragObject_.Null() && dragSourceWidget_.Null())
         return;
 
@@ -188,6 +187,17 @@ void UIDragDrop::HandleMouseMove(StringHash eventType, VariantMap& eventData)
 
     }
 
+    using namespace MouseMove;
+
+    int x = eventData[P_X].GetInt();
+    int y = eventData[P_Y].GetInt();
+
+    // tolerance to 8 pixels to start drag/drop operation
+    IntVector2 mousePos(x, y);
+    mousePos -= mouseDownPosition_;
+    if (Abs(mousePos.x_) < 8 && Abs(mousePos.y_) < 8)
+        return;
+
     // initialize if necessary
     if (dragLayout_->GetVisibility() == UI_WIDGET_VISIBILITY_GONE)
     {
@@ -199,11 +209,6 @@ void UIDragDrop::HandleMouseMove(StringHash eventType, VariantMap& eventData)
         dragLayout_->SetRect(IntRect(0, 0, sz->GetMinWidth(), sz->GetMinHeight()));
     }
 
-    using namespace MouseMove;
-
-    int x = eventData[P_X].GetInt();
-    int y = eventData[P_Y].GetInt();
-
     // see if we have a widget
     TBWidget* tbw = TBWidget::hovered_widget;
 

+ 2 - 1
Source/Atomic/UI/UIDragDrop.h

@@ -69,7 +69,8 @@ private:
 
     SharedPtr<UIDragObject> dragObject_;
 
-
+    // initial mouse down position to handle whether or not to start a drag operation
+    IntVector2 mouseDownPosition_;
 
 };