void SelectAllTypes(bool state, EventTypeSelection eventTypeSelection = EventTypeSelection.All) { foreach (KeyValuePair <long, bool> v in m_State.ToList()) { long eventTypeId = v.Key; if (eventTypeSelection == EventTypeSelection.All || (eventTypeSelection == EventTypeSelection.Mouse && (eventTypeId == MouseMoveEvent.TypeId() || eventTypeId == MouseOverEvent.TypeId() || eventTypeId == MouseDownEvent.TypeId() || eventTypeId == MouseUpEvent.TypeId() || eventTypeId == WheelEvent.TypeId() || eventTypeId == ContextClickEvent.TypeId())) || (eventTypeSelection == EventTypeSelection.Keyboard && (eventTypeId == KeyDownEvent.TypeId() || eventTypeId == KeyUpEvent.TypeId())) || (eventTypeSelection == EventTypeSelection.Drag && (eventTypeId == DragUpdatedEvent.TypeId() || eventTypeId == DragPerformEvent.TypeId() || eventTypeId == DragExitedEvent.TypeId())) || (eventTypeSelection == EventTypeSelection.Command && (eventTypeId == ValidateCommandEvent.TypeId() || eventTypeId == ExecuteCommandEvent.TypeId()))) { m_State[eventTypeId] = state; } else { // Unaffected should be reset to false m_State[eventTypeId] = false; } } UpdateValue(); }
static void SendDragAndDropEvent(IDragAndDropEvent evt, List <ISelectable> selection, IDropTarget dropTarget, ISelection dragSource) { if (dropTarget == null) { return; } EventBase e = evt as EventBase; if (e.eventTypeId == DragExitedEvent.TypeId()) { dropTarget.DragExited(); } else if (e.eventTypeId == DragEnterEvent.TypeId()) { dropTarget.DragEnter(evt as DragEnterEvent, selection, dropTarget, dragSource); } else if (e.eventTypeId == DragLeaveEvent.TypeId()) { dropTarget.DragLeave(evt as DragLeaveEvent, selection, dropTarget, dragSource); } if (!dropTarget.CanAcceptDrop(selection)) { return; } if (e.eventTypeId == DragPerformEvent.TypeId()) { dropTarget.DragPerform(evt as DragPerformEvent, selection, dropTarget, dragSource); } else if (e.eventTypeId == DragUpdatedEvent.TypeId()) { dropTarget.DragUpdated(evt as DragUpdatedEvent, selection, dropTarget, dragSource); } }
private void OnDragUpdate(DragUpdatedEvent evt) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; }
public bool DragUpdated(DragUpdatedEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget) { HandleDragAndDropEvent(evt, selection); return(true); }
private static void DragUpdated(DragUpdatedEvent evt, (Object dockArea, IMGUIContainer container) args)
/// <summary> /// Handler for any DragUpdatedEvent passed to this element /// </summary> /// <param name="evt">event passed.</param> public virtual void OnDragUpdated(DragUpdatedEvent evt) { DragAndDrop.visualMode = CurrentDropAccepted ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; }
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; // Handle the selected element Rect selectedElementGeom = GetSelectedElementGeom(); m_ShiftClicked = e.shiftKey; if (snapEnabled && !m_ShiftClicked) { ComputeSnappedRect(ref selectedElementGeom, m_XScale); } if (snapEnabled && m_ShiftClicked) { m_Snapper.ClearSnapLines(); } 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.hierarchy.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; } SnapOrMoveElement(v, selectedElementGeom); } // 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; m_Dragging = true; e.StopPropagation(); }
private void OnDragUpdatedEvent(DragUpdatedEvent evt) { var selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>; if (selection == null) { SetDragIndicatorVisible(false); return; } if (selection.Any(t => !(t is VFXBlackboardField))) { SetDragIndicatorVisible(false); return; } Vector2 localPosition = evt.localMousePosition; m_InsertIndex = InsertionIndex(localPosition); if (m_InsertIndex != -1) { float indicatorY = 0; if (m_InsertIndex == childCount) { if (childCount > 0) { VisualElement lastChild = this[childCount - 1]; indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.style.marginBottom)).y; } else { indicatorY = this.contentRect.height; } } else { VisualElement childAtInsertIndex = this[m_InsertIndex]; indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.style.marginTop)).y; } SetDragIndicatorVisible(true); m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height); } else { SetDragIndicatorVisible(false); m_InsertIndex = -1; } if (m_InsertIndex != -1) { DragAndDrop.visualMode = evt.ctrlKey ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move; } evt.StopPropagation(); }
void UpdateEventbaseInfo(EventDebuggerEventRecord eventBase, IEventHandler focused, IEventHandler capture) { ClearEventbaseInfo(); if (eventBase == null) { return; } m_EventbaseInfo.text += "Focused element: " + EventDebugger.GetObjectDisplayName(focused) + "\n"; m_EventbaseInfo.text += "Capture element: " + EventDebugger.GetObjectDisplayName(capture) + "\n"; if (eventBase.eventTypeId == MouseMoveEvent.TypeId() || eventBase.eventTypeId == MouseOverEvent.TypeId() || eventBase.eventTypeId == MouseOutEvent.TypeId() || eventBase.eventTypeId == MouseDownEvent.TypeId() || eventBase.eventTypeId == MouseUpEvent.TypeId() || eventBase.eventTypeId == MouseEnterEvent.TypeId() || eventBase.eventTypeId == MouseLeaveEvent.TypeId() || eventBase.eventTypeId == DragEnterEvent.TypeId() || eventBase.eventTypeId == DragLeaveEvent.TypeId() || eventBase.eventTypeId == DragUpdatedEvent.TypeId() || eventBase.eventTypeId == DragPerformEvent.TypeId() || eventBase.eventTypeId == DragExitedEvent.TypeId() || eventBase.eventTypeId == ContextClickEvent.TypeId() || eventBase.eventTypeId == PointerMoveEvent.TypeId() || eventBase.eventTypeId == PointerOverEvent.TypeId() || eventBase.eventTypeId == PointerOutEvent.TypeId() || eventBase.eventTypeId == PointerDownEvent.TypeId() || eventBase.eventTypeId == PointerUpEvent.TypeId() || eventBase.eventTypeId == PointerCancelEvent.TypeId() || eventBase.eventTypeId == PointerStationaryEvent.TypeId() || eventBase.eventTypeId == PointerEnterEvent.TypeId() || eventBase.eventTypeId == PointerLeaveEvent.TypeId()) { m_EventbaseInfo.text += "Mouse position: " + eventBase.mousePosition + "\n"; m_EventbaseInfo.text += "Modifiers: " + eventBase.modifiers + "\n"; } if (eventBase.eventTypeId == KeyDownEvent.TypeId() || eventBase.eventTypeId == KeyUpEvent.TypeId()) { m_EventbaseInfo.text += "Modifiers: " + eventBase.modifiers + "\n"; } if (eventBase.eventTypeId == MouseDownEvent.TypeId() || eventBase.eventTypeId == MouseUpEvent.TypeId() || eventBase.eventTypeId == PointerDownEvent.TypeId() || eventBase.eventTypeId == PointerUpEvent.TypeId() || eventBase.eventTypeId == DragUpdatedEvent.TypeId() || eventBase.eventTypeId == DragPerformEvent.TypeId() || eventBase.eventTypeId == DragExitedEvent.TypeId()) { m_EventbaseInfo.text += "Button: " + (eventBase.button == 0 ? "Left" : eventBase.button == 1 ? "Middle" : "Right") + "\n"; m_EventbaseInfo.text += "Click count: " + eventBase.clickCount + "\n"; } if (eventBase.eventTypeId == MouseMoveEvent.TypeId() || eventBase.eventTypeId == MouseOverEvent.TypeId() || eventBase.eventTypeId == MouseOutEvent.TypeId() || eventBase.eventTypeId == MouseDownEvent.TypeId() || eventBase.eventTypeId == MouseUpEvent.TypeId() || eventBase.eventTypeId == MouseEnterEvent.TypeId() || eventBase.eventTypeId == MouseLeaveEvent.TypeId() || eventBase.eventTypeId == DragEnterEvent.TypeId() || eventBase.eventTypeId == DragLeaveEvent.TypeId() || eventBase.eventTypeId == DragUpdatedEvent.TypeId() || eventBase.eventTypeId == DragPerformEvent.TypeId() || eventBase.eventTypeId == DragExitedEvent.TypeId() || eventBase.eventTypeId == ContextClickEvent.TypeId() || eventBase.eventTypeId == WheelEvent.TypeId() || eventBase.eventTypeId == PointerMoveEvent.TypeId() || eventBase.eventTypeId == PointerOverEvent.TypeId() || eventBase.eventTypeId == PointerOutEvent.TypeId() || eventBase.eventTypeId == PointerDownEvent.TypeId() || eventBase.eventTypeId == PointerUpEvent.TypeId() || eventBase.eventTypeId == PointerCancelEvent.TypeId() || eventBase.eventTypeId == PointerStationaryEvent.TypeId() || eventBase.eventTypeId == PointerEnterEvent.TypeId() || eventBase.eventTypeId == PointerLeaveEvent.TypeId()) { m_EventbaseInfo.text += "Pressed buttons: " + eventBase.pressedButtons + "\n"; } if (eventBase.eventTypeId == WheelEvent.TypeId()) { m_EventbaseInfo.text += "Mouse delta: " + eventBase.delta + "\n"; } if (eventBase.eventTypeId == KeyDownEvent.TypeId() || eventBase.eventTypeId == KeyUpEvent.TypeId()) { if (char.IsControl(eventBase.character)) { m_EventbaseInfo.text += "Character: \\" + (byte)(eventBase.character) + "\n"; } else { m_EventbaseInfo.text += "Character: " + eventBase.character + "\n"; } m_EventbaseInfo.text += "Key code: " + eventBase.keyCode + "\n"; } if (eventBase.eventTypeId == ValidateCommandEvent.TypeId() || eventBase.eventTypeId == ExecuteCommandEvent.TypeId()) { m_EventbaseInfo.text += "Command: " + eventBase.commandName + "\n"; } }
private void OnDragUpdate(DragUpdatedEvent evt) { var visualMode = UpdateDrag(evt.mousePosition); DragAndDropUtility.dragAndDrop.SetVisualMode(visualMode); }
public void DispatchEvent(EventBase evt, IPanel panel) { if (evt.GetEventTypeId() == IMGUIEvent.TypeId()) { Event e = evt.imguiEvent; if (e.type == EventType.Repaint) { return; } } if (panel != null && panel.panelDebug != null && panel.panelDebug.enabled && panel.panelDebug.interceptEvents != null) { if (panel.panelDebug.interceptEvents(evt.imguiEvent)) { evt.StopPropagation(); return; } } IMouseEvent mouseEvent = evt as IMouseEvent; IMouseEventInternal mouseEventInternal = evt as IMouseEventInternal; if (mouseEvent != null && mouseEventInternal != null && mouseEventInternal.hasUnderlyingPhysicalEvent) { m_LastMousePosition = mouseEvent.mousePosition; } bool eventHandled = false; // Release mouse capture if capture element is not in a panel. VisualElement captureVE = MouseCaptureController.mouseCapture as VisualElement; if (evt.GetEventTypeId() != MouseCaptureOutEvent.TypeId() && captureVE != null && captureVE.panel == null) { Event e = evt.imguiEvent; Debug.Log(String.Format("Capture has no panel, forcing removal (capture={0} eventType={1})", MouseCaptureController.mouseCapture, e != null ? e.type.ToString() : "null")); MouseCaptureController.ReleaseMouseCapture(); } // Send all IMGUI events (for backward compatibility) and MouseEvents with null target (because thats what we want to do in the new system) // to the capture, if there is one. Note that events coming from IMGUI have their target set to null. bool sendEventToMouseCapture = false; bool mouseEventWasCaptured = false; if (MouseCaptureController.mouseCapture != null) { if (evt.imguiEvent != null && evt.target == null) { // Non exclusive processing by capturing element. sendEventToMouseCapture = true; mouseEventWasCaptured = false; } if (mouseEvent != null && (evt.target == null || evt.target == MouseCaptureController.mouseCapture)) { // Exclusive processing by capturing element. sendEventToMouseCapture = true; mouseEventWasCaptured = true; } if (panel != null) { if (captureVE != null && captureVE.panel.contextType != panel.contextType) { // Capturing element is not in the right context. Ignore it. sendEventToMouseCapture = false; mouseEventWasCaptured = false; } } } evt.skipElement = null; if (sendEventToMouseCapture) { IEventHandler originalCaptureElement = MouseCaptureController.mouseCapture; eventHandled = true; evt.dispatch = true; evt.target = MouseCaptureController.mouseCapture; evt.currentTarget = MouseCaptureController.mouseCapture; evt.propagationPhase = PropagationPhase.AtTarget; MouseCaptureController.mouseCapture.HandleEvent(evt); // Do further processing with a target computed the usual way. // However, if mouseEventWasCaptured, the only thing remaining to do is ExecuteDefaultAction, // which whould be done with mouseCapture as the target. if (!mouseEventWasCaptured) { evt.target = null; } evt.currentTarget = null; evt.propagationPhase = PropagationPhase.None; evt.dispatch = false; // Do not call HandleEvent again for this element. evt.skipElement = originalCaptureElement; } if (!mouseEventWasCaptured && !evt.isPropagationStopped) { if (evt is IKeyboardEvent && panel != null) { eventHandled = true; if (panel.focusController.focusedElement != null) { IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer; if (imguiContainer != null) { // THINK ABOUT THIS PF: shoudln't we allow for the capture dispatch phase? if (imguiContainer != evt.skipElement && imguiContainer.HandleIMGUIEvent(evt.imguiEvent)) { evt.StopPropagation(); evt.PreventDefault(); } } else { evt.target = panel.focusController.focusedElement; PropagateEvent(evt); } } else { evt.target = panel.visualTree; PropagateEvent(evt); if (!evt.isPropagationStopped) { PropagateToIMGUIContainer(panel.visualTree, evt); } } } else if (mouseEvent != null) { // FIXME: we should not change hover state when capture is true. // However, when doing drag and drop, drop target should be highlighted. // TODO when EditorWindow is docked MouseLeaveWindow is not always sent // this is a problem in itself but it could leave some elements as "hover" if (evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId()) { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; m_TopElementUnderMouse = null; DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } else if (evt.GetEventTypeId() == DragExitedEvent.TypeId()) { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; m_TopElementUnderMouse = null; DispatchDragEnterDragLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } // update element under mouse and fire necessary events else { VisualElement currentTopElementUnderMouse = m_TopElementUnderMouse; if (evt.target == null && panel != null) { m_TopElementUnderMouse = panel.Pick(mouseEvent.mousePosition); evt.target = m_TopElementUnderMouse; } if (evt.target != null) { eventHandled = true; PropagateEvent(evt); } if (evt.GetEventTypeId() == MouseMoveEvent.TypeId() || evt.GetEventTypeId() == MouseDownEvent.TypeId() || evt.GetEventTypeId() == MouseUpEvent.TypeId() || evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() || evt.GetEventTypeId() == WheelEvent.TypeId()) { DispatchMouseEnterMouseLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); DispatchMouseOverMouseOut(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } else if (evt.GetEventTypeId() == DragUpdatedEvent.TypeId()) { DispatchDragEnterDragLeave(currentTopElementUnderMouse, m_TopElementUnderMouse, mouseEvent); } } } else if (panel != null && evt is ICommandEvent) { IMGUIContainer imguiContainer = panel.focusController.focusedElement as IMGUIContainer; eventHandled = true; if (imguiContainer != null) { if (imguiContainer != evt.skipElement && imguiContainer.HandleIMGUIEvent(evt.imguiEvent)) { evt.StopPropagation(); evt.PreventDefault(); } } else if (panel.focusController.focusedElement != null) { evt.target = panel.focusController.focusedElement; PropagateEvent(evt); } else { PropagateToIMGUIContainer(panel.visualTree, evt); } } else if (evt is IPropagatableEvent || evt is IFocusEvent || evt is IChangeEvent || evt.GetEventTypeId() == InputEvent.TypeId() || evt.GetEventTypeId() == GeometryChangedEvent.TypeId()) { Debug.Assert(evt.target != null); eventHandled = true; PropagateEvent(evt); } } if (!mouseEventWasCaptured && !evt.isPropagationStopped && panel != null) { Event e = evt.imguiEvent; if (!eventHandled || (e != null && e.type == EventType.Used) || evt.GetEventTypeId() == MouseEnterWindowEvent.TypeId() || evt.GetEventTypeId() == MouseLeaveWindowEvent.TypeId()) { PropagateToIMGUIContainer(panel.visualTree, evt); } } if (evt.target == null && panel != null) { evt.target = panel.visualTree; } ExecuteDefaultAction(evt); }
public bool DragUpdated(DragUpdatedEvent evt, IEnumerable <ISelectable> dragSelection, IDropTarget dropTarget, ISelection dragSource) { return((m_GraphView as IDropTarget)?.DragUpdated(evt, dragSelection, dropTarget, dragSource) ?? false); }
/// <inheritdoc /> public override void OnDragUpdated(DragUpdatedEvent e) { DragAndDrop.visualMode = e.ctrlKey ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Move; }
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(); }
bool IDropTarget.DragUpdated(DragUpdatedEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget, ISelection dragSource) { return(((IDropTarget)handler).DragUpdated(evt, selection, dropTarget, dragSource)); }
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 USE_DRAG_RESET_WHEN_OUT_OF_GRAPH_VIEW // We currently don't have a real use case for this and it just appears to annoy users. // If and when the use case arise, we can revive this functionality. if (gvMousePos.x < 0 || gvMousePos.y < 0 || gvMousePos.x > m_GraphView.layout.width || gvMousePos.y > m_GraphView.layout.height) { if (!m_GoneOut) { m_PanSchedule.Pause(); foreach (KeyValuePair <GraphElement, Rect> v in m_OriginalPos) { v.Key.SetPosition(v.Value); } m_GoneOut = true; } e.StopPropagation(); return; } if (m_GoneOut) { m_GoneOut = false; } #endif 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.hierarchy.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); } foreach (var edge in m_EdgesToUpdate) { UpdateEdge(edge); } // 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(); }
public virtual void OnDragUpdated(DragUpdatedEvent e) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; }
public void HandleDragUpdated(DragUpdatedEvent e, DragNDropContext ctx) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; }
public bool DragUpdated(DragUpdatedEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget) { return(true); }
internal void CommitElementUnderPointers(EventDispatcher dispatcher) { for (var i = 0; i < m_TopElementUnderPointer.Length; i++) { var triggerPointerEvent = m_TriggerPointerEvent[i]; var previous = m_TopElementUnderPointer[i]; var current = m_PendingTopElementUnderPointer[i]; if (current == previous) { if (triggerPointerEvent != null) { var pos3d = triggerPointerEvent.position; m_PickingPointerPositions[i] = new Vector2(pos3d.x, pos3d.y); } else if (m_TriggerMouseEvent[i] != null) { m_PickingPointerPositions[i] = m_TriggerMouseEvent[i].mousePosition; } continue; } m_TopElementUnderPointer[i] = current; if (triggerPointerEvent == null && m_TriggerMouseEvent[i] == null) { using (new EventDispatcherGate(dispatcher)) { Vector2 position = PointerDeviceState.GetPointerPosition(i); PointerEventsHelper.SendOverOut(previous, current, null, position, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, null, position, i); m_PickingPointerPositions[i] = position; if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(previous, current, null, position); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, null, position); } } } if (triggerPointerEvent != null) { var pos3d = triggerPointerEvent.position; m_PickingPointerPositions[i] = new Vector2(pos3d.x, pos3d.y); var baseEvent = triggerPointerEvent as EventBase; if (baseEvent != null && ( baseEvent.eventTypeId == PointerMoveEvent.TypeId() || baseEvent.eventTypeId == PointerDownEvent.TypeId() || baseEvent.eventTypeId == PointerUpEvent.TypeId() || baseEvent.eventTypeId == PointerCancelEvent.TypeId())) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(previous, current, triggerPointerEvent, pos3d, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, triggerPointerEvent, pos3d, i); } } } m_TriggerPointerEvent[i] = null; var triggerMouseEvent = m_TriggerMouseEvent[i]; if (triggerMouseEvent != null) { Vector2 mousePos = triggerMouseEvent.mousePosition; m_PickingPointerPositions[i] = mousePos; var baseEvent = triggerMouseEvent as EventBase; if (baseEvent != null) { if (baseEvent.eventTypeId == MouseMoveEvent.TypeId() || baseEvent.eventTypeId == MouseDownEvent.TypeId() || baseEvent.eventTypeId == MouseUpEvent.TypeId() || baseEvent.eventTypeId == WheelEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, triggerMouseEvent, mousePos); } } else if (baseEvent.eventTypeId == MouseEnterWindowEvent.TypeId() || baseEvent.eventTypeId == MouseLeaveWindowEvent.TypeId() ) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(previous, current, null, mousePos, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, null, mousePos, i); if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, triggerMouseEvent, mousePos); } } } else if (baseEvent.eventTypeId == DragUpdatedEvent.TypeId() || baseEvent.eventTypeId == DragExitedEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(previous, current, null, mousePos, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( previous, current, null, mousePos, i); MouseEventsHelper.SendMouseOverMouseOut(previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( previous, current, triggerMouseEvent, mousePos); MouseEventsHelper.SendEnterLeave <DragLeaveEvent, DragEnterEvent>( previous, current, triggerMouseEvent, mousePos); } } } m_TriggerMouseEvent[i] = null; } } }
private void OnDragUpdatedEvent(DragUpdatedEvent evt) { var selection = DragAndDrop.GetGenericData("DragSelection") as List <ISelectable>; if (!CanAcceptDrop(selection)) { SetDragIndicatorVisible(false); return; } VisualElement sourceItem = null; foreach (ISelectable selectedElement in selection) { sourceItem = selectedElement as VisualElement; if (sourceItem == null) { continue; } } if (!Contains(sourceItem)) { SetDragIndicatorVisible(false); return; } Vector2 localPosition = evt.localMousePosition; m_InsertIndex = InsertionIndex(localPosition); if (m_InsertIndex != -1) { float indicatorY = 0; if (m_InsertIndex == childCount) { VisualElement lastChild = this[childCount - 1]; indicatorY = lastChild.ChangeCoordinatesTo(this, new Vector2(0, lastChild.layout.height + lastChild.resolvedStyle.marginBottom)).y; } else { VisualElement childAtInsertIndex = this[m_InsertIndex]; indicatorY = childAtInsertIndex.ChangeCoordinatesTo(this, new Vector2(0, -childAtInsertIndex.resolvedStyle.marginTop)).y; } SetDragIndicatorVisible(true); m_DragIndicator.layout = new Rect(0, indicatorY - m_DragIndicator.layout.height / 2, layout.width, m_DragIndicator.layout.height); } else { SetDragIndicatorVisible(false); m_InsertIndex = -1; } if (m_InsertIndex != -1) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; } evt.StopPropagation(); }
internal void CommitElementUnderPointers(EventDispatcher dispatcher) { for (var i = 0; i < m_TopElementUnderPointer.Length; i++) { if (m_TopElementUnderPointer[i] == m_PendingTopElementUnderPointer[i]) { continue; } if (m_TriggerPointerEvent[i] == null && m_TriggerMouseEvent[i] == null) { using (new EventDispatcherGate(dispatcher)) { Vector2 position = PointerDeviceState.GetPointerPosition(i); PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position, i); if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, position); } } } if (m_TriggerPointerEvent[i] != null) { if ((m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerMoveEvent.TypeId() || (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerDownEvent.TypeId() || (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerUpEvent.TypeId() || (m_TriggerPointerEvent[i] as EventBase)?.eventTypeId == PointerCancelEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerPointerEvent[i], m_TriggerPointerEvent[i].position, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerPointerEvent[i], m_TriggerPointerEvent[i].position, i); } } m_TriggerPointerEvent[i] = null; } if (m_TriggerMouseEvent[i] != null) { if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseMoveEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseDownEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseUpEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == WheelEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); } } else if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseEnterWindowEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == MouseLeaveWindowEvent.TypeId() ) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); if (i == PointerId.mousePointerId) { MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); } } } else if ((m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == DragUpdatedEvent.TypeId() || (m_TriggerMouseEvent[i] as EventBase)?.eventTypeId == DragExitedEvent.TypeId()) { using (new EventDispatcherGate(dispatcher)) { PointerEventsHelper.SendOverOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); PointerEventsHelper.SendEnterLeave <PointerLeaveEvent, PointerEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], null, m_TriggerMouseEvent[i].mousePosition, i); MouseEventsHelper.SendMouseOverMouseOut(m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <MouseLeaveEvent, MouseEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); MouseEventsHelper.SendEnterLeave <DragLeaveEvent, DragEnterEvent>( m_TopElementUnderPointer[i], m_PendingTopElementUnderPointer[i], m_TriggerMouseEvent[i], m_TriggerMouseEvent[i].mousePosition); } } m_TriggerMouseEvent[i] = null; } m_TopElementUnderPointer[i] = m_PendingTopElementUnderPointer[i]; } }
public virtual bool DragUpdated(DragUpdatedEvent evt, IEnumerable <ISelectable> selection, IDropTarget dropTarget, ISelection dragSource) { HandleDragAndDropEvent(evt); return(true); }
/// <summary> /// Callback for the MouseMove event. /// </summary> /// <param name="e">The event.</param> protected 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; if (m_SelectedElement.parent != null) { // Handle the selected element Rect selectedElementGeom = GetSelectedElementGeom(); ComputeSnappedRect(ref selectedElementGeom, m_SelectedElement); 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.hierarchy.parent == null) { continue; } if (!v.Value.dragStarted) { v.Value.dragStarted = true; } SnapOrMoveElement(v.Key, v.Value.pos, selectedElementGeom); } foreach (var edge in m_EdgesToUpdate) { SnapOrMoveEdge(edge, selectedElementGeom); } } var selection = m_GraphView.GetSelection(); var selectedUI = selection.Select(m => m.GetUI(m_GraphView)); // 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? var previousDropTarget = m_CurrentDropTarget; m_CurrentDropTarget = GetDropTargetAt(e.mousePosition, selectedUI.OfType <VisualElement>().ToList()); if (m_CurrentDropTarget != previousDropTarget) { if (previousDropTarget != null) { using (DragLeaveEvent eLeave = DragLeaveEvent.GetPooled(e)) { eLeave.target = previousDropTarget; m_GraphView.SendEvent(eLeave); } } if (m_CurrentDropTarget != null) { using (DragEnterEvent eEnter = DragEnterEvent.GetPooled(e)) { eEnter.target = m_CurrentDropTarget; m_GraphView.SendEvent(eEnter); } } } if (m_CurrentDropTarget != null) { using (DragUpdatedEvent eUpdated = DragUpdatedEvent.GetPooled(e)) { eUpdated.target = m_CurrentDropTarget; m_GraphView.SendEvent(eUpdated); } } m_Dragging = true; e.StopPropagation(); }