A game framework written with osu! in mind.
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.Input.States;
5using osuTK;
6using osuTK.Input;
7
8namespace osu.Framework.Input.Events
9{
10 /// <summary>
11 /// An event representing a mouse drag.
12 /// Triggered when mouse is moved while dragging.
13 /// </summary>
14 public class DragEvent : MouseButtonEvent
15 {
16 /// <summary>
17 /// The last mouse position before this mouse move in the screen space.
18 /// </summary>
19 public readonly Vector2 ScreenSpaceLastMousePosition;
20
21 /// <summary>
22 /// The last mouse position before this mouse move in local space.
23 /// </summary>
24 public Vector2 LastMousePosition => ToLocalSpace(ScreenSpaceLastMousePosition);
25
26 /// <summary>
27 /// The difference of mouse position from last position to current position in local space.
28 /// </summary>
29 public Vector2 Delta => MousePosition - LastMousePosition;
30
31 public DragEvent(InputState state, MouseButton button, Vector2? screenSpaceMousePosition = null, Vector2? screenSpaceLastMousePosition = null)
32 : base(state, button, screenSpaceMousePosition)
33 {
34 ScreenSpaceLastMousePosition = screenSpaceLastMousePosition ?? state.Mouse.Position;
35 }
36 }
37}