public void RemoveElement(GraphElement graphElement) { // TODO : Find a better way to remove a graphElement from its scope when it is removed from the GraphView. Scope scope = graphElement.GetContainingScope(); if (scope != null) { scope.RemoveElement(graphElement); } graphElement.RemoveFromHierarchy(); }
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); } }
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(); }