mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
added generic isdown, ispressed and isup methods to InputHandler
This commit is contained in:
parent
90d292cd37
commit
35fccfcd83
1 changed files with 30 additions and 0 deletions
|
@ -130,6 +130,36 @@ namespace MLEM.Input {
|
|||
return this.WasGamepadButtonUp(index, button) && this.IsGamepadButtonDown(index, button);
|
||||
}
|
||||
|
||||
public bool IsDown(object control, int index = 0) {
|
||||
if (control is Keys key)
|
||||
return this.IsKeyDown(key);
|
||||
if (control is Buttons button)
|
||||
return this.IsGamepadButtonDown(index, button);
|
||||
if (control is MouseButton mouse)
|
||||
return this.IsMouseButtonDown(mouse);
|
||||
throw new ArgumentException(nameof(control));
|
||||
}
|
||||
|
||||
public bool IsUp(object control, int index = 0) {
|
||||
if (control is Keys key)
|
||||
return this.IsKeyUp(key);
|
||||
if (control is Buttons button)
|
||||
return this.IsGamepadButtonUp(index, button);
|
||||
if (control is MouseButton mouse)
|
||||
return this.IsMouseButtonUp(mouse);
|
||||
throw new ArgumentException(nameof(control));
|
||||
}
|
||||
|
||||
public bool IsPressed(object control, int index = 0) {
|
||||
if (control is Keys key)
|
||||
return this.IsKeyPressed(key);
|
||||
if (control is Buttons button)
|
||||
return this.IsGamepadButtonPressed(index, button);
|
||||
if (control is MouseButton mouse)
|
||||
return this.IsMouseButtonPressed(mouse);
|
||||
throw new ArgumentException(nameof(control));
|
||||
}
|
||||
|
||||
private static ButtonState GetState(MouseState state, MouseButton button) {
|
||||
switch (button) {
|
||||
case MouseButton.Left:
|
||||
|
|
Loading…
Reference in a new issue