Browse Source

Add drag/drop pixel tolerance

Josh Engebretson 9 years ago
parent
commit
ebb400b7d9
2 changed files with 14 additions and 8 deletions
  1. 12 7
      Source/Atomic/UI/UIDragDrop.cpp
  2. 2 1
      Source/Atomic/UI/UIDragDrop.h

+ 12 - 7
Source/Atomic/UI/UIDragDrop.cpp

@@ -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_;
 
 };