// 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); } }
public static T GetPooled(Touch touch, EventModifiers modifiers = EventModifiers.None) { T e = GetPooled(); e.pointerId = touch.fingerId + PointerId.touchPointerIdBase; e.pointerType = PointerType.touch; bool otherTouchDown = false; for (var i = PointerId.touchPointerIdBase; i < PointerId.touchPointerIdBase + PointerId.touchPointerCount; i++) { if (i != e.pointerId && PointerDeviceState.GetPressedButtons(i) != 0) { otherTouchDown = true; break; } } e.isPrimary = !otherTouchDown; if (touch.phase == TouchPhase.Began) { PointerDeviceState.PressButton(e.pointerId, 0); e.button = 0; } else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { PointerDeviceState.ReleaseButton(e.pointerId, 0); e.button = 0; } else { e.button = -1; } e.pressedButtons = PointerDeviceState.GetPressedButtons(e.pointerId); e.position = touch.position; e.localPosition = touch.position; e.deltaPosition = touch.deltaPosition; e.deltaTime = touch.deltaTime; e.clickCount = touch.tapCount; e.pressure = Mathf.Abs(touch.maximumPossiblePressure) > Mathf.Epsilon ? touch.pressure / touch.maximumPossiblePressure : 1f; e.tangentialPressure = 0; e.altitudeAngle = touch.altitudeAngle; e.azimuthAngle = touch.azimuthAngle; e.twist = 0; e.radius = new Vector2(touch.radius, touch.radius); e.radiusVariance = new Vector2(touch.radiusVariance, touch.radiusVariance); e.modifiers = modifiers; ((IPointerEventInternal)e).triggeredByOS = true; return(e); }
public static T GetPooled(Touch touch, EventModifiers modifiers = EventModifiers.None) { T pooled = EventBase <T> .GetPooled(); pooled.pointerId = touch.fingerId + PointerId.touchPointerIdBase; pooled.pointerType = PointerType.touch; bool flag = false; for (int i = PointerId.touchPointerIdBase; i < PointerId.touchPointerIdBase + PointerId.touchPointerCount; i++) { bool flag2 = i != pooled.pointerId && PointerDeviceState.GetPressedButtons(i) != 0; if (flag2) { flag = true; break; } } pooled.isPrimary = !flag; bool flag3 = touch.phase == TouchPhase.Began; if (flag3) { PointerDeviceState.PressButton(pooled.pointerId, 0); pooled.button = 0; } else { bool flag4 = touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled; if (flag4) { PointerDeviceState.ReleaseButton(pooled.pointerId, 0); pooled.button = 0; } else { pooled.button = -1; } } pooled.pressedButtons = PointerDeviceState.GetPressedButtons(pooled.pointerId); pooled.position = touch.position; pooled.localPosition = touch.position; pooled.deltaPosition = touch.deltaPosition; pooled.deltaTime = touch.deltaTime; pooled.clickCount = touch.tapCount; pooled.pressure = ((Mathf.Abs(touch.maximumPossiblePressure) > Mathf.Epsilon) ? (touch.pressure / touch.maximumPossiblePressure) : 1f); pooled.tangentialPressure = 0f; pooled.altitudeAngle = touch.altitudeAngle; pooled.azimuthAngle = touch.azimuthAngle; pooled.twist = 0f; pooled.radius = new Vector2(touch.radius, touch.radius); pooled.radiusVariance = new Vector2(touch.radiusVariance, touch.radiusVariance); pooled.modifiers = modifiers; pooled.triggeredByOS = true; return(pooled); }
void OnFocus(FocusEvent _) { GUIUtility.imeCompositionMode = IMECompositionMode.On; m_DragToPosition = false; // If focus was given to this element from a mouse click or a Panel.Focus call, allow select on mouse up. if (PointerDeviceState.GetPressedButtons(PointerId.mousePointerId) != 0 || (textInputField as VisualElement)?.panel.contextType == ContextType.Editor && Event.current == null) { m_SelectAllOnMouseUp = true; } }
internal static T GetPooled(Vector2 position, int button, int clickCount, Vector2 delta, EventModifiers modifiers, bool fromOS) { T pooled = EventBase <T> .GetPooled(); pooled.modifiers = modifiers; pooled.mousePosition = position; pooled.localMousePosition = position; pooled.mouseDelta = delta; pooled.button = button; pooled.pressedButtons = PointerDeviceState.GetPressedButtons(PointerId.mousePointerId); pooled.clickCount = clickCount; pooled.triggeredByOS = fromOS; pooled.recomputeTopElementUnderMouse = true; return(pooled); }
public static T GetPooled(Event systemEvent) { T pooled = EventBase <T> .GetPooled(); pooled.imguiEvent = systemEvent; bool flag = systemEvent != null; if (flag) { pooled.modifiers = systemEvent.modifiers; pooled.mousePosition = systemEvent.mousePosition; pooled.localMousePosition = systemEvent.mousePosition; pooled.mouseDelta = systemEvent.delta; pooled.button = systemEvent.button; pooled.pressedButtons = PointerDeviceState.GetPressedButtons(PointerId.mousePointerId); pooled.clickCount = systemEvent.clickCount; pooled.triggeredByOS = true; pooled.recomputeTopElementUnderMouse = true; } return(pooled); }
public static T GetPooled(Event systemEvent) { T e = GetPooled(); Debug.Assert(IsMouse(systemEvent) || systemEvent.rawType == EventType.DragUpdated, "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); }