From f361084d6fcbff326e0b7d8f6752479c40c9628b Mon Sep 17 00:00:00 2001 From: Ben Perry Date: Fri, 13 Oct 2023 19:10:36 -0500 Subject: [PATCH] Mouse and Key buttons must share a common NumButtons iota, otherwise the count is off --- backends/opengl/input.go | 6 +++--- backends/opengl/window.go | 8 ++++---- input.go | 20 +++++++------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/backends/opengl/input.go b/backends/opengl/input.go index ba5e463..250a250 100644 --- a/backends/opengl/input.go +++ b/backends/opengl/input.go @@ -298,9 +298,9 @@ func (w *Window) doUpdateInput() { w.releaseEvents = w.tempReleaseEvents // Clear last frame's temporary status - w.tempPressEvents = [pixel.NumKeys]bool{} - w.tempReleaseEvents = [pixel.NumKeys]bool{} - w.tempInp.repeat = [pixel.NumKeys]bool{} + w.tempPressEvents = [pixel.NumButtons]bool{} + w.tempReleaseEvents = [pixel.NumButtons]bool{} + w.tempInp.repeat = [pixel.NumButtons]bool{} w.tempInp.scroll = pixel.ZV w.tempInp.typed = "" diff --git a/backends/opengl/window.go b/backends/opengl/window.go index 67ba1fd..4739e8b 100644 --- a/backends/opengl/window.go +++ b/backends/opengl/window.go @@ -99,14 +99,14 @@ type Window struct { prevInp, currInp, tempInp struct { mouse pixel.Vec - buttons [pixel.NumKeys]bool - repeat [pixel.NumKeys]bool + buttons [pixel.NumButtons]bool + repeat [pixel.NumButtons]bool scroll pixel.Vec typed string } - pressEvents, tempPressEvents [pixel.NumKeys]bool - releaseEvents, tempReleaseEvents [pixel.NumKeys]bool + pressEvents, tempPressEvents [pixel.NumButtons]bool + releaseEvents, tempReleaseEvents [pixel.NumButtons]bool prevJoy, currJoy, tempJoy joystickState } diff --git a/input.go b/input.go index 63e0e46..08c7c0d 100644 --- a/input.go +++ b/input.go @@ -24,19 +24,8 @@ const ( MouseButton7 MouseButton8 - // Last iota - // NOTE: These will be unexported in the future when Window is move to the pixel package. - NumMouseButtons int = iota - - // Aliases - MouseButtonLeft = MouseButton1 - MouseButtonRight = MouseButton2 - MouseButtonMiddle = MouseButton3 -) - -const ( // List of all keyboard buttons. - KeySpace = iota + Button(NumMouseButtons) + KeySpace KeyApostrophe KeyComma KeyMinus @@ -159,7 +148,12 @@ const ( // Last iota // NOTE: These will be unexported in the future when Window is move to the pixel package. - NumKeys int = iota + NumButtons int = iota + + // Aliases + MouseButtonLeft = MouseButton1 + MouseButtonRight = MouseButton2 + MouseButtonMiddle = MouseButton3 ) var buttonNames = map[Button]string{