void OnDragExitedEvent(DragExitedEvent e)
        {
            Debug.Log("OnDragExitedEvent");
            object draggedLabel = DragAndDrop.GetGenericData(DraggableLabel.s_DragDataType);

            m_DropArea.RemoveFromClassList("dragover");
        }
Exemple #2
0
        /// <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();
        }
Exemple #3
0
 private void OnDragExitedEvent(DragExitedEvent evt)
 {
     if (onDragExited != null)
     {
         onDragExited(evt);
         evt.StopImmediatePropagation();
     }
 }
Exemple #4
0
        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();
        }
Exemple #5
0
        void DragExit(DragExitedEvent evt)
        {
            foreach (UnityEngine.Object obj in DragAndDrop.objectReferences)
            {
                if (!IsInAcceptedTypes(obj.GetType()))
                {
                    continue;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                evt.StopPropagation();
                return;
            }
        }
Exemple #6
0
        static void SendDragAndDropEvent(IDragAndDropEvent evt, List <ISelectable> selection, IDropTarget dropTarget)
        {
            if (dropTarget == null || !dropTarget.CanAcceptDrop(selection))
            {
                return;
            }
            EventBase e = evt as EventBase;

            if (e.GetEventTypeId() == DragPerformEvent.TypeId())
            {
                dropTarget.DragPerform(evt as DragPerformEvent, selection, dropTarget);
            }
            else if (e.GetEventTypeId() == DragUpdatedEvent.TypeId())
            {
                dropTarget.DragUpdated(evt as DragUpdatedEvent, selection, dropTarget);
            }
            else if (e.GetEventTypeId() == DragExitedEvent.TypeId())
            {
                dropTarget.DragExited();
            }
        }
        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();
        }
Exemple #8
0
        /// <summary>
        /// Callback for the MouseCaptureOut event.
        /// </summary>
        /// <param name="e">The event.</param>
        protected void OnMouseCaptureOutEvent(MouseCaptureOutEvent e)
        {
            if (m_Active)
            {
                if (m_CurrentDropTarget != null && m_GraphView != null)
                {
                    using (DragExitedEvent eExit = DragExitedEvent.GetPooled())
                    {
                        eExit.target = m_CurrentDropTarget;
                        m_GraphView.SendEvent(eExit);
                    }
                }

                // Stop processing the event sequence if the target has lost focus, then.
                m_SelectedElement   = null;
                m_CurrentDropTarget = null;
                m_Active            = false;

                if (m_GraphView?.GetSelection().Any() ?? false)
                {
                    m_Snapper.EndSnap();
                }
            }
        }
Exemple #9
0
        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);
            }
        }
        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();
        }
        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";
            }
        }
Exemple #12
0
 void OnDragEnteredEvent(DragExitedEvent evt)
 {
     OnDragExited(evt.DraggableObject, evt.TargetCollider);
 }
 public virtual void OnDragExited(DragExitedEvent e)
 {
 }
Exemple #14
0
 private void OnDragExitedEvent(DragExitedEvent evt)
 {
     ClearDragAndDropUI();
 }
 private static void OnDragExited(DragExitedEvent evt)
 {
 }
Exemple #16
0
 /// <summary>
 /// Handler for any DragExitedEvent passed to this element
 /// </summary>
 /// <param name="evt">event passed.</param>
 public virtual void OnDragExited(DragExitedEvent evt)
 {
     OnDragEnd();
 }
Exemple #17
0
        public void DispatchEvent(EventBase evt, IPanel panel)
        {
            IMouseEvent mouseEvent = evt as IMouseEvent;

            // 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"

            BaseVisualElementPanel basePanel = panel as BaseVisualElementPanel;

            if (basePanel != null && (evt.eventTypeId == MouseLeaveWindowEvent.TypeId() || evt.eventTypeId == DragExitedEvent.TypeId()))
            {
                basePanel.SetElementUnderPointer(null, evt);
            }
            else
            {
                // update element under mouse and fire necessary events
                if (basePanel != null)
                {
                    bool shouldRecomputeTopElementUnderMouse = true;
                    if ((IMouseEventInternal)mouseEvent != null)
                    {
                        shouldRecomputeTopElementUnderMouse =
                            ((IMouseEventInternal)mouseEvent).recomputeTopElementUnderMouse;
                    }

                    VisualElement elementUnderMouse = shouldRecomputeTopElementUnderMouse
                        ? basePanel.Pick(mouseEvent.mousePosition)
                        : basePanel.GetTopElementUnderPointer(PointerId.mousePointerId);

                    if (evt.target == null)
                    {
                        evt.target = elementUnderMouse;
                    }

                    basePanel.SetElementUnderPointer(elementUnderMouse, evt);
                }

                if (evt.target != null)
                {
                    evt.propagateToIMGUI = false;
                    EventDispatchUtilities.PropagateEvent(evt);
                }
            }

            if (!evt.isPropagationStopped && panel != null)
            {
                if (evt.propagateToIMGUI ||
                    evt.eventTypeId == MouseEnterWindowEvent.TypeId() ||
                    evt.eventTypeId == MouseLeaveWindowEvent.TypeId()
                    )
                {
                    EventDispatchUtilities.PropagateToIMGUIContainer(panel.visualTree, evt);
                }
            }

            evt.stopDispatch = true;
        }
Exemple #18
0
        /// <summary>
        /// Callback for the MouseUp event.
        /// </summary>
        /// <param name="evt">The event.</param>
        protected void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active)
                {
                    target.ReleaseMouse();
                    m_SelectedElement   = null;
                    m_Active            = false;
                    m_Dragging          = false;
                    m_CurrentDropTarget = null;
                }

                return;
            }

            var selectedModels = m_GraphView.GetSelection();

            if (CanStopManipulation(evt))
            {
                if (m_Active)
                {
                    if (m_Dragging || m_SelectedElement == null)
                    {
                        if (target is GraphView graphView)
                        {
                            graphView.StopSelectionDragger();
                            graphView.PositionDependenciesManager.StopNotifyMove();
                        }

                        // if we stop dragging on something else than a DropTarget, just move elements
                        if (m_GraphView != null && (m_CurrentDropTarget == null || !m_CurrentDropTarget.CanAcceptDrop(selectedModels)))
                        {
                            var movedElements = new HashSet <GraphElement>(m_OriginalPos.Keys);
                            movedElements.AddRangeInternal(m_EdgesToUpdate);

                            KeyValuePair <GraphElement, OriginalPos> firstPos = m_OriginalPos.First();
                            var delta  = firstPos.Key.GetPosition().position - firstPos.Value.pos.position;
                            var models = movedElements
                                         // PF remove this Where clause. It comes from VseGraphView.OnGraphViewChanged.
                                         .Where(e => !(e.Model is INodeModel) || e.IsMovable())
                                         .Select(e => e.Model)
                                         .OfType <IMovable>();
                            m_GraphView.CommandDispatcher.Dispatch(
                                new MoveElementsCommand(delta, models.ToList()));
                        }
                    }

                    foreach (var edge in m_EdgesToUpdate)
                    {
                        edge.EdgeControl.ControlPointOffset = Vector2.zero;
                    }
                    m_EdgesToUpdate.Clear();

                    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));
                    }

                    if (selectedModels.Count > 0 && m_CurrentDropTarget != null)
                    {
                        if (m_CurrentDropTarget.CanAcceptDrop(selectedModels))
                        {
                            using (DragPerformEvent ePerform = DragPerformEvent.GetPooled(evt))
                            {
                                ePerform.target = m_CurrentDropTarget;
                                m_GraphView.SendEvent(ePerform);
                            }
                        }
                        else
                        {
                            using (DragExitedEvent eExit = DragExitedEvent.GetPooled(evt))
                            {
                                eExit.target = m_CurrentDropTarget;
                                m_GraphView.SendEvent(eExit);
                            }
                        }
                    }

                    if (selectedModels.Any())
                    {
                        m_Snapper.EndSnap();
                    }

                    target.ReleaseMouse();
                    evt.StopPropagation();
                }
                m_SelectedElement   = null;
                m_Active            = false;
                m_CurrentDropTarget = null;
                m_Dragging          = false;
                m_CurrentDropTarget = null;
            }
        }
        protected new void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active)
                {
                    target.ReleaseMouse();
                    selectedElement  = null;
                    m_Active         = false;
                    m_PrevDropTarget = null;
                }

                return;
            }

            List <ISelectable> selection = m_GraphView.selection;

            if (CanStopManipulation(evt))
            {
                if (m_Active)
                {
                    foreach (var edge in m_EdgesToUpdate)
                    {
                        edge.EdgeControl.ControlPointOffset = Vector2.zero;
                    }
                    m_EdgesToUpdate.Clear();

                    if (selectedElement == null)
                    {
                        m_MovedElements.Clear();

                        foreach (IGrouping <StackNode, GraphElement> grouping in m_OriginalPos.GroupBy(v => v.Value.stack, v => v.Key))
                        {
                            if (grouping.Key != null && m_GraphView.elementsRemovedFromStackNode != null)
                            {
                                m_GraphView.elementsRemovedFromStackNode(grouping.Key, grouping);
                            }

                            m_MovedElements.AddRange(grouping);
                        }

                        // PF: remove graphViewChanged and all.
                        var graphView = target as GraphView;
                        if (graphView?.graphViewChanged != null)
                        {
                            KeyValuePair <GraphElement, OriginalPos> firstPos = m_OriginalPos.First();
                            m_GraphViewChange.moveDelta = firstPos.Key.GetPosition().position - firstPos.Value.pos.position;
                            graphView.graphViewChanged(m_GraphViewChange);
                        }

                        if (m_GraphView != null)
                        {
                            KeyValuePair <GraphElement, OriginalPos> firstPos = m_OriginalPos.First();
                            var delta  = firstPos.Key.GetPosition().position - firstPos.Value.pos.position;
                            var models = m_OriginalPos.Keys
                                         // PF remove this Where clause. It comes from VseGraphView.OnGraphViewChanged.
                                         .Where(e => e is IMovable movable && (!(e.Model is IGTFNodeModel) || movable.IsMovable))
                                         .Select(e => e.Model)
                                         .OfType <IPositioned>();
                            m_GraphView.Store.Dispatch(new MoveElementsAction(delta, models.ToArray()));
                        }
                    }

                    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)
                    {
                        if (m_PrevDropTarget.CanAcceptDrop(selection))
                        {
                            using (DragPerformEvent drop = DragPerformEvent.GetPooled(evt))
                            {
                                SendDragAndDropEvent(drop, selection, m_PrevDropTarget, m_GraphView);
                            }
                        }
                        else
                        {
                            using (DragExitedEvent dexit = DragExitedEvent.GetPooled(evt))
                            {
                                SendDragAndDropEvent(dexit, selection, m_PrevDropTarget, m_GraphView);
                            }
                        }
                    }

                    target.ReleaseMouse();
                    evt.StopPropagation();
                }
                selectedElement  = null;
                m_Active         = false;
                m_PrevDropTarget = null;
            }
        }
Exemple #20
0
 private void OnDragEnteredEvent(DragExitedEvent evt)
 {
     OnDragExited(evt.DraggableObject, evt.TargetCollider);
 }
Exemple #21
0
 protected virtual void OnDragExitedEvent(DragExitedEvent obj)
 {
     RemoveDragIndicator();
     m_DragStarted = false;
 }
Exemple #22
0
        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();
        }
Exemple #23
0
        protected new void OnMouseUp(MouseUpEvent evt)
        {
            if (m_GraphView == null)
            {
                if (m_Active)
                {
                    target.ReleaseMouse();
                    selectedElement  = null;
                    m_Active         = false;
                    m_Dragging       = false;
                    m_PrevDropTarget = null;
                }

                return;
            }

            List <ISelectable> selection = m_GraphView.selection;

            if (CanStopManipulation(evt))
            {
                if (m_Active)
                {
                    if (m_Dragging)
                    {
                        foreach (IGrouping <StackNode, GraphElement> grouping in m_OriginalPos.GroupBy(v => v.Value.stack, v => v.Key))
                        {
                            if (grouping.Key != null && m_GraphView.elementsRemovedFromStackNode != null)
                            {
                                m_GraphView.elementsRemovedFromStackNode(grouping.Key, grouping);
                            }

                            foreach (GraphElement ge in grouping)
                            {
                                ge.UpdatePresenterPosition();
                            }

                            m_MovedElements.AddRange(grouping);
                        }

                        var graphView = target as GraphView;
                        if (graphView != null && graphView.graphViewChanged != null)
                        {
                            KeyValuePair <GraphElement, OriginalPos> firstPos = m_OriginalPos.First();
                            m_GraphViewChange.moveDelta = firstPos.Key.GetPosition().position - firstPos.Value.pos.position;
                            graphView.graphViewChanged(m_GraphViewChange);
                        }
                        m_MovedElements.Clear();
                    }

                    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)
                    {
                        if (m_PrevDropTarget.CanAcceptDrop(selection))
                        {
                            using (DragPerformEvent drop = DragPerformEvent.GetPooled(evt))
                            {
                                SendDragAndDropEvent(drop, selection, m_PrevDropTarget, m_GraphView);
                            }
                        }
                        else
                        {
                            using (DragExitedEvent dexit = DragExitedEvent.GetPooled(evt))
                            {
                                SendDragAndDropEvent(dexit, selection, m_PrevDropTarget, m_GraphView);
                            }
                        }
                    }

                    if (snapEnabled)
                    {
                        m_Snapper.EndSnap(m_GraphView);
                    }

                    target.ReleaseMouse();
                    evt.StopPropagation();
                }

                selectedElement  = null;
                m_Active         = false;
                m_PrevDropTarget = null;
                m_Dragging       = false;
                m_PrevDropTarget = null;
            }
        }
Exemple #24
0
        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];
            }
        }
Exemple #25
0
        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;
                }
            }
        }
Exemple #26
0
 static void OnDragExited(DragExitedEvent evt)
 {
     MouseLeave(evt);
 }