예제 #1
0
 protected void OnMouseDown(MouseDownEvent e)
 {
     if (e.currentTarget is ISelectable)
     {
         if (base.CanStartManipulation(e))
         {
             if ((base.target as ISelectable).HitTest(e.localMousePosition))
             {
                 GraphElement graphElement = e.currentTarget as GraphElement;
                 if (graphElement != null)
                 {
                     VisualElement parent = graphElement.shadow.parent;
                     while (parent != null && !(parent is GraphView))
                     {
                         parent = parent.shadow.parent;
                     }
                     GraphView selectionContainer = parent as GraphView;
                     if (graphElement.IsSelected(selectionContainer) && e.ctrlKey)
                     {
                         graphElement.Unselect(selectionContainer);
                     }
                     else
                     {
                         graphElement.Select(selectionContainer, e.shiftKey || e.ctrlKey);
                     }
                 }
             }
         }
     }
 }
예제 #2
0
        public virtual void OnStartDragging(GraphElement ge)
        {
            var node = ge as Node;

            if (node != null)
            {
                ge.RemoveFromHierarchy();

                graphView.AddElement(ge);
                // Reselect it because RemoveFromHierarchy unselected it
                ge.Select(graphView, true);
            }
        }
예제 #3
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 positionning the graph elements once the
            // mouse has gone out.
            m_MouseDiff = m_originalMouse - e.mousePosition;

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

                // Detach the selected element from its parent before dragging it
                // TODO: Make it more generic
                if (ce.parent is StackNode)
                {
                    StackNode stackNode = ce.parent as StackNode;

                    ce.RemoveFromHierarchy();

                    m_GraphView.AddElement(ce);
                    // Reselect it because RemoveFromHierarchy unselected it
                    ce.Select(m_GraphView, true);

                    if (m_GraphView.elementRemovedFromStackNode != null)
                    {
                        m_GraphView.elementRemovedFromStackNode(stackNode, ce);
                    }
                }

                MoveElement(ce, v.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 && m_PrevDropTarget != null)
            {
                using (DragExitedEvent eexit = DragExitedEvent.GetPooled(e))
                {
                    SendDragAndDropEvent(eexit, selection, m_PrevDropTarget);
                }
            }

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

            m_PrevDropTarget = dropTarget;

            selectedElement = null;
            e.StopPropagation();
        }