protected new void OnMouseUp(MouseUpEvent evt) { if (this.m_GraphView == null) { if (this.m_Active && base.target.HasMouseCapture()) { base.target.ReleaseMouseCapture(); this.selectedElement = null; this.m_Active = false; this.m_PrevDropTarget = null; } } else { List <ISelectable> selection = this.m_GraphView.selection; if (base.CanStopManipulation(evt)) { if (this.m_Active && base.target.HasMouseCapture()) { if (this.selectedElement == null) { this.m_MovedElements.Clear(); foreach (GraphElement current in this.m_OriginalPos.Keys) { current.UpdatePresenterPosition(); this.m_MovedElements.Add(current); } GraphView graphView = base.target as GraphView; if (graphView != null && graphView.graphViewChanged != null) { graphView.graphViewChanged(this.m_GraphViewChange); } } this.m_PanSchedule.Pause(); if (this.m_ItemPanDiff != Vector3.zero) { Vector3 position = this.m_GraphView.contentViewContainer.transform.position; Vector3 scale = this.m_GraphView.contentViewContainer.transform.scale; this.m_GraphView.UpdateViewTransform(position, scale); } if (selection.Count > 0 && this.m_PrevDropTarget != null) { using (IMGUIEvent pooled = IMGUIEvent.GetPooled(evt.imguiEvent)) { pooled.imguiEvent.type = EventType.DragPerform; this.SendDragAndDropEvent(pooled, selection, this.m_PrevDropTarget); } } base.target.ReleaseMouseCapture(); evt.StopPropagation(); } this.selectedElement = null; this.m_Active = false; this.m_PrevDropTarget = null; } } }
protected new void OnMouseMove(MouseMoveEvent e) { if (!base.target.HasMouseCapture()) { this.m_PrevDropTarget = null; this.m_Active = false; } if (this.m_Active) { if (this.m_GraphView != null) { VisualElement src = (VisualElement)e.target; Vector2 mousePos = src.ChangeCoordinatesTo(this.m_GraphView.contentContainer, e.localMousePosition); this.m_PanDiff = this.GetEffectivePanSpeed(mousePos); if (this.m_PanDiff != Vector3.zero) { this.m_PanSchedule.Resume(); } else { this.m_PanSchedule.Pause(); } this.m_MouseDiff = this.m_originalMouse - e.mousePosition; foreach (KeyValuePair <GraphElement, Rect> current in this.m_OriginalPos) { GraphElement key = current.Key; Matrix4x4 worldTransform = key.worldTransform; Vector3 vector = new Vector3(worldTransform.m00, worldTransform.m11, worldTransform.m22); Rect position = key.GetPosition(); key.SetPosition(new Rect(current.Value.x - (this.m_MouseDiff.x - this.m_ItemPanDiff.x) * base.panSpeed.x / vector.x, current.Value.y - (this.m_MouseDiff.y - this.m_ItemPanDiff.y) * base.panSpeed.y / vector.y, position.width, position.height)); } List <ISelectable> selection = this.m_GraphView.selection; IDropTarget dropTargetAt = this.GetDropTargetAt(e.localMousePosition); if (this.m_PrevDropTarget != dropTargetAt && this.m_PrevDropTarget != null) { using (IMGUIEvent pooled = IMGUIEvent.GetPooled(e.imguiEvent)) { pooled.imguiEvent.type = EventType.DragExited; this.SendDragAndDropEvent(pooled, selection, this.m_PrevDropTarget); } } using (IMGUIEvent pooled2 = IMGUIEvent.GetPooled(e.imguiEvent)) { pooled2.imguiEvent.type = EventType.DragUpdated; this.SendDragAndDropEvent(pooled2, selection, dropTargetAt); } this.m_PrevDropTarget = dropTargetAt; this.selectedElement = null; e.StopPropagation(); } } }
protected void OnIMGUIEvent(IMGUIEvent e) { if (this.m_Active && this.selectionContainer != null) { List <ISelectable> list = this.selectionContainer.selection.ToList <ISelectable>(); Event imguiEvent = e.imguiEvent; EventType type = imguiEvent.type; if (type != EventType.DragUpdated) { if (type != EventType.DragExited) { if (type == EventType.DragPerform) { if (this.m_Active && imguiEvent.button == (int)this.activateButton && list.Count > 0) { if (list.Count > 0) { if (this.OnDrop != null) { VisualElement visualElement = base.target.panel.Pick(base.target.LocalToWorld(imguiEvent.mousePosition)); IDropTarget dropTarget = (visualElement == null) ? null : visualElement.GetFirstAncestorOfType <IDropTarget>(); this.OnDrop(e, list, dropTarget); } DragAndDrop.visualMode = DragAndDropVisualMode.None; DragAndDrop.SetGenericData("DragSelection", null); } } this.prevDropTarget = null; this.m_Active = false; base.target.ReleaseMouseCapture(); } } else { if (this.OnDrop != null && this.prevDropTarget != null) { this.OnDrop(e, list, this.prevDropTarget); } DragAndDrop.visualMode = DragAndDropVisualMode.None; DragAndDrop.SetGenericData("DragSelection", null); this.prevDropTarget = null; this.m_Active = false; base.target.ReleaseMouseCapture(); } } else if (base.target.HasMouseCapture() && imguiEvent.button == (int)this.activateButton && list.Count > 0) { this.selectedElement = null; if (this.OnDrop != null) { VisualElement visualElement2 = base.target.panel.Pick(base.target.LocalToWorld(imguiEvent.mousePosition)); IDropTarget dropTarget2 = (visualElement2 == null) ? null : visualElement2.GetFirstAncestorOfType <IDropTarget>(); if (this.prevDropTarget != dropTarget2 && this.prevDropTarget != null) { using (IMGUIEvent pooled = IMGUIEvent.GetPooled(e.imguiEvent)) { pooled.imguiEvent.type = EventType.DragExited; this.OnDrop(pooled, list, this.prevDropTarget); } } this.OnDrop(e, list, dropTarget2); this.prevDropTarget = dropTarget2; } DragAndDrop.visualMode = ((!imguiEvent.control) ? DragAndDropVisualMode.Move : DragAndDropVisualMode.Copy); } } }
protected void OnIMGUIEvent(IMGUIEvent e) { if (!m_Active || selectionContainer == null) { return; } // Keep a copy of the selection var selection = selectionContainer.selection.ToList(); Event evt = e.imguiEvent; switch (evt.type) { case EventType.DragUpdated: { if (target.HasMouseCapture() && evt.button == (int)activateButton && selection.Count > 0) { selectedElement = null; // 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? if (OnDrop != null) { var pickElem = target.panel.Pick(target.LocalToWorld(evt.mousePosition)); IDropTarget dropTarget = pickElem != null?pickElem.GetFirstAncestorOfType <IDropTarget>() : null; if (prevDropTarget != dropTarget && prevDropTarget != null) { using (IMGUIEvent eexit = IMGUIEvent.GetPooled(e.imguiEvent)) { eexit.imguiEvent.type = EventType.DragExited; OnDrop(eexit, selection, prevDropTarget); } } OnDrop(e, selection, dropTarget); prevDropTarget = dropTarget; } DragAndDrop.visualMode = evt.control ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move; } break; } case EventType.DragExited: { if (OnDrop != null && prevDropTarget != null) { OnDrop(e, selection, prevDropTarget); } DragAndDrop.visualMode = DragAndDropVisualMode.None; DragAndDrop.SetGenericData("DragSelection", null); prevDropTarget = null; m_Active = false; target.ReleaseMouseCapture(); break; } case EventType.DragPerform: { if (m_Active && evt.button == (int)activateButton && selection.Count > 0) { if (selection.Count > 0) { if (OnDrop != null) { var pickElem = target.panel.Pick(target.LocalToWorld(evt.mousePosition)); IDropTarget dropTarget = pickElem != null?pickElem.GetFirstAncestorOfType <IDropTarget>() : null; OnDrop(e, selection, dropTarget); } DragAndDrop.visualMode = DragAndDropVisualMode.None; DragAndDrop.SetGenericData("DragSelection", null); } } prevDropTarget = null; m_Active = false; target.ReleaseMouseCapture(); break; } } }
protected new void OnMouseUp(MouseUpEvent evt) { if (m_GraphView == null) { if (m_Active && target.HasMouseCapture()) { target.ReleaseMouseCapture(); selectedElement = null; m_Active = false; m_PrevDropTarget = null; } return; } List <ISelectable> selection = m_GraphView.selection; if (CanStopManipulation(evt)) { if (m_Active && target.HasMouseCapture()) { if (selectedElement == null) { m_MovedElements.Clear(); foreach (GraphElement ce in m_OriginalPos.Keys) { ce.UpdatePresenterPosition(); m_MovedElements.Add(ce); } var graphView = target as GraphView; if (graphView != null && graphView.graphViewChanged != null) { graphView.graphViewChanged(m_GraphViewChange); } } 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); } if (selection.Count > 0 && m_PrevDropTarget != null) { using (IMGUIEvent drop = IMGUIEvent.GetPooled(evt.imguiEvent)) { drop.imguiEvent.type = EventType.DragPerform; SendDragAndDropEvent(drop, selection, m_PrevDropTarget); } } target.ReleaseMouseCapture(); evt.StopPropagation(); } selectedElement = null; m_Active = false; m_PrevDropTarget = null; } }
protected new void OnMouseMove(MouseMoveEvent e) { if (!target.HasMouseCapture()) { // We lost the capture. Since we still receive mouse events, // the MouseDown target must have taken it in its ExecuteDefaultAction(). // Stop processing the event sequence, then. // FIXME: replace this by a handler on the upcoming LostCaptureEvent. m_PrevDropTarget = null; m_Active = false; } 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; Matrix4x4 g = ce.worldTransform; var scale = new Vector3(g.m00, g.m11, g.m22); Rect ceLayout = ce.GetPosition(); ce.SetPosition( new Rect(v.Value.x - (m_MouseDiff.x - m_ItemPanDiff.x) * panSpeed.x / scale.x, v.Value.y - (m_MouseDiff.y - m_ItemPanDiff.y) * panSpeed.y / scale.y, ceLayout.width, ceLayout.height)); } 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.localMousePosition); if (m_PrevDropTarget != dropTarget && m_PrevDropTarget != null) { using (IMGUIEvent eexit = IMGUIEvent.GetPooled(e.imguiEvent)) { eexit.imguiEvent.type = EventType.DragExited; SendDragAndDropEvent(eexit, selection, m_PrevDropTarget); } } using (IMGUIEvent eupdated = IMGUIEvent.GetPooled(e.imguiEvent)) { eupdated.imguiEvent.type = EventType.DragUpdated; SendDragAndDropEvent(eupdated, selection, dropTarget); } m_PrevDropTarget = dropTarget; selectedElement = null; e.StopPropagation(); }