// 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);
     }
 }
Ejemplo n.º 2
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(MouseMoveEvent.GetPooled(systemEvent));

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

            case EventType.MouseDown:
                return(MouseDownEvent.GetPooled(systemEvent));

            case EventType.MouseUp:
                return(MouseUpEvent.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));
            }
        }
Ejemplo n.º 3
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));
            }
        }