public static GroupNode GetContainingGroupNode(this GraphElement element) { GroupNode result; if (element == null) { result = null; } else { GraphView firstAncestorOfType = element.GetFirstAncestorOfType <GraphView>(); if (firstAncestorOfType == null) { result = null; } else { List <GroupNode> list = firstAncestorOfType.Query(null, null).ToList(); foreach (GroupNode current in list) { if (current.ContainsElement(element)) { result = current; return(result); } } result = null; } } return(result); }
private void OnMouseMove(MouseMoveEvent e) { GraphElement graphElement = base.parent as GraphElement; if (graphElement != null) { if (graphElement.IsResizable()) { if (this.m_Active && base.parent.style.positionType == PositionType.Manual) { Vector2 vector = this.ChangeCoordinatesTo(base.parent, e.localMousePosition) - this.m_Start; Vector2 vector2 = new Vector2(this.m_StartPos.width + vector.x, this.m_StartPos.height + vector.y); if (vector2.x < this.m_MinimumSize.x) { vector2.x = this.m_MinimumSize.x; } if (vector2.y < this.m_MinimumSize.y) { vector2.y = this.m_MinimumSize.y; } graphElement.SetPosition(new Rect(graphElement.layout.x, graphElement.layout.y, vector2.x, vector2.y)); graphElement.UpdatePresenterPosition(); GraphView firstAncestorOfType = graphElement.GetFirstAncestorOfType <GraphView>(); if (firstAncestorOfType != null && firstAncestorOfType.elementResized != null) { firstAncestorOfType.elementResized(graphElement); } this.m_LabelText.text = string.Format("{0:0}", base.parent.layout.width) + "x" + string.Format("{0:0}", base.parent.layout.height); e.StopPropagation(); } } } }
public static GroupNode GetContainingGroupNode(this GraphElement element) { if (element == null) { return(null); } GraphView graphView = element.GetFirstAncestorOfType <GraphView>(); if (graphView == null) { return(null); } List <GroupNode> groups = graphView.Query <GroupNode>().ToList(); foreach (GroupNode group in groups) { if (group.ContainsElement(element)) { return(group); } } return(null); }
public static Scope GetContainingScope(this GraphElement element) { if (element == null) { return(null); } GraphView graphView = element.GetFirstAncestorOfType <GraphView>(); if (graphView == null) { return(null); } return(graphView.Query <Scope>().Where(scope => scope.containedElements.Contains(element)).First()); }
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; 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.shadow.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); } // 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(); }