flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [30/30] git commit: [flex-asjs] [refs/heads/develop] - Drag/Drop now works
Date Sat, 18 Oct 2014 05:43:47 GMT
Drag/Drop now works


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c4d292fb
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c4d292fb
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c4d292fb

Branch: refs/heads/develop
Commit: c4d292fb6bc713cf40d5f097abd098e0f85fab8d
Parents: cd04796
Author: Alex Harui <aharui@apache.org>
Authored: Fri Oct 17 22:37:59 2014 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Oct 17 22:38:49 2014 -0700

----------------------------------------------------------------------
 .../beads/controllers/DragMouseController.as    | 61 +++++++++++++++++++-
 .../beads/controllers/DropMouseController.as    | 14 ++++-
 2 files changed, 69 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c4d292fb/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DragMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DragMouseController.as
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DragMouseController.as
index 9d14b1c..3dc833d 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DragMouseController.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DragMouseController.as
@@ -20,14 +20,18 @@ package org.apache.flex.html.beads.controllers
 {
 	import flash.display.DisplayObject;
 	import flash.events.MouseEvent;
+	import flash.geom.Point;
 	
 	import org.apache.flex.core.IBead;
 	import org.apache.flex.core.IDragInitiator;
+    import org.apache.flex.core.IPopUpHost;
 	import org.apache.flex.core.IStrand;
+    import org.apache.flex.core.IUIBase;
 	import org.apache.flex.core.UIBase;
 	import org.apache.flex.events.DragEvent;
-    import org.apache.flex.events.EventDispatcher;
+	import org.apache.flex.events.EventDispatcher;
 	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.utils.UIUtils;
 	
     /**
      *  Indicates that a drag/drop operation is starting.
@@ -106,6 +110,36 @@ package org.apache.flex.html.beads.controllers
         public static var dragging:Boolean;
         
         /**
+         *  The drag image.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public static var dragImage:IUIBase;
+        
+        /**
+         *  The offset of the drag image.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public static var dragImageOffsetX:Number = 0;
+        
+        /**
+         *  The offset of the drag image.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public static var dragImageOffsetY:Number = 0;
+        
+        /**
          *  The default movement in x and or y that
          *  means a drag should start
          *  
@@ -165,11 +199,14 @@ package org.apache.flex.html.beads.controllers
         private var mouseDownX:Number;
         private var mouseDownY:Number;
         
+        private var host:IPopUpHost;
+        
         /**
          *  @private
          */
         private function dragMouseDownHandler(event:MouseEvent):void
         {
+            trace("dragMouseDown");
             DisplayObject(_strand).stage.addEventListener(MouseEvent.MOUSE_MOVE, dragMouseMoveHandler);
             DisplayObject(_strand).stage.addEventListener(MouseEvent.MOUSE_UP, dragMouseUpHandler);
             mouseDownX = event.stageX;
@@ -178,49 +215,67 @@ package org.apache.flex.html.beads.controllers
         
         private function dragMouseMoveHandler(event:MouseEvent):void
         {
+            var pt:Point;
             var dragEvent:DragEvent;
+            trace("dragMouseMove");
             
             if (!dragging)
             {
+                trace("not dragging anything else");
                 if (Math.abs(event.stageX - mouseDownX) > threshold ||
                     Math.abs(event.stageY - mouseDownY) > threshold)
                 {
+                    trace("sending dragStart");
                     dragEvent = new DragEvent("dragStart", true, true);
                     dragEvent.copyMouseEventProperties(event);
                     IEventDispatcher(_strand).dispatchEvent(dragEvent);
                     if (dragSource != null)
                     {
                         dragging = true;
+                        host = UIUtils.findPopUpHost(_strand as IUIBase);
+                        host.addElement(dragImage);
+                        pt = DisplayObject(host).globalToLocal(new Point(event.stageX, event.stageY));
+                        dragImage.x = pt.x + dragImageOffsetX;
+                        dragImage.y = pt.y + dragImageOffsetY;
                     }
                 }
             }
             else
             {
+                trace("sending dragMove", event.target);
                 dragEvent = new DragEvent("dragMove", true, true);
                 event.stopImmediatePropagation();
                 dragEvent.copyMouseEventProperties(event);
                 dragEvent.dragSource = dragSource;
                 dragEvent.dragInitiator = dragInitiator;
-                IEventDispatcher(_strand).dispatchEvent(dragEvent);
+                pt = DisplayObject(host).globalToLocal(new Point(event.stageX, event.stageY));
+                dragImage.x = pt.x + dragImageOffsetX;
+                dragImage.y = pt.y + dragImageOffsetY;
+                event.target.dispatchEvent(dragEvent);
             }
         }
         
         private function dragMouseUpHandler(event:MouseEvent):void
         {
+            trace("dragMouseUp");
             var dragEvent:DragEvent;
             
             if (dragging)
             {
+                trace("sending dragEnd");
                 dragEvent = new DragEvent("dragEnd", true, true);
                 dragEvent.copyMouseEventProperties(event);
                 event.stopImmediatePropagation();
                 dragEvent.dragSource = dragSource;
                 dragEvent.dragInitiator = dragInitiator;
-                IEventDispatcher(_strand).dispatchEvent(dragEvent);
+                event.target.dispatchEvent(dragEvent);
             }
             dragging = false;
             dragSource = null;
             dragInitiator = null;
+            if (dragImage)
+                host.removeElement(dragImage);
+            dragImage = null;
             DisplayObject(_strand).stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragMouseMoveHandler);
             DisplayObject(_strand).stage.removeEventListener(MouseEvent.MOUSE_UP, dragMouseUpHandler);
		
         }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c4d292fb/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DropMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DropMouseController.as
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DropMouseController.as
index c70c9a8..49d4d79 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DropMouseController.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/beads/controllers/DropMouseController.as
@@ -24,6 +24,7 @@ package org.apache.flex.html.beads.controllers
 	import org.apache.flex.core.IBead;
 	import org.apache.flex.core.IDragInitiator;
 	import org.apache.flex.core.IStrand;
+    import org.apache.flex.core.IUIBase;
 	import org.apache.flex.core.UIBase;
 	import org.apache.flex.events.DragEvent;
 	import org.apache.flex.events.EventDispatcher;
@@ -111,11 +112,17 @@ package org.apache.flex.html.beads.controllers
         private var dragSource:Object;
         private var dragInitiator:IDragInitiator;
         
+        public function acceptDragDrop(target:IUIBase, type:String):void
+        {
+            // TODO: aharui: switch icons
+        }
+        
         /**
          *  @private
          */
         private function dragMoveHandler(event:DragEvent):void
         {
+            trace("dragMove");
             var dragEvent:DragEvent;
             if (!inside)
             {
@@ -123,7 +130,7 @@ package org.apache.flex.html.beads.controllers
                 dragEvent.copyMouseEventProperties(event);
                 dragSource = dragEvent.dragSource = event.dragSource;
                 dragInitiator = dragEvent.dragInitiator = event.dragInitiator;
-                IEventDispatcher(_strand).dispatchEvent(dragEvent);
+                dispatchEvent(dragEvent);
                 inside = true;
                 DisplayObject(_strand).stage.addEventListener(DragEvent.DRAG_END, dragEndHandler);
                 DisplayObject(_strand).addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
@@ -151,7 +158,7 @@ package org.apache.flex.html.beads.controllers
                 dragSource = null;
                 dragInitiator = null;
                 event.stopImmediatePropagation();
-                IEventDispatcher(_strand).dispatchEvent(dragEvent);
+                dispatchEvent(dragEvent);
                 inside = false;
             }
             DisplayObject(_strand).stage.removeEventListener(DragEvent.DRAG_END, dragEndHandler);
@@ -160,6 +167,7 @@ package org.apache.flex.html.beads.controllers
         
         private function dragEndHandler(event:DragEvent):void
         {
+            trace("dragEnd");
             var dragEvent:DragEvent;
             
             dragEvent = new DragEvent("dragDrop", true, true);
@@ -169,7 +177,7 @@ package org.apache.flex.html.beads.controllers
             dragSource = null;
             dragInitiator = null;
             event.stopImmediatePropagation();
-            IEventDispatcher(_strand).dispatchEvent(dragEvent);
+            dispatchEvent(dragEvent);
             
             DisplayObject(_strand).stage.removeEventListener(DragEvent.DRAG_END, dragEndHandler);
             DisplayObject(_strand).removeEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
		


Mime
View raw message