inpututil: Add APIs for the standard gamepad layout

This change adds these APIs to inpututil:

  * IsStandardGamepadButtonJustPressed
  * IsStandardGamepadButtonJustReleased
  * StandardGamepadButtonPressDuration

Closes #1557
This commit is contained in:
Hajime Hoshi
2021-07-20 02:25:52 +09:00
parent aa694be6f6
commit 51f83b1527
3 changed files with 85 additions and 0 deletions

View File

@@ -67,6 +67,7 @@ func (g *Game) Update() error {
v := ebiten.GamepadAxisValue(id, a)
g.axes[id] = append(g.axes[id], fmt.Sprintf("%d:%+0.2f", a, v))
}
maxButton := ebiten.GamepadButton(ebiten.GamepadButtonNum(id))
for b := ebiten.GamepadButton(id); b < maxButton; b++ {
if ebiten.IsGamepadButtonPressed(id, b) {
@@ -81,6 +82,18 @@ func (g *Game) Update() error {
log.Printf("button released: id: %d, button: %d", id, b)
}
}
if ebiten.HasGamepadStandardLayoutMapping(id) {
for b := ebiten.StandardGamepadButton(0); b <= ebiten.StandardGamepadButtonMax; b++ {
// Log button events.
if inpututil.IsStandardGamepadButtonJustPressed(id, b) {
log.Printf("standard button pressed: id: %d, button: %d", id, b)
}
if inpututil.IsStandardGamepadButtonJustReleased(id, b) {
log.Printf("standard button released: id: %d, button: %d", id, b)
}
}
}
}
return nil
}