examples/events: Fix examples to build with latest go-sdl2
Signed-off-by: Lilis Iskandar <lilis@veand.co>
This commit is contained in:
parent
48be04793a
commit
b0d2a074f1
|
@ -3,12 +3,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var winTitle string = "Go-SDL2 TestWaitEvent"
|
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
|
const pushTime uint32 = 1000 // number of milliseconds between event pushes
|
||||||
|
|
||||||
|
@ -38,8 +39,13 @@ func run() int {
|
||||||
defer renderer.Destroy()
|
defer renderer.Destroy()
|
||||||
|
|
||||||
var peepArray []sdl.Event = make([]sdl.Event, 2)
|
var peepArray []sdl.Event = make([]sdl.Event, 2)
|
||||||
peepArray[0] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 1331, nil, nil}
|
id, err := window.GetID()
|
||||||
peepArray[1] = &sdl.UserEvent{sdl.USEREVENT, sdl.GetTicks(), window.GetID(), 10101, nil, nil}
|
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
|
running = true
|
||||||
lastPushTime := sdl.GetTicks()
|
lastPushTime := sdl.GetTicks()
|
||||||
|
@ -50,7 +56,7 @@ func run() int {
|
||||||
numEventsHandled, err := sdl.PeepEvents(peepArray, sdl.ADDEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
|
numEventsHandled, err := sdl.PeepEvents(peepArray, sdl.ADDEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "PeepEvents error: %s\n", err)
|
fmt.Fprintf(os.Stderr, "PeepEvents error: %s\n", err)
|
||||||
return 3
|
return 4
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Successful push of %d events\n", numEventsHandled)
|
fmt.Printf("Successful push of %d events\n", numEventsHandled)
|
||||||
}
|
}
|
||||||
|
@ -69,7 +75,7 @@ func run() int {
|
||||||
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.KeyUpEvent:
|
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:
|
||||||
|
|
|
@ -3,12 +3,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var winTitle string = "Go-SDL2 TestWaitEvent"
|
var winTitle string = "Go-SDL2 TestWaitEvent"
|
||||||
var winWidth, winHeight int = 800, 600
|
var winWidth, winHeight int32 = 800, 600
|
||||||
|
|
||||||
func run() int {
|
func run() int {
|
||||||
var window *sdl.Window
|
var window *sdl.Window
|
||||||
|
@ -63,7 +64,7 @@ func run() int {
|
||||||
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.KeyUpEvent:
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var winTitle string = "Go-SDL2 TestWaitEvent"
|
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
|
const pushTime uint32 = 1000 // number of milliseconds between event pushes
|
||||||
|
|
||||||
|
@ -44,12 +45,16 @@ func run() int {
|
||||||
// Push a UserEvent every second
|
// Push a UserEvent every second
|
||||||
if lastPushTime+pushTime < sdl.GetTicks() {
|
if lastPushTime+pushTime < sdl.GetTicks() {
|
||||||
lastPushTime = 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
|
retVal, err := sdl.PushEvent(pEvent) // Here's where the event is actually pushed
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Failed to push event: %s\n", err)
|
fmt.Fprintf(os.Stderr, "Failed to push event: %s\n", err)
|
||||||
return 3
|
return 4
|
||||||
}
|
}
|
||||||
|
|
||||||
if retVal {
|
if retVal {
|
||||||
|
@ -72,7 +77,7 @@ func run() int {
|
||||||
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.KeyUpEvent:
|
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:
|
||||||
|
|
|
@ -3,12 +3,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var winTitle string = "Go-SDL2 TestWaitEvent"
|
var winTitle string = "Go-SDL2 TestWaitEvent"
|
||||||
var winWidth, winHeight int = 800, 600
|
var winWidth, winHeight int32 = 800, 600
|
||||||
|
|
||||||
func run() int {
|
func run() int {
|
||||||
var window *sdl.Window
|
var window *sdl.Window
|
||||||
|
@ -50,7 +51,7 @@ func run() int {
|
||||||
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.KeyUpEvent:
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var winTitle string = "Go-SDL2 TestWaitEvent"
|
var winTitle string = "Go-SDL2 TestWaitEvent"
|
||||||
var winWidth, winHeight int = 800, 600
|
var winWidth, winHeight int32 = 800, 600
|
||||||
|
|
||||||
func run() int {
|
func run() int {
|
||||||
var window *sdl.Window
|
var window *sdl.Window
|
||||||
|
@ -56,7 +57,7 @@ func run() int {
|
||||||
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.KeyUpEvent:
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue