A game framework written with osu! in mind.
at master 1.9 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Extensions.TypeExtensions; 5using osu.Framework.Input.States; 6using osuTK; 7 8namespace osu.Framework.Input.Events 9{ 10 /// <summary> 11 /// Represents a touch event. 12 /// </summary> 13 public class TouchEvent : UIEvent 14 { 15 /// <summary> 16 /// The touch of this event with the screen space position. 17 /// </summary> 18 public readonly Touch ScreenSpaceTouch; 19 20 /// <summary> 21 /// The touch of this event with local space position. 22 /// </summary> 23 public Touch Touch => new Touch(ScreenSpaceTouch.Source, ToLocalSpace(ScreenSpaceTouch.Position)); 24 25 /// <summary> 26 /// The touch position at the <see cref="TouchDownEvent"/> for this touch source in the screen space. 27 /// </summary> 28 public readonly Vector2 ScreenSpaceTouchDownPosition; 29 30 /// <summary> 31 /// The touch position at the <see cref="TouchDownEvent"/> for this touch source in local space. 32 /// </summary> 33 public Vector2 TouchDownPosition => ToLocalSpace(ScreenSpaceTouchDownPosition); 34 35 /// <summary> 36 /// Whether a touch is active. 37 /// </summary> 38 /// <param name="touch">The touch to check for.</param> 39 public bool IsActive(Touch touch) => CurrentState.Touch.IsActive(touch.Source); 40 41 public TouchEvent(InputState state, Touch touch, Vector2? screenSpaceTouchDownPosition = null) 42 : base(state) 43 { 44 ScreenSpaceTouch = touch; 45 ScreenSpaceTouchDownPosition = screenSpaceTouchDownPosition ?? ScreenSpaceTouch.Position; 46 } 47 48 public override string ToString() => $"{GetType().ReadableName()}({ScreenSpaceTouch.Source})"; 49 } 50}