protected void OnPointerMove(PointerMoveEvent evt) { if (evt.pointerId != PointerId.mousePointerId && active) { ProcessMoveEvent(evt, evt.localPosition); } }
void OnPointerMove(PointerMoveEvent evt) { m_MousePosition = m_ScrollView.WorldToLocal(evt.position); if (!m_ScrollView.ContainsPoint(m_MousePosition)) { return; } var ve = evt.target as VisualElement; if (ve == null) { return; } if ((ve.pseudoStates & PseudoStates.Hover) != PseudoStates.Hover) { var selectedIndex = GetSelectedIndex(); if (selectedIndex >= 0) { m_Items[selectedIndex].element.pseudoStates &= ~PseudoStates.Hover; } ve.pseudoStates |= PseudoStates.Hover; } }
protected void OnPointerMove(PointerMoveEvent evt) { if (IsNotMouseEvent(evt) && active) { ProcessMoveEvent(evt, evt.localPosition); } }
protected override void ProcessMoveEvent(EventBase evt, Vector2 localPosition) { // Let base class Clickable handle the mouse event first // (although nothing much happens in the base class on pointer drag) base.ProcessMoveEvent(evt, localPosition); // Take control if we can if (dragDirection == DragDirection.None) { dragDirection = DragDirection.Free; } // If and when we have control, set value from drag element if (dragDirection == DragDirection.Free) { if (evt.eventTypeId == PointerMoveEvent.TypeId()) { var pointerMoveEvent = (PointerMoveEvent)evt; if (pointerMoveEvent.pointerId != PointerId.mousePointerId) { pointerMoveEvent.isHandledByDraggable = true; } } dragging?.Invoke(); } }
// 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 OnPointerMove(PointerMoveEvent evt) { bool flag = evt.pointerId != PointerId.mousePointerId && base.active; if (flag) { this.ProcessMoveEvent(evt, evt.localPosition); } }
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()); }
void OnPointerMoveEvent(PointerMoveEvent evt) { // Support cases where PointerMove corresponds to a MouseDown or MouseUp event with multiple buttons. if (evt.button == (int)MouseButton.LeftMouse) { if ((evt.pressedButtons & (1 << (int)MouseButton.LeftMouse)) != 0) { ProcessPointerDown(evt); } } }
void OnPointerMove(PointerMoveEvent evt) { m_MousePosition = m_ScrollView.WorldToLocal(evt.position); UpdateSelection(evt.target as VisualElement); if (evt.pointerId != PointerId.mousePointerId) { m_MenuContainer.panel.PreventCompatibilityMouseEvents(evt.pointerId); } evt.StopPropagation(); }
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); } }
private void OnPointerMoveEvent(PointerMoveEvent evt) { if (useDragEvents) { if (m_DragState != DragState.CanStartDrag) { return; } } else { if (m_DragState == DragState.Dragging) { UpdateDrag(evt.position); return; } if (m_DragState != DragState.CanStartDrag) { return; } } if (Mathf.Abs(m_Start.x - evt.position.x) > k_DistanceToActivation || Mathf.Abs(m_Start.y - evt.position.y) > k_DistanceToActivation) { var startDragArgs = StartDrag(m_Start); if (useDragEvents) { // Drag can only be started by mouse events or else it will throw an error, so we leave early. if (Event.current.type != EventType.MouseDown && Event.current.type != EventType.MouseDrag) { return; } DragAndDropUtility.dragAndDrop.StartDrag(startDragArgs); } else // Force default drag and drop client for runtime panels. { m_Target.CapturePointer(evt.pointerId); evt.StopPropagation(); dragAndDropClient = new DefaultDragAndDropClient(); dragAndDropClient.StartDrag(startDragArgs); } m_DragState = DragState.Dragging; } }
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); } }
private void OnPointerMoveEvent(PointerMoveEvent evt) { bool flag = !this.m_CanStartDrag; if (!flag) { bool flag2 = Mathf.Abs(this.m_Start.x - evt.position.x) > 5f || Mathf.Abs(this.m_Start.y - evt.position.y) > 5f; if (flag2) { StartDragArgs args = this.StartDrag(evt.position); DragAndDropUtility.dragAndDrop.StartDrag(args); this.m_CanStartDrag = false; } } }
private void OnPointerMove(PointerMoveEvent evt) { bool flag = evt.pointerId == this.m_ScrollingPointerId; if (flag) { bool flag2 = this.touchScrollBehavior == ScrollView.TouchScrollBehavior.Clamped; Vector2 vector; if (flag2) { vector = this.m_StartPosition - (new Vector2(evt.position.x, evt.position.y) - this.m_PointerStartPosition); vector = Vector2.Max(vector, this.m_LowBounds); vector = Vector2.Min(vector, this.m_HighBounds); } else { bool flag3 = this.touchScrollBehavior == ScrollView.TouchScrollBehavior.Elastic; if (flag3) { Vector2 vector2 = new Vector2(evt.position.x, evt.position.y) - this.m_PointerStartPosition; vector.x = ScrollView.ComputeElasticOffset(vector2.x, this.m_StartPosition.x, this.m_LowBounds.x, this.m_LowBounds.x - this.contentViewport.resolvedStyle.width, this.m_HighBounds.x, this.m_HighBounds.x + this.contentViewport.resolvedStyle.width); vector.y = ScrollView.ComputeElasticOffset(vector2.y, this.m_StartPosition.y, this.m_LowBounds.y, this.m_LowBounds.y - this.contentViewport.resolvedStyle.height, this.m_HighBounds.y, this.m_HighBounds.y + this.contentViewport.resolvedStyle.height); } else { vector = this.m_StartPosition - (new Vector2(evt.position.x, evt.position.y) - this.m_PointerStartPosition); } } bool hasInertia = this.hasInertia; if (hasInertia) { float unscaledDeltaTime = Time.unscaledDeltaTime; Vector2 b = (vector - this.scrollOffset) / unscaledDeltaTime; this.m_Velocity = Vector2.Lerp(this.m_Velocity, b, unscaledDeltaTime * 10f); } this.scrollOffset = vector; evt.currentTarget.CapturePointer(evt.pointerId); evt.StopPropagation(); } }
void OnPointerMove(PointerMoveEvent evt) { if (evt.pointerId == m_ScrollingPointerId) { Vector2 newScrollOffset; if (touchScrollBehavior == TouchScrollBehavior.Clamped) { newScrollOffset = m_StartPosition - (new Vector2(evt.position.x, evt.position.y) - m_PointerStartPosition); newScrollOffset = Vector2.Max(newScrollOffset, m_LowBounds); newScrollOffset = Vector2.Min(newScrollOffset, m_HighBounds); } else if (touchScrollBehavior == TouchScrollBehavior.Elastic) { Vector2 deltaPointer = new Vector2(evt.position.x, evt.position.y) - m_PointerStartPosition; newScrollOffset.x = ComputeElasticOffset(deltaPointer.x, m_StartPosition.x, m_LowBounds.x, m_LowBounds.x - contentViewport.resolvedStyle.width, m_HighBounds.x, m_HighBounds.x + contentViewport.resolvedStyle.width); newScrollOffset.y = ComputeElasticOffset(deltaPointer.y, m_StartPosition.y, m_LowBounds.y, m_LowBounds.y - contentViewport.resolvedStyle.height, m_HighBounds.y, m_HighBounds.y + contentViewport.resolvedStyle.height); } else { newScrollOffset = m_StartPosition - (new Vector2(evt.position.x, evt.position.y) - m_PointerStartPosition); } if (hasInertia) { float deltaTime = Time.unscaledDeltaTime; var newVelocity = (newScrollOffset - scrollOffset) / deltaTime; m_Velocity = Vector2.Lerp(m_Velocity, newVelocity, deltaTime * 10); } scrollOffset = newScrollOffset; evt.currentTarget.CapturePointer(evt.pointerId); evt.StopPropagation(); } }
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; }
internal static MouseMoveEvent GetPooled(PointerMoveEvent pointerEvent) { return(MouseEventBase <MouseMoveEvent> .GetPooled(pointerEvent)); }
// 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)); } }
private void UpdateValueOnPointerMove(PointerMoveEvent evt) { ProcessMoveEvent(evt.shiftKey, evt.altKey, evt.deltaPosition); }
internal static MouseUpEvent GetPooled(PointerMoveEvent pointerEvent) { return(MouseUpEvent.MakeFromPointerEvent(pointerEvent)); }
internal static DragUpdatedEvent GetPooled(PointerMoveEvent pointerEvent) { return(MouseEventBase <DragUpdatedEvent> .GetPooled(pointerEvent)); }