add support for mouse X1 and X2 buttons (#36)

Reviewed-on: MoonsideGames/MoonWorks#36
moar-validation
cosmonaut 2022-11-18 18:33:15 +00:00
parent fa992652b1
commit faf81bceed
2 changed files with 13 additions and 15 deletions

View File

@ -8,6 +8,8 @@ namespace MoonWorks.Input
public MouseButton LeftButton { get; } public MouseButton LeftButton { get; }
public MouseButton MiddleButton { get; } public MouseButton MiddleButton { get; }
public MouseButton RightButton { get; } public MouseButton RightButton { get; }
public MouseButton X1Button { get; }
public MouseButton X2Button { get; }
public int X { get; private set; } public int X { get; private set; }
public int Y { get; private set; } public int Y { get; private set; }
@ -41,27 +43,23 @@ namespace MoonWorks.Input
private readonly Dictionary<MouseButtonCode, MouseButton> CodeToButton; private readonly Dictionary<MouseButtonCode, MouseButton> CodeToButton;
private IEnumerable<MouseButton> Buttons private IEnumerable<MouseButton> Buttons => CodeToButton.Values;
{
get
{
yield return LeftButton;
yield return MiddleButton;
yield return RightButton;
}
}
public Mouse() public Mouse()
{ {
LeftButton = new MouseButton(this, MouseButtonCode.Left, SDL.SDL_BUTTON_LMASK); LeftButton = new MouseButton(this, MouseButtonCode.Left, SDL.SDL_BUTTON_LMASK);
MiddleButton = new MouseButton(this, MouseButtonCode.Middle, SDL.SDL_BUTTON_MMASK); MiddleButton = new MouseButton(this, MouseButtonCode.Middle, SDL.SDL_BUTTON_MMASK);
RightButton = new MouseButton(this, MouseButtonCode.Right, SDL.SDL_BUTTON_RMASK); RightButton = new MouseButton(this, MouseButtonCode.Right, SDL.SDL_BUTTON_RMASK);
X1Button = new MouseButton(this, MouseButtonCode.X1, SDL.SDL_BUTTON_X1MASK);
X2Button = new MouseButton(this, MouseButtonCode.X2, SDL.SDL_BUTTON_X2MASK);
CodeToButton = new Dictionary<MouseButtonCode, MouseButton> CodeToButton = new Dictionary<MouseButtonCode, MouseButton>
{ {
{ MouseButtonCode.Left, LeftButton }, { MouseButtonCode.Left, LeftButton },
{ MouseButtonCode.Right, RightButton }, { MouseButtonCode.Right, RightButton },
{ MouseButtonCode.Middle, MiddleButton } { MouseButtonCode.Middle, MiddleButton },
{ MouseButtonCode.X1, X1Button },
{ MouseButtonCode.X2, X2Button }
}; };
} }
@ -80,12 +78,10 @@ namespace MoonWorks.Input
Wheel = WheelRaw - previousWheelRaw; Wheel = WheelRaw - previousWheelRaw;
previousWheelRaw = WheelRaw; previousWheelRaw = WheelRaw;
LeftButton.Update();
MiddleButton.Update();
RightButton.Update();
foreach (var button in Buttons) foreach (var button in Buttons)
{ {
button.Update();
if (button.IsPressed) if (button.IsPressed)
{ {
AnyPressed = true; AnyPressed = true;

View File

@ -4,6 +4,8 @@ namespace MoonWorks.Input
{ {
Left, Left,
Right, Right,
Middle Middle,
X1,
X2
} }
} }