forked from ppy/osu-framework
/
OpenTKMouseState.cs
40 lines (33 loc) · 1.48 KB
/
OpenTKMouseState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
using OpenTK;
using OpenTK.Input;
using MouseState = osu.Framework.Input.MouseState;
namespace osu.Framework.Desktop.Input.Handlers.Mouse
{
internal abstract class OpenTKMouseState : MouseState
{
public readonly bool WasActive;
public override int WheelDelta => WasActive ? base.WheelDelta : 0;
protected OpenTKMouseState(OpenTK.Input.MouseState tkState, bool active, Vector2? mappedPosition)
{
WasActive = active;
// While not focused, let's silently ignore everything but position.
if (active && tkState.IsAnyButtonDown)
{
addIfPressed(tkState.LeftButton, MouseButton.Left);
addIfPressed(tkState.MiddleButton, MouseButton.Middle);
addIfPressed(tkState.RightButton, MouseButton.Right);
addIfPressed(tkState.XButton1, MouseButton.Button1);
addIfPressed(tkState.XButton2, MouseButton.Button2);
}
Wheel = tkState.Wheel;
Position = new Vector2(mappedPosition?.X ?? tkState.X, mappedPosition?.Y ?? tkState.Y);
}
private void addIfPressed(ButtonState tkState, MouseButton button)
{
if (tkState == ButtonState.Pressed)
SetPressed(button, true);
}
}
}