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.StateChanges.Events;
5using osu.Framework.Input.States;
6using osuTK;
7
8namespace osu.Framework.Input.StateChanges
9{
10 /// <summary>
11 /// Denotes an absolute change of mouse position.
12 /// Pointing devices such as tablets provide absolute input.
13 /// </summary>
14 /// <remarks>
15 /// This is the first input received from any pointing device.
16 /// </remarks>
17 public class MousePositionAbsoluteInput : IInput
18 {
19 /// <summary>
20 /// The position which will be assigned to the current position.
21 /// </summary>
22 public Vector2 Position;
23
24 public void Apply(InputState state, IInputStateChangeHandler handler)
25 {
26 var mouse = state.Mouse;
27
28 if (!mouse.IsPositionValid || mouse.Position != Position)
29 {
30 var lastPosition = mouse.IsPositionValid ? mouse.Position : Position;
31 mouse.IsPositionValid = true;
32 mouse.LastSource = this;
33 mouse.Position = Position;
34 handler.HandleInputStateChange(new MousePositionChangeEvent(state, this, lastPosition));
35 }
36 }
37 }
38}