Ejemplo n.º 1
0
        internal static ClickEvent GetPooled(PointerUpEvent pointerEvent, int clickCount)
        {
            ClickEvent pooled = PointerEventBase <ClickEvent> .GetPooled(pointerEvent);

            pooled.clickCount = clickCount;
            return(pooled);
        }
Ejemplo n.º 2
0
        private void OnPointerUp(PointerUpEvent evt)
        {
            if (!HasValidDataAndBindings())
            {
                return;
            }

            if (!evt.isPrimary)
            {
                return;
            }

            if (evt.button != (int)MouseButton.LeftMouse)
            {
                return;
            }

            if (evt.pointerType != PointerType.mouse)
            {
                var delay = evt.timestamp - m_TouchDownTime;
                var delta = evt.position - m_TouchDownPosition;
                if (delay < 500 && delta.sqrMagnitude <= 100)
                {
                    DoSelect(evt.localPosition, evt.clickCount, evt.actionKey, evt.shiftKey);
                }
            }
        }
Ejemplo n.º 3
0
        internal static ClickEvent GetPooled(PointerUpEvent pointerEvent, int clickCount)
        {
            var evt = PointerEventBase <ClickEvent> .GetPooled(pointerEvent);

            evt.clickCount = clickCount;
            return(evt);
        }
Ejemplo n.º 4
0
        private void OnPointerUp(PointerUpEvent evt)
        {
            bool flag = evt.pointerId == this.m_ScrollingPointerId;

            if (flag)
            {
                evt.currentTarget.ReleasePointer(evt.pointerId);
                evt.StopPropagation();
                bool flag2 = this.touchScrollBehavior == ScrollView.TouchScrollBehavior.Elastic || this.hasInertia;
                if (flag2)
                {
                    this.ComputeInitialSpringBackVelocity();
                    bool flag3 = this.m_PostPointerUpAnimation == null;
                    if (flag3)
                    {
                        this.m_PostPointerUpAnimation = base.schedule.Execute(new Action(this.PostPointerUpAnimation)).Every(30L);
                    }
                    else
                    {
                        this.m_PostPointerUpAnimation.Resume();
                    }
                }
                this.m_ScrollingPointerId = PointerId.invalidPointerId;
            }
        }
Ejemplo n.º 5
0
 protected void OnPointerUp(PointerUpEvent evt)
 {
     if (IsNotMouseEvent(evt) && active && CanStopManipulation(evt))
     {
         ProcessUpEvent(evt, evt.localPosition, evt.pointerId);
     }
 }
 // In order for tests to run without an EditorWindow but still be able to send
 // events, we sometimes need to force the event type. IMGUI::GetEventType() (native) will
 // return the event type as Ignore if the proper views haven't yet been
 // initialized. This (falsely) breaks tests that rely on the event type. So for tests, we
 // just ensure the event type is what we originally set it to when we sent it.
 internal static EventBase CreateEvent(Event systemEvent, EventType eventType)
 {
     switch (eventType)
     {
         case EventType.MouseMove:
             return PointerMoveEvent.GetPooled(systemEvent);
         case EventType.MouseDrag:
             return PointerMoveEvent.GetPooled(systemEvent);
         case EventType.MouseDown:
             // If some buttons are already down, we generate PointerMove/MouseDown events.
             // Otherwise we generate PointerDown/MouseDown events.
             // See W3C pointer events recommendation: https://www.w3.org/TR/pointerevents2
             if (PointerDeviceState.GetPressedButtons(PointerId.mousePointerId) != 0)
             {
                 return PointerMoveEvent.GetPooled(systemEvent);
             }
             else
             {
                 return PointerDownEvent.GetPooled(systemEvent);
             }
         case EventType.MouseUp:
             // If more buttons are still down, we generate PointerMove/MouseUp events.
             // Otherwise we generate PointerUp/MouseUp events.
             // See W3C pointer events recommendation: https://www.w3.org/TR/pointerevents2
             if (PointerDeviceState.HasAdditionalPressedButtons(PointerId.mousePointerId, systemEvent.button))
             {
                 return PointerMoveEvent.GetPooled(systemEvent);
             }
             else
             {
                 return PointerUpEvent.GetPooled(systemEvent);
             }
         case EventType.ContextClick:
             return ContextClickEvent.GetPooled(systemEvent);
         case EventType.MouseEnterWindow:
             return MouseEnterWindowEvent.GetPooled(systemEvent);
         case EventType.MouseLeaveWindow:
             return MouseLeaveWindowEvent.GetPooled(systemEvent);
         case EventType.ScrollWheel:
             return WheelEvent.GetPooled(systemEvent);
         case EventType.KeyDown:
             return KeyDownEvent.GetPooled(systemEvent);
         case EventType.KeyUp:
             return KeyUpEvent.GetPooled(systemEvent);
         case EventType.DragUpdated:
             return DragUpdatedEvent.GetPooled(systemEvent);
         case EventType.DragPerform:
             return DragPerformEvent.GetPooled(systemEvent);
         case EventType.DragExited:
             return DragExitedEvent.GetPooled(systemEvent);
         case EventType.ValidateCommand:
             return ValidateCommandEvent.GetPooled(systemEvent);
         case EventType.ExecuteCommand:
             return ExecuteCommandEvent.GetPooled(systemEvent);
         default:// Layout, Ignore, Used
             return IMGUIEvent.GetPooled(systemEvent);
     }
 }
        protected void OnPointerUp(PointerUpEvent evt)
        {
            bool flag = evt.pointerId != PointerId.mousePointerId && base.active && base.CanStopManipulation(evt);

            if (flag)
            {
                this.ProcessUpEvent(evt, evt.localPosition, evt.pointerId);
            }
        }
Ejemplo n.º 8
0
        private bool IsLocalEvent(EventBase evt)
        {
            long evtType = evt.eventTypeId;

            return(evtType == MouseDownEvent.TypeId() || evtType == MouseUpEvent.TypeId() ||
                   evtType == MouseMoveEvent.TypeId() ||
                   evtType == PointerDownEvent.TypeId() || evtType == PointerUpEvent.TypeId() ||
                   evtType == PointerMoveEvent.TypeId());
        }
Ejemplo n.º 9
0
        public void ProcessEvent(EventBase evt)
        {
            IPointerEvent pe = evt as IPointerEvent;

            if (pe == null)
            {
                return;
            }

            if (evt.eventTypeId == PointerDownEvent.TypeId() && pe.button == 0)
            {
                StartClickTracking(evt);
            }
            else if (evt.eventTypeId == PointerMoveEvent.TypeId())
            {
                // Button 1 pressed while another button was already pressed.
                if (pe.button == 0 && (pe.pressedButtons & 1) == 1)
                {
                    StartClickTracking(evt);
                }
                // Button 1 released while another button is still pressed.
                else if (pe.button == 0 && (pe.pressedButtons & 1) == 0)
                {
                    SendClickEvent(evt);
                }
                // Pointer moved or other button pressed/released
                else
                {
                    var clickStatus = m_ClickStatus[pe.pointerId];
                    if (clickStatus.m_Target != null)
                    {
                        // stop the multi-click sequence on move
                        clickStatus.m_LastPointerDownTime = 0;
                    }
                }
            }
            else if (evt.eventTypeId == PointerCancelEvent.TypeId() ||
                     evt.eventTypeId == DragUpdatedEvent.TypeId()
                     )
            {
                CancelClickTracking(evt);

                // Note that we don't cancel the click when we have a PointerStationaryEvent anymore. Touch stationary
                // events are sent on each frame where the touch doesn't move, starting immediately after the frame
                // where the touch begin event occured. If we want to cancel the ClickEvent after the touch has been
                // idle for some time, then we need to manually track the duration of the stationary phase.
            }
            else if (evt.eventTypeId == PointerUpEvent.TypeId() && pe.button == 0)
            {
                SendClickEvent(evt);
            }
        }
        void OnPointerUp(PointerUpEvent evt)
        {
            var selectedIndex = GetSelectedIndex();

            if (selectedIndex != -1)
            {
                var item = m_Items[selectedIndex];
                item.action?.Invoke();
                item.actionUserData?.Invoke(item.element.userData);

                Hide();
            }
        }
Ejemplo n.º 11
0
        public void ProcessEvent(EventBase evt)
        {
            IPointerEvent pe = evt as IPointerEvent;

            if (pe == null)
            {
                return;
            }

            if (evt.eventTypeId == PointerDownEvent.TypeId() && pe.button == 0)
            {
                StartClickTracking(evt);
            }
            else if (evt.eventTypeId == PointerMoveEvent.TypeId())
            {
                // Button 1 pressed while another button was already pressed.
                if (pe.button == 0 && (pe.pressedButtons & 1) == 1)
                {
                    StartClickTracking(evt);
                }
                // Button 1 released while another button is still pressed.
                else if (pe.button == 0 && (pe.pressedButtons & 1) == 0)
                {
                    SendClickEvent(evt);
                }
                // Pointer moved or other button pressed/released
                else
                {
                    var clickStatus = m_ClickStatus[pe.pointerId];
                    if (clickStatus.m_Target != null)
                    {
                        // stop the multi-click sequence on move
                        clickStatus.m_LastPointerDownTime = 0;
                    }
                }
            }
            else if (evt.eventTypeId == PointerCancelEvent.TypeId() ||
                     evt.eventTypeId == PointerStationaryEvent.TypeId()
#if UNITY_EDITOR
                     || evt.eventTypeId == DragUpdatedEvent.TypeId()
#endif
                     )
            {
                CancelClickTracking(evt);
            }
            else if (evt.eventTypeId == PointerUpEvent.TypeId() && pe.button == 0)
            {
                SendClickEvent(evt);
            }
        }
Ejemplo n.º 12
0
        internal void OnPointerUpEvent(PointerUpEvent evt)
        {
            if (!useDragEvents)
            {
                if (m_DragState == DragState.Dragging)
                {
                    m_Target.ReleasePointer(evt.pointerId);
                    OnDrop(evt.position);
                    ClearDragAndDropUI();
                    evt.StopPropagation();
                }
            }

            m_DragState = DragState.None;
        }
Ejemplo n.º 13
0
        void OnPointerUp(PointerUpEvent evt)
        {
            var selectedIndex = GetSelectedIndex();

            if (selectedIndex != -1)
            {
                var item = m_Items[selectedIndex];
                item.action?.Invoke();
                item.actionUserData?.Invoke(item.element.userData);

                Hide(true);
            }

            if (evt.pointerId != PointerId.mousePointerId)
            {
                m_MenuContainer.panel.PreventCompatibilityMouseEvents(evt.pointerId);
            }

            evt.StopPropagation();
        }
Ejemplo n.º 14
0
        void OnPointerUp(PointerUpEvent evt)
        {
            if (evt.pointerId == m_ScrollingPointerId)
            {
                evt.currentTarget.ReleasePointer(evt.pointerId);
                evt.StopPropagation();

                if (touchScrollBehavior == TouchScrollBehavior.Elastic || hasInertia)
                {
                    ComputeInitialSpringBackVelocity();

                    if (m_PostPointerUpAnimation == null)
                    {
                        m_PostPointerUpAnimation = schedule.Execute(PostPointerUpAnimation).Every(30);
                    }
                    else
                    {
                        m_PostPointerUpAnimation.Resume();
                    }
                }

                m_ScrollingPointerId = PointerId.invalidPointerId;
            }
        }
Ejemplo n.º 15
0
        // In order for tests to run without an EditorWindow but still be able to send
        // events, we sometimes need to force the event type. IMGUI::GetEventType() (native) will
        // return the event type as Ignore if the proper views haven't yet been
        // initialized. This (falsely) breaks tests that rely on the event type. So for tests, we
        // just ensure the event type is what we originally set it to when we sent it.
        internal static EventBase CreateEvent(Event systemEvent, EventType eventType)
        {
            switch (eventType)
            {
            case EventType.MouseMove:
                return(PointerMoveEvent.GetPooled(systemEvent));

            case EventType.MouseDrag:
                return(PointerMoveEvent.GetPooled(systemEvent));

            case EventType.MouseDown:
                // If some buttons are already down, we generate PointerMove/MouseDown events.
                // Otherwise we generate PointerDown/MouseDown events.
                // See W3C pointer events recommendation: https://www.w3.org/TR/pointerevents2
                // Note: sometimes systemEvent.button is already pressed (systemEvent is processed multiple times).
                if (PointerDeviceState.HasAdditionalPressedButtons(PointerId.mousePointerId, systemEvent.button))
                {
                    return(PointerMoveEvent.GetPooled(systemEvent));
                }
                else
                {
                    return(PointerDownEvent.GetPooled(systemEvent));
                }

            case EventType.MouseUp:
                // If more buttons are still down, we generate PointerMove/MouseUp events.
                // Otherwise we generate PointerUp/MouseUp events.
                // See W3C pointer events recommendation: https://www.w3.org/TR/pointerevents2
                if (PointerDeviceState.HasAdditionalPressedButtons(PointerId.mousePointerId, systemEvent.button))
                {
                    return(PointerMoveEvent.GetPooled(systemEvent));
                }
                else
                {
                    return(PointerUpEvent.GetPooled(systemEvent));
                }

            case EventType.ContextClick:
                return(ContextClickEvent.GetPooled(systemEvent));

            case EventType.MouseEnterWindow:
                return(MouseEnterWindowEvent.GetPooled(systemEvent));

            case EventType.MouseLeaveWindow:
                return(MouseLeaveWindowEvent.GetPooled(systemEvent));

            case EventType.ScrollWheel:
                return(WheelEvent.GetPooled(systemEvent));

            case EventType.KeyDown:
                return(KeyDownEvent.GetPooled(systemEvent));

            case EventType.KeyUp:
                return(KeyUpEvent.GetPooled(systemEvent));

#if UNITY_EDITOR
            case EventType.DragUpdated:
                return(DragUpdatedEvent.GetPooled(systemEvent));

            case EventType.DragPerform:
                return(DragPerformEvent.GetPooled(systemEvent));

            case EventType.DragExited:
                return(DragExitedEvent.GetPooled(systemEvent));
#endif
            case EventType.ValidateCommand:
                return(ValidateCommandEvent.GetPooled(systemEvent));

            case EventType.ExecuteCommand:
                return(ExecuteCommandEvent.GetPooled(systemEvent));

            default:    // Layout, Ignore, Used
                return(IMGUIEvent.GetPooled(systemEvent));
            }
        }
Ejemplo n.º 16
0
 void OnPointerUp(PointerUpEvent evt)
 {
     onPointerUp?.Invoke(evt);
 }
Ejemplo n.º 17
0
 private void UpdateValueOnPointerUp(PointerUpEvent evt)
 {
     ProcessUpEvent(evt, evt.pointerId);
 }
Ejemplo n.º 18
0
 internal static MouseUpEvent GetPooled(PointerUpEvent pointerEvent)
 {
     return(MouseUpEvent.MakeFromPointerEvent(pointerEvent));
 }
Ejemplo n.º 19
0
        private IEnumerator DoReplayEvents(IEnumerable <EventDebuggerEventRecord> eventBases, Action <int, int> refreshList)
        {
            var sortedEvents      = eventBases.OrderBy(e => e.timestamp).ToList();
            var sortedEventsCount = sortedEvents.Count;

            IEnumerator AwaitForNextEvent(int currentIndex)
            {
                if (currentIndex == sortedEvents.Count - 1)
                {
                    yield break;
                }

                var deltaTimestampMs = sortedEvents[currentIndex + 1].timestamp - sortedEvents[currentIndex].timestamp;

                var timeMs = 0.0f;

                while (timeMs < deltaTimestampMs)
                {
                    if (isPlaybackPaused)
                    {
                        yield return(null);
                    }
                    else
                    {
                        var time = Panel.TimeSinceStartupMs();
                        yield return(null);

                        var delta = Panel.TimeSinceStartupMs() - time;
                        timeMs += delta * playbackSpeed;
                    }
                }
            }

            for (var i = 0; i < sortedEventsCount; i++)
            {
                if (!isReplaying)
                {
                    break;
                }

                var eventBase = sortedEvents[i];
                var newEvent  = new Event
                {
                    button        = eventBase.button,
                    clickCount    = eventBase.clickCount,
                    modifiers     = eventBase.modifiers,
                    mousePosition = eventBase.mousePosition,
                };

                if (eventBase.eventTypeId == MouseMoveEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseMove;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseMove), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseDownEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseDown;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseUpEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseUp;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ContextClickEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.ContextClick;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ContextClick), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseEnterWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseEnterWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseEnterWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == MouseLeaveWindowEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseLeaveWindow;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseLeaveWindow), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == PointerMoveEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseMove;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseMove), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == PointerDownEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseDown;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == PointerUpEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type = EventType.MouseUp;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.MouseUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == WheelEvent.TypeId() && eventBase.hasUnderlyingPhysicalEvent)
                {
                    newEvent.type  = EventType.ScrollWheel;
                    newEvent.delta = eventBase.delta;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ScrollWheel), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyDownEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyDown;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyDown), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == KeyUpEvent.TypeId())
                {
                    newEvent.type      = EventType.KeyUp;
                    newEvent.character = eventBase.character;
                    newEvent.keyCode   = eventBase.keyCode;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.KeyUp), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == NavigationMoveEvent.TypeId())
                {
                    panel.dispatcher.Dispatch(NavigationMoveEvent.GetPooled(eventBase.navigationDirection, eventBase.deviceType, eventBase.modifiers), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == NavigationSubmitEvent.TypeId())
                {
                    panel.dispatcher.Dispatch(NavigationSubmitEvent.GetPooled(eventBase.deviceType, eventBase.modifiers), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == NavigationCancelEvent.TypeId())
                {
                    panel.dispatcher.Dispatch(NavigationCancelEvent.GetPooled(eventBase.deviceType, eventBase.modifiers), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragUpdatedEvent.TypeId())
                {
                    newEvent.type = EventType.DragUpdated;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragUpdated), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragPerformEvent.TypeId())
                {
                    newEvent.type = EventType.DragPerform;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragPerform), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == DragExitedEvent.TypeId())
                {
                    newEvent.type = EventType.DragExited;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.DragExited), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ValidateCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ValidateCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ValidateCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == ExecuteCommandEvent.TypeId())
                {
                    newEvent.type        = EventType.ExecuteCommand;
                    newEvent.commandName = eventBase.commandName;
                    panel.dispatcher.Dispatch(UIElementsUtility.CreateEvent(newEvent, EventType.ExecuteCommand), panel,
                                              DispatchMode.Default);
                }
                else if (eventBase.eventTypeId == IMGUIEvent.TypeId())
                {
                    Debug.Log("Skipped IMGUI event (" + eventBase.eventBaseName + "): " + eventBase);
                    var awaitSkipped = AwaitForNextEvent(i);
                    while (awaitSkipped.MoveNext())
                    {
                        yield return(null);
                    }
                    continue;
                }
                else
                {
                    Debug.Log("Skipped event (" + eventBase.eventBaseName + "): " + eventBase);
                    var awaitSkipped = AwaitForNextEvent(i);
                    while (awaitSkipped.MoveNext())
                    {
                        yield return(null);
                    }
                    continue;
                }

                refreshList?.Invoke(i, sortedEventsCount);

                Debug.Log($"Replayed event {eventBase.eventId.ToString()} ({eventBase.eventBaseName}): {newEvent}");
                var await = AwaitForNextEvent(i);
                while (await.MoveNext())
                {
                    yield return(null);
                }
            }

            isReplaying = false;
        }
 private void OnPointerUpEvent(PointerUpEvent evt)
 {
     this.OnPointerUp();
 }