OSDN Git Service

Only allow one drag action at a time
authorJohan Lövdahl <johan.lovdahl@uxvibe.com>
Mon, 18 Feb 2013 11:13:22 +0000 (12:13 +0100)
committerJohan Lövdahl <johan.lovdahl@uxvibe.com>
Mon, 18 Feb 2013 11:13:22 +0000 (12:13 +0100)
The DragAndDrop class only manages one payload and drag actor, so we
need to stop several drag events from happening at the same time.

gdx/src/com/badlogic/gdx/scenes/scene2d/utils/DragAndDrop.java

index 13c8e52..ba26bb5 100644 (file)
@@ -40,10 +40,23 @@ public class DragAndDrop {
        float dragActorX = 14, dragActorY = -20;
        long dragStartTime;
        int dragTime = 250;
+       boolean isDragging = false;
+       Object dragSyncObj = new Object();
+       int activePointer;
 
        public void addSource (final Source source) {
                DragListener listener = new DragListener() {
                        public void dragStart (InputEvent event, float x, float y, int pointer) {
+                               synchronized (dragSyncObj) {
+                                       if (isDragging) {
+                                               event.stop();
+                                               return;
+                                       }
+
+                                       isDragging = true;
+                                       activePointer = pointer;
+                               }
+
                                dragStartTime = System.currentTimeMillis();
                                payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer);
                                event.stop();
@@ -51,6 +64,8 @@ public class DragAndDrop {
 
                        public void drag (InputEvent event, float x, float y, int pointer) {
                                if (payload == null) return;
+                               if (pointer != activePointer) return;
+
                                Stage stage = event.getStage();
 
                                Touchable dragActorTouchable = null;
@@ -102,6 +117,12 @@ public class DragAndDrop {
 
                        public void dragStop (InputEvent event, float x, float y, int pointer) {
                                if (payload == null) return;
+                               if (pointer != activePointer) return;
+
+                               synchronized (dragSyncObj) {
+                                       isDragging = false;
+                               }
+
                                if (System.currentTimeMillis() - dragStartTime < dragTime) isValidTarget = false;
                                if (dragActor != null) dragActor.remove();
                                if (isValidTarget) {