Skip to content

Commit

Permalink
Mouse and Key buttons must share a common NumButtons iota, otherwise …
Browse files Browse the repository at this point in the history
…the count is off
  • Loading branch information
bhperry committed Oct 14, 2023
1 parent 4a06644 commit f361084
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
6 changes: 3 additions & 3 deletions backends/opengl/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand Down
8 changes: 4 additions & 4 deletions backends/opengl/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 7 additions & 13 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit f361084

Please sign in to comment.