examples/events: Fix examples to build with latest go-sdl2

Signed-off-by: Lilis Iskandar <lilis@veand.co>
This commit is contained in:
Lilis Iskandar 2018-08-08 23:59:37 +00:00
parent 48be04793a
commit b0d2a074f1
5 changed files with 35 additions and 21 deletions

View File

@ -3,12 +3,13 @@ package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
"github.com/veandco/go-sdl2/sdl"
)
var winTitle string = "Go-SDL2 TestWaitEvent"
var winWidth, winHeight int = 800, 600
var winWidth, winHeight int32 = 800, 600
const pushTime uint32 = 1000 // number of milliseconds between event pushes
@ -38,8 +39,13 @@ func run() int {
defer renderer.Destroy()
var peepArray []sdl.Event = make([]sdl.Event, 2)
peepArray[0] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
peepArray[1] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 10101, nil, nil}
id, err := window.GetID()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get window ID: %s\n", err)
return 3
}
peepArray[0] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), id, 1331, nil, nil}
peepArray[1] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), id, 10101, nil, nil}
running = true
lastPushTime := sdl.GetTicks()
@ -50,7 +56,7 @@ func run() int {
numEventsHandled, err := sdl.PeepEvents(peepArray, sdl.ADDEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
if err != nil {
fmt.Fprintf(os.Stderr, "PeepEvents error: %s\n", err)
return 3
return 4
} else {
fmt.Printf("Successful push of %d events\n", numEventsHandled)
}
@ -69,7 +75,7 @@ func run() int {
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.KeyUpEvent:
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:

View File

@ -3,12 +3,13 @@ package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
"github.com/veandco/go-sdl2/sdl"
)
var winTitle string = "Go-SDL2 TestWaitEvent"
var winWidth, winHeight int = 800, 600
var winWidth, winHeight int32 = 800, 600
func run() int {
var window *sdl.Window
@ -63,7 +64,7 @@ func run() int {
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.KeyUpEvent:
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)
}
@ -76,4 +77,4 @@ func run() int {
func main() {
os.Exit(run())
}
}

View File

@ -3,12 +3,13 @@ package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
"github.com/veandco/go-sdl2/sdl"
)
var winTitle string = "Go-SDL2 TestWaitEvent"
var winWidth, winHeight int = 800, 600
var winWidth, winHeight int32 = 800, 600
const pushTime uint32 = 1000 // number of milliseconds between event pushes
@ -44,12 +45,16 @@ func run() int {
// Push a UserEvent every second
if lastPushTime+pushTime < sdl.GetTicks() {
lastPushTime = sdl.GetTicks()
pEvent := &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
id, err := window.GetID()
if err != nil {
return 3
}
pEvent := &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), id, 1331, nil, nil}
retVal, err := sdl.PushEvent(pEvent) // Here's where the event is actually pushed
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to push event: %s\n", err)
return 3
return 4
}
if retVal {
@ -72,7 +77,7 @@ func run() int {
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.KeyUpEvent:
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:

View File

@ -3,12 +3,13 @@ package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
"github.com/veandco/go-sdl2/sdl"
)
var winTitle string = "Go-SDL2 TestWaitEvent"
var winWidth, winHeight int = 800, 600
var winWidth, winHeight int32 = 800, 600
func run() int {
var window *sdl.Window
@ -50,7 +51,7 @@ func run() int {
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.KeyUpEvent:
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)
}

View File

@ -4,12 +4,13 @@ package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
"github.com/veandco/go-sdl2/sdl"
)
var winTitle string = "Go-SDL2 TestWaitEvent"
var winWidth, winHeight int = 800, 600
var winWidth, winHeight int32 = 800, 600
func run() int {
var window *sdl.Window
@ -56,7 +57,7 @@ func run() int {
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.KeyUpEvent:
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)
}