public void ProcessEvent(PointerEvent inputEvent) { pointerEvents.Add(inputEvent); // Update position and delta from whatever device sends position updates LastPointerDevice = inputEvent.Pointer; if (inputEvent.Device is IMouseDevice) { mousePosition = inputEvent.Position; absoluteMousePosition = inputEvent.AbsolutePosition; // Add deltas together, so nothing gets lost if a down events gets sent after a move event with the actual delta MouseDelta += inputEvent.DeltaPosition; AbsoluteMouseDelta += inputEvent.AbsoluteDeltaPosition; } }
/// <summary> /// Updates a pointer event with position / type / id set and updates the storted pointer data /// </summary> /// <param name="evt"></param> public void UpdatePointerState(PointerEvent evt, bool updateDelta = true) { var data = GetPointerData(evt.PointerId); data.Id = evt.PointerId; if (updateDelta) { // Update delta based on change in position evt.DeltaPosition = data.Delta = evt.Position - data.Position; } else { data.Delta = evt.DeltaPosition; } // Update position data.Position = evt.Position; if (evt.EventType == PointerEventType.Pressed) { // Start pressed events with time 0 data.Clock.Restart(); data.IsDown = true; pressedPointers.Add(data); downPointers.Add(data); } else if (evt.EventType == PointerEventType.Released || evt.EventType == PointerEventType.Canceled) { releasedPointers.Add(data); downPointers.Remove(data); data.IsDown = false; } evt.IsDown = data.IsDown; evt.DeltaTime = data.Clock.Elapsed; // Reset pointer clock data.Clock.Restart(); }
private float GetDeltaY(PointerEvent pointerEvent) { return(pointerEvent.DeltaPosition.Y); }
private float GetPositionY(PointerEvent pointerEvent) { return(pointerEvent.Position.Y); }