veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.17k stars 219 forks source link

sdl: Bugfix the button rework #564

Closed Lundis closed 1 year ago

Lundis commented 1 year ago

MouseButtonEvent.button is a Button, not a ButtonMask. On the other hand, it is correct that MouseMotionEvent, GetRelativeMouseState, GetMouseState and GetGlobalMouseState all deal with ButtonMask.

The utility functions to convert between Button and ButtonMask mentioned in the example here was not committed: so I added them also since they sounded nice.

So the correct way to check for a right button in a MouseButtonEvent e

if e.Button == sdl.ButtonRight {...}

While for a MouseMotionEvent e it would be:

if e.State.Has(sdl.ButtonLeft) {...}

or

if e.State&sdl.ButtonMaskLeft != 0 {...}
veeableful commented 1 year ago

Hi @Lundis, thanks for the fixes! I was wondering if we need additional Has() API but if both of you would like to have it then I will merge it.