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 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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 := ""
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue