ebiten: add additional MouseButtons (#2467)

Closes #2445
This commit is contained in:
Kacper Drobny 2022-11-22 20:28:34 +01:00 committed by GitHub
parent 5356b44286
commit 6e12fd13e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 8 deletions

View File

@ -101,11 +101,7 @@ func (i *inputState) update() {
} }
// Mouse // Mouse
for _, b := range []ebiten.MouseButton{ for b := ebiten.MouseButton(0); b <= ebiten.MouseButtonMax; b++ {
ebiten.MouseButtonLeft,
ebiten.MouseButtonRight,
ebiten.MouseButtonMiddle,
} {
i.prevMouseButtonDurations[b] = i.mouseButtonDurations[b] i.prevMouseButtonDurations[b] = i.mouseButtonDurations[b]
if ebiten.IsMouseButtonPressed(b) { if ebiten.IsMouseButtonPressed(b) {
i.mouseButtonDurations[b]++ i.mouseButtonDurations[b]++

View File

@ -54,6 +54,8 @@ const (
MouseButtonLeft = MouseButton(0) MouseButtonLeft = MouseButton(0)
MouseButtonRight = MouseButton(1) MouseButtonRight = MouseButton(1)
MouseButtonMiddle = MouseButton(2) MouseButtonMiddle = MouseButton(2)
MouseButton3 = MouseButton(3)
MouseButton4 = MouseButton(4)
) )
const ( const (

View File

@ -152,6 +152,8 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
glfw.MouseButtonLeft: MouseButtonLeft, glfw.MouseButtonLeft: MouseButtonLeft,
glfw.MouseButtonRight: MouseButtonRight, glfw.MouseButtonRight: MouseButtonRight,
glfw.MouseButtonMiddle: MouseButtonMiddle, glfw.MouseButtonMiddle: MouseButtonMiddle,
glfw.MouseButton3: MouseButton3,
glfw.MouseButton4: MouseButton4,
} }
// update must be called from the main thread. // update must be called from the main thread.

View File

@ -129,6 +129,8 @@ var codeToMouseButton = map[int]MouseButton{
0: MouseButtonLeft, 0: MouseButtonLeft,
1: MouseButtonMiddle, 1: MouseButtonMiddle,
2: MouseButtonRight, 2: MouseButtonRight,
3: MouseButton3,
4: MouseButton4,
} }
func (i *Input) IsMouseButtonPressed(button MouseButton) bool { func (i *Input) IsMouseButtonPressed(button MouseButton) bool {

View File

@ -24,9 +24,15 @@ import (
type MouseButton int type MouseButton int
const ( const (
MouseButtonLeft MouseButton = iota MouseButton0 MouseButton = iota
MouseButtonRight MouseButton1
MouseButtonMiddle MouseButton2
MouseButton3
MouseButton4
MouseButtonLeft = MouseButton0
MouseButtonRight = MouseButton1
MouseButtonMiddle = MouseButton2
) )
type TouchID int type TouchID int

View File

@ -26,4 +26,10 @@ const (
MouseButtonLeft MouseButton = ui.MouseButtonLeft MouseButtonLeft MouseButton = ui.MouseButtonLeft
MouseButtonRight MouseButton = ui.MouseButtonRight MouseButtonRight MouseButton = ui.MouseButtonRight
MouseButtonMiddle MouseButton = ui.MouseButtonMiddle MouseButtonMiddle MouseButton = ui.MouseButtonMiddle
MouseButton0 MouseButton = ui.MouseButton0
MouseButton1 MouseButton = ui.MouseButton1
MouseButton2 MouseButton = ui.MouseButton2
MouseButton3 MouseButton = ui.MouseButton3
MouseButton4 MouseButton = ui.MouseButton4
MouseButtonMax MouseButton = MouseButton4
) )