Harrison af7c1b37f9 Improved window and input handling.
Window now has some events.

Keyboard and mouse implemented.
2020-05-27 20:24:02 -05:00

41 lines
1.7 KiB
C#

namespace SlatedGameToolkit.Framework.Input.Devices
{
public delegate void MouseUpdate(bool leftDown, bool rightDown, bool middle, int x, int y, int scrollX, int scrollY);
public static class Mouse
{
public static event MouseUpdate mouseUpdateEvent;
public static bool LeftButtonPressed { get; private set; }
public static bool RightButtonPressed { get; private set; }
public static bool MiddleButtonPressed { get; private set; }
public static int ScrollChangeX { get; private set; }
public static int ScrollChangeY { get; private set; }
public static int X { get; private set; }
public static int Y{ get; private set; }
internal static void OnMouseMoved(int x, int y) {
X = x;
Y = y;
}
internal static void OnLeftChange(bool down) {
LeftButtonPressed = down;
mouseUpdateEvent?.Invoke(down, RightButtonPressed, MiddleButtonPressed, X, Y, ScrollChangeX, ScrollChangeY);
}
internal static void OnRightChange(bool down) {
RightButtonPressed = down;
mouseUpdateEvent?.Invoke(LeftButtonPressed, down, MiddleButtonPressed, X, Y, ScrollChangeX, ScrollChangeY);
}
internal static void OnMiddleChange(bool down) {
RightButtonPressed = down;
mouseUpdateEvent?.Invoke(LeftButtonPressed, RightButtonPressed, down, X, Y, ScrollChangeX, ScrollChangeY);
}
internal static void OnScroll(int scrollX, int scrollY) {
ScrollChangeX = scrollX;
ScrollChangeY = scrollY;
mouseUpdateEvent?.Invoke(LeftButtonPressed, RightButtonPressed, MiddleButtonPressed, X, Y, scrollX, scrollY);
}
}
}