// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; namespace osu.Framework.Input.StateChanges { /// /// Denotes a change of a touch input. /// public class TouchInput : IInput { /// /// The list of touch structures each providing the source and position to move to. /// public readonly IEnumerable Touches; /// /// Whether to activate the provided . /// public readonly bool Activate; /// /// Constructs a new . /// /// The . /// Whether to activate the provided , must be true if changing position only. public TouchInput(Touch touch, bool activate) : this(touch.Yield(), activate) { } /// /// Constructs a new . /// /// The list of es. /// Whether to activate the provided , must be true if changing position only. public TouchInput(IEnumerable touches, bool activate) { Touches = touches; Activate = activate; } public void Apply(InputState state, IInputStateChangeHandler handler) { var touches = state.Touch; foreach (var touch in Touches) { var lastPosition = touches.GetTouchPosition(touch.Source); touches.TouchPositions[(int)touch.Source] = touch.Position; bool activityChanged = touches.ActiveSources.SetPressed(touch.Source, Activate); var positionChanged = lastPosition != null && touch.Position != lastPosition; if (activityChanged || positionChanged) { handler.HandleInputStateChange(new TouchStateChangeEvent(state, this, touch, !activityChanged ? (bool?)null : Activate, !positionChanged ? null : lastPosition )); } } } } }