Esempio n. 1
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();
            }
        }
Esempio n. 2
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";
            }
        }
Esempio n. 5
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];
            }
        }
Esempio n. 6
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;
        }
Esempio n. 7
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;
                }
            }
        }