Beispiel #1
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));
            }
        }
        public static T GetPooled(Event systemEvent)
        {
            T e = GetPooled();

            if (!(IsMouse(systemEvent) || systemEvent.rawType == EventType.DragUpdated))
            {
                Debug.Assert(false, "Unexpected event type: " + systemEvent.rawType + " (" + systemEvent.type + ")");
            }

            switch (systemEvent.pointerType)
            {
            default:
                e.pointerType = PointerType.mouse;
                e.pointerId   = PointerId.mousePointerId;
                break;

            case UnityEngine.PointerType.Touch:
                e.pointerType = PointerType.touch;
                e.pointerId   = PointerId.touchPointerIdBase;
                break;

            case UnityEngine.PointerType.Pen:
                e.pointerType = PointerType.pen;
                e.pointerId   = PointerId.penPointerIdBase;
                break;
            }

            e.isPrimary = true;

            e.altitudeAngle  = 0;
            e.azimuthAngle   = 0;
            e.twist          = 0;
            e.radius         = Vector2.zero;
            e.radiusVariance = Vector2.zero;

            e.imguiEvent = systemEvent;

            if (systemEvent.rawType == EventType.MouseDown)
            {
                PointerDeviceState.PressButton(PointerId.mousePointerId, systemEvent.button);
                e.button = systemEvent.button;
            }
            else if (systemEvent.rawType == EventType.MouseUp)
            {
                PointerDeviceState.ReleaseButton(PointerId.mousePointerId, systemEvent.button);
                e.button = systemEvent.button;
            }
            else if (systemEvent.rawType == EventType.MouseMove)
            {
                e.button = -1;
            }

            e.pressedButtons = PointerDeviceState.GetPressedButtons(e.pointerId);
            e.position       = systemEvent.mousePosition;
            e.localPosition  = systemEvent.mousePosition;
            e.deltaPosition  = systemEvent.delta;
            e.clickCount     = systemEvent.clickCount;
            e.modifiers      = systemEvent.modifiers;

            switch (systemEvent.pointerType)
            {
            default:
                e.pressure = e.pressedButtons == 0 ? 0f : 0.5f;
                break;

            case UnityEngine.PointerType.Touch:
            case UnityEngine.PointerType.Pen:
                e.pressure = systemEvent.pressure;
                break;
            }

            e.tangentialPressure = 0;

            ((IPointerEventInternal)e).triggeredByOS = true;

            return(e);
        }
        public static T GetPooled(Event systemEvent)
        {
            T pooled = EventBase <T> .GetPooled();

            bool flag = !PointerEventBase <T> .IsMouse(systemEvent) && systemEvent.rawType != EventType.DragUpdated;

            if (flag)
            {
                Debug.Assert(false, string.Concat(new string[]
                {
                    "Unexpected event type: ",
                    systemEvent.rawType.ToString(),
                    " (",
                    systemEvent.type.ToString(),
                    ")"
                }));
            }
            UnityEngine.PointerType pointerType  = systemEvent.pointerType;
            UnityEngine.PointerType pointerType2 = pointerType;
            if (pointerType2 != UnityEngine.PointerType.Touch)
            {
                if (pointerType2 != UnityEngine.PointerType.Pen)
                {
                    pooled.pointerType = PointerType.mouse;
                    pooled.pointerId   = PointerId.mousePointerId;
                }
                else
                {
                    pooled.pointerType = PointerType.pen;
                    pooled.pointerId   = PointerId.penPointerIdBase;
                }
            }
            else
            {
                pooled.pointerType = PointerType.touch;
                pooled.pointerId   = PointerId.touchPointerIdBase;
            }
            pooled.isPrimary      = true;
            pooled.altitudeAngle  = 0f;
            pooled.azimuthAngle   = 0f;
            pooled.twist          = 0f;
            pooled.radius         = Vector2.zero;
            pooled.radiusVariance = Vector2.zero;
            pooled.imguiEvent     = systemEvent;
            bool flag2 = systemEvent.rawType == EventType.MouseDown;

            if (flag2)
            {
                PointerDeviceState.PressButton(PointerId.mousePointerId, systemEvent.button);
                pooled.button = systemEvent.button;
            }
            else
            {
                bool flag3 = systemEvent.rawType == EventType.MouseUp;
                if (flag3)
                {
                    PointerDeviceState.ReleaseButton(PointerId.mousePointerId, systemEvent.button);
                    pooled.button = systemEvent.button;
                }
                else
                {
                    bool flag4 = systemEvent.rawType == EventType.MouseMove;
                    if (flag4)
                    {
                        pooled.button = -1;
                    }
                }
            }
            pooled.pressedButtons = PointerDeviceState.GetPressedButtons(pooled.pointerId);
            pooled.position       = systemEvent.mousePosition;
            pooled.localPosition  = systemEvent.mousePosition;
            pooled.deltaPosition  = systemEvent.delta;
            pooled.clickCount     = systemEvent.clickCount;
            pooled.modifiers      = systemEvent.modifiers;
            UnityEngine.PointerType pointerType3 = systemEvent.pointerType;
            UnityEngine.PointerType pointerType4 = pointerType3;
            if (pointerType4 - UnityEngine.PointerType.Touch > 1)
            {
                pooled.pressure = ((pooled.pressedButtons == 0) ? 0f : 0.5f);
            }
            else
            {
                pooled.pressure = systemEvent.pressure;
            }
            pooled.tangentialPressure = 0f;
            pooled.triggeredByOS      = true;
            return(pooled);
        }