protected new void OnMouseMove(MouseMoveEvent e)
        {
            if (!m_Active)
            {
                return;
            }

            if (m_GraphView == null)
            {
                return;
            }

            var     ve         = (VisualElement)e.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(m_GraphView.contentContainer, e.localMousePosition);

            m_PanDiff = GetEffectivePanSpeed(gvMousePos);

#if USE_DRAG_RESET_WHEN_OUT_OF_GRAPH_VIEW
            // We currently don't have a real use case for this and it just appears to annoy users.
            // If and when the use case arise, we can revive this functionality.

            if (gvMousePos.x < 0 || gvMousePos.y < 0 || gvMousePos.x > m_GraphView.layout.width ||
                gvMousePos.y > m_GraphView.layout.height)
            {
                if (!m_GoneOut)
                {
                    m_PanSchedule.Pause();

                    foreach (KeyValuePair <GraphElement, Rect> v in m_OriginalPos)
                    {
                        v.Key.SetPosition(v.Value);
                    }
                    m_GoneOut = true;
                }

                e.StopPropagation();
                return;
            }

            if (m_GoneOut)
            {
                m_GoneOut = false;
            }
#endif

            if (m_PanDiff != Vector3.zero)
            {
                m_PanSchedule.Resume();
            }
            else
            {
                m_PanSchedule.Pause();
            }

            // We need to monitor the mouse diff "by hand" because we stop positioning the graph elements once the
            // mouse has gone out.
            m_MouseDiff = m_originalMouse - e.mousePosition;

            var groupElementsDraggedOut = e.shiftKey ? new Dictionary <Group, List <GraphElement> >() : null;
            foreach (KeyValuePair <GraphElement, OriginalPos> v in m_OriginalPos)
            {
                GraphElement ce = v.Key;

                // Protect against stale visual elements that have been deparented since the start of the manipulation
                if (ce.hierarchy.parent == null)
                {
                    continue;
                }

                if (!v.Value.dragStarted)
                {
                    // TODO Would probably be a good idea to batch stack items as we do for group ones.
                    var stackParent = ce.GetFirstAncestorOfType <StackNode>();
                    if (stackParent != null)
                    {
                        stackParent.OnStartDragging(ce);
                    }

                    if (groupElementsDraggedOut != null)
                    {
                        var groupParent = ce.GetContainingScope() as Group;
                        if (groupParent != null)
                        {
                            if (!groupElementsDraggedOut.ContainsKey(groupParent))
                            {
                                groupElementsDraggedOut[groupParent] = new List <GraphElement>();
                            }
                            groupElementsDraggedOut[groupParent].Add(ce);
                        }
                    }
                    v.Value.dragStarted = true;
                }

                MoveElement(ce, v.Value.pos);
            }

            foreach (var edge in m_EdgesToUpdate)
            {
                UpdateEdge(edge);
            }

            // Needed to ensure nodes can be dragged out of multiple groups all at once.
            if (groupElementsDraggedOut != null)
            {
                foreach (KeyValuePair <Group, List <GraphElement> > kvp in groupElementsDraggedOut)
                {
                    kvp.Key.OnStartDragging(e, kvp.Value);
                }
            }

            List <ISelectable> selection = m_GraphView.selection;

            // TODO: Replace with a temp drawing or something...maybe manipulator could fake position
            // all this to let operation know which element sits under cursor...or is there another way to draw stuff that is being dragged?

            IDropTarget dropTarget = GetDropTargetAt(e.mousePosition, selection.OfType <VisualElement>());

            if (m_PrevDropTarget != dropTarget)
            {
                if (m_PrevDropTarget != null)
                {
                    using (DragLeaveEvent eexit = DragLeaveEvent.GetPooled(e))
                    {
                        SendDragAndDropEvent(eexit, selection, m_PrevDropTarget, m_GraphView);
                    }
                }

                using (DragEnterEvent eenter = DragEnterEvent.GetPooled(e))
                {
                    SendDragAndDropEvent(eenter, selection, dropTarget, m_GraphView);
                }
            }

            using (DragUpdatedEvent eupdated = DragUpdatedEvent.GetPooled(e))
            {
                SendDragAndDropEvent(eupdated, selection, dropTarget, m_GraphView);
            }

            m_PrevDropTarget = dropTarget;

            selectedElement = null;
            e.StopPropagation();
        }
Ejemplo n.º 2
0
        protected new void OnMouseMove(MouseMoveEvent e)
        {
            if (!m_Active)
            {
                return;
            }

            if (m_GraphView == null)
            {
                return;
            }

            var     ve         = (VisualElement)e.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(m_GraphView.contentContainer, e.localMousePosition);

            m_PanDiff = GetEffectivePanSpeed(gvMousePos);


            if (m_PanDiff != Vector3.zero)
            {
                m_PanSchedule.Resume();
            }
            else
            {
                m_PanSchedule.Pause();
            }

            // We need to monitor the mouse diff "by hand" because we stop positioning the graph elements once the
            // mouse has gone out.
            m_MouseDiff = m_originalMouse - e.mousePosition;

            var groupElementsDraggedOut = e.shiftKey ? new Dictionary <Group, List <GraphElement> >() : null;

            // Handle the selected element
            Rect selectedElementGeom = GetSelectedElementGeom();

            m_ShiftClicked = e.shiftKey;

            if (snapEnabled && !m_ShiftClicked)
            {
                ComputeSnappedRect(ref selectedElementGeom, m_XScale);
            }

            if (snapEnabled && m_ShiftClicked)
            {
                m_Snapper.ClearSnapLines();
            }

            foreach (KeyValuePair <GraphElement, OriginalPos> v in m_OriginalPos)
            {
                GraphElement ce = v.Key;

                // Protect against stale visual elements that have been deparented since the start of the manipulation
                if (ce.hierarchy.parent == null)
                {
                    continue;
                }

                if (!v.Value.dragStarted)
                {
                    // TODO Would probably be a good idea to batch stack items as we do for group ones.
                    var stackParent = ce.GetFirstAncestorOfType <StackNode>();
                    if (stackParent != null)
                    {
                        stackParent.OnStartDragging(ce);
                    }

                    if (groupElementsDraggedOut != null)
                    {
                        var groupParent = ce.GetContainingScope() as Group;
                        if (groupParent != null)
                        {
                            if (!groupElementsDraggedOut.ContainsKey(groupParent))
                            {
                                groupElementsDraggedOut[groupParent] = new List <GraphElement>();
                            }
                            groupElementsDraggedOut[groupParent].Add(ce);
                        }
                    }
                    v.Value.dragStarted = true;
                }

                SnapOrMoveElement(v, selectedElementGeom);
            }

            // Needed to ensure nodes can be dragged out of multiple groups all at once.
            if (groupElementsDraggedOut != null)
            {
                foreach (KeyValuePair <Group, List <GraphElement> > kvp in groupElementsDraggedOut)
                {
                    kvp.Key.OnStartDragging(e, kvp.Value);
                }
            }

            List <ISelectable> selection = m_GraphView.selection;

            // TODO: Replace with a temp drawing or something...maybe manipulator could fake position
            // all this to let operation know which element sits under cursor...or is there another way to draw stuff that is being dragged?

            IDropTarget dropTarget = GetDropTargetAt(e.mousePosition, selection.OfType <VisualElement>());

            if (m_PrevDropTarget != dropTarget)
            {
                if (m_PrevDropTarget != null)
                {
                    using (DragLeaveEvent eexit = DragLeaveEvent.GetPooled(e))
                    {
                        SendDragAndDropEvent(eexit, selection, m_PrevDropTarget, m_GraphView);
                    }
                }

                using (DragEnterEvent eenter = DragEnterEvent.GetPooled(e))
                {
                    SendDragAndDropEvent(eenter, selection, dropTarget, m_GraphView);
                }
            }

            using (DragUpdatedEvent eupdated = DragUpdatedEvent.GetPooled(e))
            {
                SendDragAndDropEvent(eupdated, selection, dropTarget, m_GraphView);
            }

            m_PrevDropTarget = dropTarget;

            m_Dragging = true;
            e.StopPropagation();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Callback for the MouseMove event.
        /// </summary>
        /// <param name="e">The event.</param>
        protected void OnMouseMove(MouseMoveEvent e)
        {
            if (!m_Active)
            {
                return;
            }

            if (m_GraphView == null)
            {
                return;
            }

            var     ve         = (VisualElement)e.target;
            Vector2 gvMousePos = ve.ChangeCoordinatesTo(m_GraphView.contentContainer, e.localMousePosition);

            m_PanDiff = GetEffectivePanSpeed(gvMousePos);

            if (m_PanDiff != Vector3.zero)
            {
                m_PanSchedule.Resume();
            }
            else
            {
                m_PanSchedule.Pause();
            }

            // We need to monitor the mouse diff "by hand" because we stop positioning the graph elements once the
            // mouse has gone out.
            m_MouseDiff = m_OriginalMouse - e.mousePosition;

            if (m_SelectedElement.parent != null)
            {
                // Handle the selected element
                Rect selectedElementGeom = GetSelectedElementGeom();

                ComputeSnappedRect(ref selectedElementGeom, m_SelectedElement);

                foreach (KeyValuePair <GraphElement, OriginalPos> v in m_OriginalPos)
                {
                    GraphElement ce = v.Key;

                    // Protect against stale visual elements that have been deparented since the start of the manipulation
                    if (ce.hierarchy.parent == null)
                    {
                        continue;
                    }

                    if (!v.Value.dragStarted)
                    {
                        v.Value.dragStarted = true;
                    }

                    SnapOrMoveElement(v.Key, v.Value.pos, selectedElementGeom);
                }

                foreach (var edge in m_EdgesToUpdate)
                {
                    SnapOrMoveEdge(edge, selectedElementGeom);
                }
            }

            var selection  = m_GraphView.GetSelection();
            var selectedUI = selection.Select(m => m.GetUI(m_GraphView));

            // TODO: Replace with a temp drawing or something...maybe manipulator could fake position
            // all this to let operation know which element sits under cursor...or is there another way to draw stuff that is being dragged?

            var previousDropTarget = m_CurrentDropTarget;

            m_CurrentDropTarget = GetDropTargetAt(e.mousePosition, selectedUI.OfType <VisualElement>().ToList());

            if (m_CurrentDropTarget != previousDropTarget)
            {
                if (previousDropTarget != null)
                {
                    using (DragLeaveEvent eLeave = DragLeaveEvent.GetPooled(e))
                    {
                        eLeave.target = previousDropTarget;
                        m_GraphView.SendEvent(eLeave);
                    }
                }

                if (m_CurrentDropTarget != null)
                {
                    using (DragEnterEvent eEnter = DragEnterEvent.GetPooled(e))
                    {
                        eEnter.target = m_CurrentDropTarget;
                        m_GraphView.SendEvent(eEnter);
                    }
                }
            }

            if (m_CurrentDropTarget != null)
            {
                using (DragUpdatedEvent eUpdated = DragUpdatedEvent.GetPooled(e))
                {
                    eUpdated.target = m_CurrentDropTarget;
                    m_GraphView.SendEvent(eUpdated);
                }
            }

            m_Dragging = true;
            e.StopPropagation();
        }