examples: updated to remove pointer in event switch cases

Signed-off-by: Lilis Iskandar <lilis@veand.co>
This commit is contained in:
Lilis Iskandar 2023-11-30 14:59:58 +08:00
parent ec18b7ebf0
commit 4b17b2bbcf
No known key found for this signature in database
GPG Key ID: 7EE2F0C4E86662C6
16 changed files with 62 additions and 62 deletions

View File

@ -214,10 +214,10 @@ func SDL_main() {
for e.Running() { for e.Running() {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
e.Quit() e.Quit()
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
e.Sound.Play(2, 0) e.Sound.Play(2, 0)
if t.Type == sdl.MOUSEBUTTONDOWN && t.Button == sdl.BUTTON_LEFT { if t.Type == sdl.MOUSEBUTTONDOWN && t.Button == sdl.BUTTON_LEFT {
alpha = 255 alpha = 255
@ -235,7 +235,7 @@ func SDL_main() {
} }
} }
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
if t.Keysym.Scancode == sdl.SCANCODE_ESCAPE || t.Keysym.Scancode == sdl.SCANCODE_AC_BACK { if t.Keysym.Scancode == sdl.SCANCODE_ESCAPE || t.Keysym.Scancode == sdl.SCANCODE_AC_BACK {
e.Quit() e.Quit()
} }

View File

@ -63,7 +63,7 @@ func run() (err error) {
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) { switch event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
} }
} }

View File

@ -64,21 +64,21 @@ func run() int {
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n", fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y) t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n", fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
case *sdl.UserEvent: case sdl.UserEvent:
fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code) fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code)
} }
} }

View File

@ -53,18 +53,18 @@ func run() int {
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n", fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y) t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n", fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
} }

View File

@ -66,21 +66,21 @@ func run() int {
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n", fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y) t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n", fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
case *sdl.UserEvent: case sdl.UserEvent:
fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code) fmt.Printf("[%d ms] UserEvent\tcode:%d\n", t.Timestamp, t.Code)
} }
} }

View File

@ -40,18 +40,18 @@ func run() int {
for running { for running {
event = sdl.WaitEvent() // wait here until an event is in the event queue event = sdl.WaitEvent() // wait here until an event is in the event queue
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n", fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y) t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n", fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
} }

View File

@ -46,18 +46,18 @@ func run() int {
} }
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n", fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y) t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n", fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
} }

View File

@ -35,38 +35,38 @@ func run() int {
for running { for running {
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n", fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
t.Timestamp, t.Type, t.Which, t.X, t.Y) t.Timestamp, t.Type, t.Which, t.X, t.Y)
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n", fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
case *sdl.JoyAxisEvent: case sdl.JoyAxisEvent:
fmt.Printf("[%d ms] JoyAxis\ttype:%d\twhich:%c\taxis:%d\tvalue:%d\n", fmt.Printf("[%d ms] JoyAxis\ttype:%d\twhich:%c\taxis:%d\tvalue:%d\n",
t.Timestamp, t.Type, t.Which, t.Axis, t.Value) t.Timestamp, t.Type, t.Which, t.Axis, t.Value)
case *sdl.JoyBallEvent: case sdl.JoyBallEvent:
fmt.Printf("[%d ms] JoyBall\ttype:%d\twhich:%d\tball:%d\txrel:%d\tyrel:%d\n", fmt.Printf("[%d ms] JoyBall\ttype:%d\twhich:%d\tball:%d\txrel:%d\tyrel:%d\n",
t.Timestamp, t.Type, t.Which, t.Ball, t.XRel, t.YRel) t.Timestamp, t.Type, t.Which, t.Ball, t.XRel, t.YRel)
case *sdl.JoyButtonEvent: case sdl.JoyButtonEvent:
fmt.Printf("[%d ms] JoyButton\ttype:%d\twhich:%d\tbutton:%d\tstate:%d\n", fmt.Printf("[%d ms] JoyButton\ttype:%d\twhich:%d\tbutton:%d\tstate:%d\n",
t.Timestamp, t.Type, t.Which, t.Button, t.State) t.Timestamp, t.Type, t.Which, t.Button, t.State)
case *sdl.JoyHatEvent: case sdl.JoyHatEvent:
fmt.Printf("[%d ms] JoyHat\ttype:%d\twhich:%d\that:%d\tvalue:%d\n", fmt.Printf("[%d ms] JoyHat\ttype:%d\twhich:%d\that:%d\tvalue:%d\n",
t.Timestamp, t.Type, t.Which, t.Hat, t.Value) t.Timestamp, t.Type, t.Which, t.Hat, t.Value)
case *sdl.JoyDeviceAddedEvent: case sdl.JoyDeviceAddedEvent:
joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which)) joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which))
if joysticks[int(t.Which)] != nil { if joysticks[int(t.Which)] != nil {
fmt.Printf("Joystick %d connected\n", t.Which) fmt.Printf("Joystick %d connected\n", t.Which)
} }
case *sdl.JoyDeviceRemovedEvent: case sdl.JoyDeviceRemovedEvent:
if joystick := joysticks[int(t.Which)]; joystick != nil { if joystick := joysticks[int(t.Which)]; joystick != nil {
joystick.Close() joystick.Close()
} }

View File

@ -29,20 +29,20 @@ func run() (err error) {
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.JoyAxisEvent: case sdl.JoyAxisEvent:
fmt.Printf("[%d ms] JoyAxis\ttype:%d\twhich:%c\taxis:%d\tvalue:%d\n", fmt.Printf("[%d ms] JoyAxis\ttype:%d\twhich:%c\taxis:%d\tvalue:%d\n",
t.Timestamp, t.Type, t.Which, t.Axis, t.Value) t.Timestamp, t.Type, t.Which, t.Axis, t.Value)
case *sdl.JoyBallEvent: case sdl.JoyBallEvent:
fmt.Println("Joystick", t.Which, "trackball moved by", t.XRel, t.YRel) fmt.Println("Joystick", t.Which, "trackball moved by", t.XRel, t.YRel)
case *sdl.JoyButtonEvent: case sdl.JoyButtonEvent:
if t.State == sdl.PRESSED { if t.State == sdl.PRESSED {
fmt.Println("Joystick", t.Which, "button", t.Button, "pressed") fmt.Println("Joystick", t.Which, "button", t.Button, "pressed")
} else { } else {
fmt.Println("Joystick", t.Which, "button", t.Button, "released") fmt.Println("Joystick", t.Which, "button", t.Button, "released")
} }
case *sdl.JoyHatEvent: case sdl.JoyHatEvent:
position := "" position := ""
switch t.Value { switch t.Value {
@ -67,13 +67,13 @@ func run() (err error) {
} }
fmt.Println("Joystick", t.Which, "hat", t.Hat, "moved to", position, "position") fmt.Println("Joystick", t.Which, "hat", t.Hat, "moved to", position, "position")
case *sdl.JoyDeviceAddedEvent: case sdl.JoyDeviceAddedEvent:
// Open joystick for use // Open joystick for use
joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which)) joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which))
if joysticks[int(t.Which)] != nil { if joysticks[int(t.Which)] != nil {
fmt.Println("Joystick", t.Which, "connected") fmt.Println("Joystick", t.Which, "connected")
} }
case *sdl.JoyDeviceRemovedEvent: case sdl.JoyDeviceRemovedEvent:
if joystick := joysticks[int(t.Which)]; joystick != nil { if joystick := joysticks[int(t.Which)]; joystick != nil {
joystick.Close() joystick.Close()
} }

View File

@ -25,9 +25,9 @@ func run() (err error) {
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.KeyboardEvent: case sdl.KeyboardEvent:
keyCode := t.Keysym.Sym keyCode := t.Keysym.Sym
keys := "" keys := ""

View File

@ -59,7 +59,7 @@ func run() (err error) {
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) { switch event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
} }
} }

View File

@ -25,17 +25,17 @@ func run() (err error) {
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Println("Mouse", t.Which, "moved by", t.XRel, t.YRel, "at", t.X, t.Y) fmt.Println("Mouse", t.Which, "moved by", t.XRel, t.YRel, "at", t.X, t.Y)
case *sdl.MouseButtonEvent: case sdl.MouseButtonEvent:
if t.State == sdl.PRESSED { if t.State == sdl.PRESSED {
fmt.Println("Mouse", t.Which, "button", t.Button, "pressed at", t.X, t.Y) fmt.Println("Mouse", t.Which, "button", t.Button, "pressed at", t.X, t.Y)
} else { } else {
fmt.Println("Mouse", t.Which, "button", t.Button, "released at", t.X, t.Y) fmt.Println("Mouse", t.Which, "button", t.Button, "released at", t.X, t.Y)
} }
case *sdl.MouseWheelEvent: case sdl.MouseWheelEvent:
if t.X != 0 { if t.X != 0 {
fmt.Println("Mouse", t.Which, "wheel scrolled horizontally by", t.X) fmt.Println("Mouse", t.Which, "wheel scrolled horizontally by", t.X)
} else { } else {

View File

@ -48,9 +48,9 @@ func main() {
for running { for running {
for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
fmt.Printf("[%d ms] MouseMotion\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", t.Timestamp, t.Which, t.X, t.Y, t.XRel, t.YRel) fmt.Printf("[%d ms] MouseMotion\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n", t.Timestamp, t.Which, t.X, t.Y, t.XRel, t.YRel)
} }
} }

View File

@ -126,9 +126,9 @@ func main() {
for event = sdl.PollEvent(); event != nil; event = for event = sdl.PollEvent(); event != nil; event =
sdl.PollEvent() { sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
case *sdl.MouseMotionEvent: case sdl.MouseMotionEvent:
xrot = float32(t.Y) / 2 xrot = float32(t.Y) / 2
yrot = float32(t.X) / 2 yrot = float32(t.X) / 2

View File

@ -39,7 +39,7 @@ func run() int {
for running { for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) { switch event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
running = false running = false
} }
} }

View File

@ -72,7 +72,7 @@ func run() int {
sdl.Do(func() { sdl.Do(func() {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) { switch event.(type) {
case *sdl.QuitEvent: case sdl.QuitEvent:
runningMutex.Lock() runningMutex.Lock()
running = false running = false
runningMutex.Unlock() runningMutex.Unlock()