-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseState.cs
38 lines (26 loc) · 920 Bytes
/
MouseState.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
#nullable disable
using System.Numerics;
using Silk.NET.Input;
internal class MouseState
{
private readonly HashSet<MouseButton> buttonsDown = new();
public Vector2? Position { get; private set; } = null;
private List<ScrollDirection> scrollEvents = new();
public void ResetMouse() => Position = null;
public void MouseMove(Vector2 position) => Position = position;
public void MouseScroll(ScrollDirection scroll) => scrollEvents.Add(scroll);
public IList<ScrollDirection> HandleScrollEvents()
{
var events = scrollEvents;
scrollEvents = new();
return events;
}
public void ButtonDown(MouseButton button) => buttonsDown.Add(button);
public void ButtonUp(MouseButton button) => buttonsDown.Remove(button);
public bool IsButtonDown(MouseButton button) => buttonsDown.Contains(button);
}
internal enum ScrollDirection
{
Up,
Down
}