示例#1
0
        private static void OnMouseDrag(Event e)
        {
#if DEBUG
            if (DebugMode)
                Debug.Log("DragDropManager.OnMouseDrag: " + _dragInitiator);
#endif

            MouseEvent input = (MouseEvent)e;

            DragEvent de;

            /**
             * 1) Check for drag start
             * */
            if (!_dragging) // if not yet dragging
            {
                _dragOverComponent = null;
                _dragging = true; // we're dragging now
                if (null != _dragInitiator) // if dragging something
                {
#if DEBUG
                    if (DebugMode)
                        Debug.Log("DragEvent.DRAG_START: " + _dragInitiator);
#endif
                    de = BuildEvent(DragEvent.DRAG_START);
                    _dragInitiator.DispatchEvent(de);
                }

                return;
            }

            _dragOverComponent = CoordinateProcessor.GetComponentUnderCoordinatesOnAllStages(input.GlobalPosition, delegate(DisplayListMember dlm)
            {
                Component component = dlm as Component;
                return null != component && component.MouseEnabled; // && !(component is Stage); // commented 20130307
            }, true, true) as Component; // stopOnDisabled, stopOnInvisible

            bool isDragEnter = null != _dragOverComponent && 
                               _dragOverComponent != _lastDragOverComponent &&
                               _dragInitiator != null &&
                               _dragInitiator != _dragOverComponent;

            /**
             * 2) Check for drag enter
             * */
            if (isDragEnter)
            {
                // nullify accepted target, and allow the user to react on DRAG_ENTER event (to call AcceptDragDrop)
                _acceptedTarget = null;
                _action = Action.None;
                //Debug.Log("DragEvent.DRAG_ENTER: " + _dragOverComponent.GetType().Name);
#if DEBUG
                if (DebugMode)
                    Debug.Log("DragEvent.DRAG_ENTER: " + _dragOverComponent.GetType().Name);
#endif
                // dispatch DragEvent.DRAG_EXIT on _lastDragOverComponent
                if (null != _lastDragOverComponent)
                {
                    de = BuildEvent(DragEvent.DRAG_EXIT);
                    _lastDragOverComponent.DispatchEvent(de);
                }

                // dispatch DragEvent.DRAG_ENTER on _dragOverComponent
                de = BuildEvent(DragEvent.DRAG_ENTER);
                _dragOverComponent.DispatchEvent(de);

                // set _lastDragOverComponent
                _lastDragOverComponent = _dragOverComponent;
            }

            /**
             * 3) Handle feedback to the user
             * By this point, if the user was subscribed to DragEvent.DRAG_ENTER, he could have react with AcceptDragDrop() and (optionally) ShowFeedback()
             * */

            // check if the user has accepted drag and drop
            if (null != _acceptedTarget)
            {
                // if drop is accepted, show overlay, and show CursorType.AcceptDrop cursor
                Overlay.Visible = _overlayShouldBeVisible;
                //_overlay.SetBounds(_acceptedTarget.GlobalBounds); // fix? .MoveBy(new Point(-1, 0)),
                //Overlay.Bounds = (Rectangle)_acceptedTarget.Transform.GlobalBounds.Clone(); // consider cloning bounds 20120415
                
                if (_feedbackShouldBeVisible)
                {
                    if (Action.None == _action)
                        ChangeCursorTo(CursorType.AcceptDrop);
                    else
                        ProcessFeedback(_action);
                }
                else
                    ChangeCursorTo(CursorType.Normal);
            }
            else
            {
                // if drop is rejected (meaning not accepted by developer), hide overlay, and show CursorType.RejectDrop cursor
                Overlay.Visible = false;
                if (_feedbackShouldBeVisible)
                    ChangeCursorTo(CursorType.RejectDrop);
                else
                    ChangeCursorTo(CursorType.Normal);
            }

            /**
             * 4) Move proxy
             * */
            _proxy.X = input.GlobalPosition.X + Offset.X;
            _proxy.Y = input.GlobalPosition.Y + Offset.Y;
            _proxy.ValidateNow();
        }
示例#2
0
 private static void ProcessFeedback(Action action)
 {
     switch (action)
     {
         case Action.Copy:
             ChangeCursorTo(CursorType.DragCopy);
             break;
         case Action.Move:
             ChangeCursorTo(CursorType.DragMove);
             break;
         case Action.Link:
             ChangeCursorTo(CursorType.DragLink);
             break;
         case Action.None:
             //CursorLogic.CursorLogic.Show(CursorType.RejectDrop);
             //ChangeCursorTo(CursorType.NormalColor);
             RemoveCursor();
             break;
     }
 }
示例#3
0
        /**
	     *  Sets the feedback indicator for the drag and drop operation.
	     *  Possible values are <code>DragManager.COPY</code>, <code>DragManager.MOVE</code>,
	     *  <code>DragManager.LINK</code>, or <code>DragManager.NONE</code>.
	     *
	     *  Param: feedback The type of feedback indicator to display.
	     */
        public static void ShowFeedback(Action action)
        {
            _action = action;
        }