/// <summary> /// Callback for the KeyDown event. /// </summary> /// <param name="e">The event.</param> protected void OnKeyDown(KeyDownEvent e) { if (e.keyCode != KeyCode.Escape || m_GraphView == null || !m_Active) { return; } // Reset the items to their original pos. foreach (KeyValuePair <GraphElement, OriginalPos> v in m_OriginalPos) { OriginalPos originalPos = v.Value; v.Key.style.left = originalPos.pos.x; v.Key.style.top = originalPos.pos.y; } m_PanSchedule.Pause(); if (m_ItemPanDiff != Vector3.zero) { Vector3 p = m_GraphView.ContentViewContainer.transform.position; Vector3 s = m_GraphView.ContentViewContainer.transform.scale; m_GraphView.CommandDispatcher.Dispatch(new ReframeGraphViewCommand(p, s)); } using (DragExitedEvent eExit = DragExitedEvent.GetPooled()) { eExit.target = m_CurrentDropTarget; m_GraphView.SendEvent(eExit); } target.ReleaseMouse(); e.StopPropagation(); }
private void OnKeyDown(KeyDownEvent e) { if (e.keyCode != KeyCode.Escape || m_GraphView == null || !m_Active) { return; } // Reset the items to their original pos. var groupsElementsToReset = new Dictionary <Scope, List <GraphElement> >(); foreach (KeyValuePair <GraphElement, OriginalPos> v in m_OriginalPos) { OriginalPos originalPos = v.Value; if (originalPos.stack != null) { originalPos.stack.InsertElement(originalPos.stackIndex, v.Key); } else { if (originalPos.scope != null) { if (!groupsElementsToReset.ContainsKey(originalPos.scope)) { groupsElementsToReset[originalPos.scope] = new List <GraphElement>(); } groupsElementsToReset[originalPos.scope].Add(v.Key); } v.Key.SetPosition(originalPos.pos); } } foreach (KeyValuePair <Scope, List <GraphElement> > toReset in groupsElementsToReset) { toReset.Key.AddElements(toReset.Value); } m_PanSchedule.Pause(); if (m_ItemPanDiff != Vector3.zero) { Vector3 p = m_GraphView.contentViewContainer.transform.position; Vector3 s = m_GraphView.contentViewContainer.transform.scale; m_GraphView.UpdateViewTransform(p, s); } using (DragExitedEvent dexit = DragExitedEvent.GetPooled()) { List <ISelectable> selection = m_GraphView.selection; SendDragAndDropEvent(dexit, selection, m_PrevDropTarget, m_GraphView); } target.ReleaseMouse(); e.StopPropagation(); }
private void OnKeyDown(KeyDownEvent e) { if (e.keyCode != KeyCode.Escape || m_GraphView == null || !m_Active) { return; } // Reset the items to their original pos. foreach (KeyValuePair <GraphElement, OriginalPos> v in m_OriginalPos) { OriginalPos originalPos = v.Value; if (originalPos.stack != null) { originalPos.stack.InsertElement(originalPos.stackIndex, v.Key); } else { v.Key.style.left = originalPos.pos.x; v.Key.style.top = originalPos.pos.y; } } m_PanSchedule.Pause(); if (m_ItemPanDiff != Vector3.zero) { Vector3 p = m_GraphView.contentViewContainer.transform.position; Vector3 s = m_GraphView.contentViewContainer.transform.scale; m_GraphView.UpdateViewTransform(p, s); } using (DragExitedEvent dexit = DragExitedEvent.GetPooled()) { List <ISelectable> selection = m_GraphView.selection; SendDragAndDropEvent(dexit, selection, m_PrevDropTarget, m_GraphView); } target.ReleaseMouse(); e.StopPropagation(); }
protected new void OnMouseDown(MouseDownEvent e) { if (m_Active) { e.StopImmediatePropagation(); return; } if (CanStartManipulation(e)) { m_GraphView = target as GraphView; if (m_GraphView == null) { return; } selectedElement = null; // avoid starting a manipulation on a non movable object clickedElement = e.target as GraphElement; if (clickedElement == null) { var ve = e.target as VisualElement; clickedElement = ve.GetFirstAncestorOfType <GraphElement>(); if (clickedElement == null) { return; } } // Only start manipulating if the clicked element is movable, selected and that the mouse is in its clickable region (it must be deselected otherwise). if (!clickedElement.IsMovable() || !clickedElement.HitTest(clickedElement.WorldToLocal(e.mousePosition))) { return; } // If we hit this, this likely because the element has just been unselected // It is important for this manipulator to receive the event so the previous one did not stop it // but we shouldn't let it propagate to other manipulators to avoid a re-selection if (!m_GraphView.selection.Contains(clickedElement)) { e.StopImmediatePropagation(); return; } selectedElement = clickedElement; m_OriginalPos = new Dictionary <GraphElement, OriginalPos>(); HashSet <GraphElement> elementsToMove = new HashSet <GraphElement>(m_GraphView.selection.OfType <GraphElement>()); var selectedPlacemats = new HashSet <Placemat>(elementsToMove.OfType <Placemat>()); foreach (var placemat in selectedPlacemats) { placemat.GetElementsToMove(e.shiftKey, elementsToMove); } foreach (GraphElement ce in elementsToMove) { if (ce == null || !ce.IsMovable()) { continue; } StackNode stackNode = null; if (ce.parent is StackNode) { stackNode = ce.parent as StackNode; if (stackNode.IsSelected(m_GraphView)) { continue; } } Rect geometry = ce.GetPosition(); Rect geometryInContentViewSpace = ce.hierarchy.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, geometry); m_OriginalPos[ce] = new OriginalPos { pos = geometryInContentViewSpace, scope = ce.GetContainingScope(), stack = stackNode, stackIndex = stackNode != null?stackNode.IndexOf(ce) : -1 }; } m_originalMouse = e.mousePosition; m_ItemPanDiff = Vector3.zero; if (m_PanSchedule == null) { m_PanSchedule = m_GraphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval); m_PanSchedule.Pause(); } // Checking if the Graph Element we are moving has the snappable Capability if ((selectedElement.capabilities & Capabilities.Snappable) == 0) { snapEnabled = false; } else { snapEnabled = EditorPrefs.GetBool("GraphSnapping", true); } if (snapEnabled) { m_Snapper.BeginSnap(m_GraphView); } m_Active = true; target.CaptureMouse(); // We want to receive events even when mouse is not over ourself. e.StopImmediatePropagation(); } }
protected new void OnMouseDown(MouseDownEvent e) { if (m_Active) { e.StopImmediatePropagation(); return; } if (CanStartManipulation(e)) { m_GraphView = target as GraphView; if (m_GraphView == null) { return; } selectedElement = null; // avoid starting a manipulation on a non movable object clickedElement = e.target as GraphElement; if (clickedElement == null) { var ve = e.target as VisualElement; clickedElement = ve.GetFirstAncestorOfType <GraphElement>(); if (clickedElement == null) { return; } } // Only start manipulating if the clicked element is movable, selected and that the mouse is in its clickable region (it must be deselected otherwise). if (!clickedElement.IsMovable() || !clickedElement.HitTest(clickedElement.WorldToLocal(e.mousePosition))) { return; } // If we hit this, this likely because the element has just been unselected // It is important for this manipulator to receive the event so the previous one did not stop it // but we shouldn't let it propagate to other manipulators to avoid a re-selection if (!m_GraphView.selection.Contains(clickedElement)) { e.StopImmediatePropagation(); return; } selectedElement = clickedElement; m_OriginalPos = new Dictionary <GraphElement, OriginalPos>(); foreach (ISelectable s in m_GraphView.selection) { GraphElement ce = s as GraphElement; if (ce == null || !ce.IsMovable()) { continue; } StackNode stackNode = null; if (ce.parent is StackNode) { stackNode = ce.parent as StackNode; if (stackNode.IsSelected(m_GraphView)) { continue; } } Rect geometry = ce.GetPosition(); Rect geometryInContentViewSpace = ce.shadow.parent.ChangeCoordinatesTo(m_GraphView.contentViewContainer, geometry); m_OriginalPos[ce] = new OriginalPos { pos = geometryInContentViewSpace, scope = ce.GetContainingScope(), stack = stackNode, stackIndex = stackNode != null?stackNode.IndexOf(ce) : -1 }; } m_originalMouse = e.mousePosition; m_ItemPanDiff = Vector3.zero; if (m_PanSchedule == null) { m_PanSchedule = m_GraphView.schedule.Execute(Pan).Every(k_PanInterval).StartingIn(k_PanInterval); m_PanSchedule.Pause(); } m_Active = true; target.CaptureMouse(); // We want to receive events even when mouse is not over ourself. e.StopImmediatePropagation(); } }
/// <summary> /// Callback for the MouseDown event. /// </summary> /// <param name="e">The event.</param> protected void OnMouseDown(MouseDownEvent e) { if (m_Active) { e.StopImmediatePropagation(); return; } if (CanStartManipulation(e)) { if (m_GraphView == null) { return; } m_SelectedElement = null; // avoid starting a manipulation on a non movable object m_ClickedElement = e.target as GraphElement; if (m_ClickedElement == null) { var ve = e.target as VisualElement; m_ClickedElement = ve?.GetFirstAncestorOfType <GraphElement>(); if (m_ClickedElement == null) { return; } } // Only start manipulating if the clicked element is movable, selected and that the mouse is in its clickable region (it must be deselected otherwise). if (!m_ClickedElement.IsMovable() || !m_ClickedElement.ContainsPoint(m_ClickedElement.WorldToLocal(e.mousePosition))) { return; } // If we hit this, this likely because the element has just been unselected // It is important for this manipulator to receive the event so the previous one did not stop it // but we shouldn't let it propagate to other manipulators to avoid a re-selection if (!m_ClickedElement.IsSelected()) { e.StopImmediatePropagation(); return; } m_SelectedElement = m_ClickedElement; m_OriginalPos = new Dictionary <GraphElement, OriginalPos>(); var selection = m_GraphView.GetSelection(); var elementsToMove = new HashSet <GraphElement>(selection.Select(model => model.GetUI(m_GraphView)).OfType <GraphElement>()); var selectedPlacemats = new HashSet <Placemat>(elementsToMove.OfType <Placemat>()); foreach (var placemat in selectedPlacemats) { placemat.GetElementsToMove(e.shiftKey, elementsToMove); } m_EdgesToUpdate.Clear(); HashSet <INodeModel> nodeModelsToMove = new HashSet <INodeModel>(elementsToMove.Select(element => element.Model).OfType <INodeModel>()); foreach (var edge in m_GraphView.Edges.ToList()) { if (nodeModelsToMove.Contains(edge.Input?.NodeModel) && nodeModelsToMove.Contains(edge.Output?.NodeModel)) { m_EdgesToUpdate.Add(edge); } } foreach (GraphElement ce in elementsToMove) { if (ce == null || !ce.IsMovable()) { continue; } Rect geometry = ce.GetPosition(); Rect geometryInContentViewSpace = ce.hierarchy.parent.ChangeCoordinatesTo(m_GraphView.ContentViewContainer, geometry); m_OriginalPos[ce] = new OriginalPos { pos = geometryInContentViewSpace, }; } m_OriginalMouse = e.mousePosition; m_ItemPanDiff = Vector3.zero; if (m_PanSchedule == null) { m_PanSchedule = m_GraphView.schedule.Execute(Pan).Every(panInterval).StartingIn(panInterval); m_PanSchedule.Pause(); } m_Snapper.BeginSnap(m_SelectedElement); m_Active = true; target.CaptureMouse(); // We want to receive events even when mouse is not over ourself. e.StopImmediatePropagation(); } }