examples: updated to remove pointer in event switch cases
Signed-off-by: Lilis Iskandar <lilis@veand.co>
This commit is contained in:
parent
ec18b7ebf0
commit
4b17b2bbcf
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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 := ""
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue