From 4b17b2bbcfdcfe11627958ea63e3eeacb41f1444 Mon Sep 17 00:00:00 2001 From: Lilis Iskandar Date: Thu, 30 Nov 2023 14:59:58 +0800 Subject: [PATCH] examples: updated to remove pointer in event switch cases Signed-off-by: Lilis Iskandar --- examples/android/main.go | 6 ++--- examples/drawing-text/drawing-text.go | 2 +- examples/events/PeepEvents_add.go | 12 +++++----- examples/events/PeepEvents_peek.go | 10 ++++----- examples/events/PushEvent.go | 12 +++++----- examples/events/WaitEvent.go | 10 ++++----- examples/events/WaitEventTimeout.go | 10 ++++----- examples/events/events.go | 22 +++++++++---------- examples/joystick-input/joystick-input.go | 14 ++++++------ examples/keyboard-input/keyboard-input.go | 4 ++-- examples/loading-images/loading-images.go | 2 +- examples/mouse-input/mouse-input.go | 8 +++---- examples/opengl/opengl.go | 4 ++-- examples/opengl3/opengl3.go | 4 ++-- examples/render/render.go | 2 +- .../render_goroutines/render_goroutines.go | 2 +- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/examples/android/main.go b/examples/android/main.go index a1f3625..7bfc88d 100644 --- a/examples/android/main.go +++ b/examples/android/main.go @@ -214,10 +214,10 @@ func SDL_main() { for e.Running() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: e.Quit() - case *sdl.MouseButtonEvent: + case sdl.MouseButtonEvent: e.Sound.Play(2, 0) if t.Type == sdl.MOUSEBUTTONDOWN && t.Button == sdl.BUTTON_LEFT { 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 { e.Quit() } diff --git a/examples/drawing-text/drawing-text.go b/examples/drawing-text/drawing-text.go index eabc24f..7fc364a 100644 --- a/examples/drawing-text/drawing-text.go +++ b/examples/drawing-text/drawing-text.go @@ -63,7 +63,7 @@ func run() (err error) { for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false } } diff --git a/examples/events/PeepEvents_add.go b/examples/events/PeepEvents_add.go index 3d2e367..3e87b99 100644 --- a/examples/events/PeepEvents_add.go +++ b/examples/events/PeepEvents_add.go @@ -64,21 +64,21 @@ func run() int { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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", 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", 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", 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", 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) } } diff --git a/examples/events/PeepEvents_peek.go b/examples/events/PeepEvents_peek.go index 40e97ff..d0bffc6 100644 --- a/examples/events/PeepEvents_peek.go +++ b/examples/events/PeepEvents_peek.go @@ -53,18 +53,18 @@ func run() int { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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", 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", 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", 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", t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) } diff --git a/examples/events/PushEvent.go b/examples/events/PushEvent.go index 6bb9096..c6b3c07 100644 --- a/examples/events/PushEvent.go +++ b/examples/events/PushEvent.go @@ -66,21 +66,21 @@ func run() int { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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", 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", 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", 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", 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) } } diff --git a/examples/events/WaitEvent.go b/examples/events/WaitEvent.go index 036613d..3506946 100644 --- a/examples/events/WaitEvent.go +++ b/examples/events/WaitEvent.go @@ -40,18 +40,18 @@ func run() int { for running { event = sdl.WaitEvent() // wait here until an event is in the event queue switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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", 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", 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", 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", t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) } diff --git a/examples/events/WaitEventTimeout.go b/examples/events/WaitEventTimeout.go index 308164f..d69a56a 100644 --- a/examples/events/WaitEventTimeout.go +++ b/examples/events/WaitEventTimeout.go @@ -46,18 +46,18 @@ func run() int { } switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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", 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", 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", 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", t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat) } diff --git a/examples/events/events.go b/examples/events/events.go index bb6f74c..95c1e64 100644 --- a/examples/events/events.go +++ b/examples/events/events.go @@ -35,38 +35,38 @@ func run() int { for running { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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", 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", 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", 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", 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", 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", 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", 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", 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)) if joysticks[int(t.Which)] != nil { fmt.Printf("Joystick %d connected\n", t.Which) } - case *sdl.JoyDeviceRemovedEvent: + case sdl.JoyDeviceRemovedEvent: if joystick := joysticks[int(t.Which)]; joystick != nil { joystick.Close() } diff --git a/examples/joystick-input/joystick-input.go b/examples/joystick-input/joystick-input.go index c1475fe..ef13507 100644 --- a/examples/joystick-input/joystick-input.go +++ b/examples/joystick-input/joystick-input.go @@ -29,20 +29,20 @@ func run() (err error) { for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false - case *sdl.JoyAxisEvent: + case sdl.JoyAxisEvent: fmt.Printf("[%d ms] JoyAxis\ttype:%d\twhich:%c\taxis:%d\tvalue:%d\n", 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) - case *sdl.JoyButtonEvent: + case sdl.JoyButtonEvent: if t.State == sdl.PRESSED { fmt.Println("Joystick", t.Which, "button", t.Button, "pressed") } else { fmt.Println("Joystick", t.Which, "button", t.Button, "released") } - case *sdl.JoyHatEvent: + case sdl.JoyHatEvent: position := "" switch t.Value { @@ -67,13 +67,13 @@ func run() (err error) { } fmt.Println("Joystick", t.Which, "hat", t.Hat, "moved to", position, "position") - case *sdl.JoyDeviceAddedEvent: + case sdl.JoyDeviceAddedEvent: // Open joystick for use joysticks[int(t.Which)] = sdl.JoystickOpen(int(t.Which)) if joysticks[int(t.Which)] != nil { fmt.Println("Joystick", t.Which, "connected") } - case *sdl.JoyDeviceRemovedEvent: + case sdl.JoyDeviceRemovedEvent: if joystick := joysticks[int(t.Which)]; joystick != nil { joystick.Close() } diff --git a/examples/keyboard-input/keyboard-input.go b/examples/keyboard-input/keyboard-input.go index f27b88c..9e68fa9 100644 --- a/examples/keyboard-input/keyboard-input.go +++ b/examples/keyboard-input/keyboard-input.go @@ -25,9 +25,9 @@ func run() (err error) { for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false - case *sdl.KeyboardEvent: + case sdl.KeyboardEvent: keyCode := t.Keysym.Sym keys := "" diff --git a/examples/loading-images/loading-images.go b/examples/loading-images/loading-images.go index 43ec040..2ac82a0 100644 --- a/examples/loading-images/loading-images.go +++ b/examples/loading-images/loading-images.go @@ -59,7 +59,7 @@ func run() (err error) { for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false } } diff --git a/examples/mouse-input/mouse-input.go b/examples/mouse-input/mouse-input.go index 162db8c..3b2b9e4 100644 --- a/examples/mouse-input/mouse-input.go +++ b/examples/mouse-input/mouse-input.go @@ -25,17 +25,17 @@ func run() (err error) { for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false - case *sdl.MouseMotionEvent: + case sdl.MouseMotionEvent: 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 { fmt.Println("Mouse", t.Which, "button", t.Button, "pressed at", t.X, t.Y) } else { fmt.Println("Mouse", t.Which, "button", t.Button, "released at", t.X, t.Y) } - case *sdl.MouseWheelEvent: + case sdl.MouseWheelEvent: if t.X != 0 { fmt.Println("Mouse", t.Which, "wheel scrolled horizontally by", t.X) } else { diff --git a/examples/opengl/opengl.go b/examples/opengl/opengl.go index 9dbcec6..19b7833 100644 --- a/examples/opengl/opengl.go +++ b/examples/opengl/opengl.go @@ -48,9 +48,9 @@ func main() { for running { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: 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) } } diff --git a/examples/opengl3/opengl3.go b/examples/opengl3/opengl3.go index 1b53bc0..027216f 100644 --- a/examples/opengl3/opengl3.go +++ b/examples/opengl3/opengl3.go @@ -126,9 +126,9 @@ func main() { for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false - case *sdl.MouseMotionEvent: + case sdl.MouseMotionEvent: xrot = float32(t.Y) / 2 yrot = float32(t.X) / 2 diff --git a/examples/render/render.go b/examples/render/render.go index d989dd8..d13585a 100644 --- a/examples/render/render.go +++ b/examples/render/render.go @@ -39,7 +39,7 @@ func run() int { for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: running = false } } diff --git a/examples/render_goroutines/render_goroutines.go b/examples/render_goroutines/render_goroutines.go index 2583b43..f0f2f2b 100644 --- a/examples/render_goroutines/render_goroutines.go +++ b/examples/render_goroutines/render_goroutines.go @@ -72,7 +72,7 @@ func run() int { sdl.Do(func() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { - case *sdl.QuitEvent: + case sdl.QuitEvent: runningMutex.Lock() running = false runningMutex.Unlock()