example/basic: rewrite to use event loop
Change-Id: Ic7d8557c42b17238f3dae7fc9287a7cdb5f55eb1 Reviewed-on: https://go-review.googlesource.com/12272 Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
parent
e4c6af17e3
commit
460bd28e6c
@ -31,7 +31,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"golang.org/x/mobile/app"
|
"golang.org/x/mobile/app"
|
||||||
|
"golang.org/x/mobile/event"
|
||||||
"golang.org/x/mobile/event/config"
|
"golang.org/x/mobile/event/config"
|
||||||
|
"golang.org/x/mobile/event/lifecycle"
|
||||||
|
"golang.org/x/mobile/event/paint"
|
||||||
"golang.org/x/mobile/event/touch"
|
"golang.org/x/mobile/event/touch"
|
||||||
"golang.org/x/mobile/exp/app/debug"
|
"golang.org/x/mobile/exp/app/debug"
|
||||||
"golang.org/x/mobile/exp/f32"
|
"golang.org/x/mobile/exp/f32"
|
||||||
@ -52,12 +55,27 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app.Run(app.Callbacks{
|
app.Main(func(a app.App) {
|
||||||
Start: onStart,
|
var c config.Event
|
||||||
Stop: onStop,
|
for e := range a.Events() {
|
||||||
Draw: onDraw,
|
switch e := event.Filter(e).(type) {
|
||||||
Touch: onTouch,
|
case lifecycle.Event:
|
||||||
Config: onConfig,
|
switch e.Crosses(lifecycle.StageVisible) {
|
||||||
|
case lifecycle.CrossOn:
|
||||||
|
onStart()
|
||||||
|
case lifecycle.CrossOff:
|
||||||
|
onStop()
|
||||||
|
}
|
||||||
|
case config.Event:
|
||||||
|
c = e
|
||||||
|
touchLoc = geom.Point{c.Width / 2, c.Height / 2}
|
||||||
|
case paint.Event:
|
||||||
|
onDraw(c)
|
||||||
|
a.EndDraw()
|
||||||
|
case touch.Event:
|
||||||
|
touchLoc = e.Loc
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,14 +104,6 @@ func onStop() {
|
|||||||
gl.DeleteBuffer(buf)
|
gl.DeleteBuffer(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func onConfig(new, old config.Event) {
|
|
||||||
touchLoc = geom.Point{new.Width / 2, new.Height / 2}
|
|
||||||
}
|
|
||||||
|
|
||||||
func onTouch(t touch.Event, c config.Event) {
|
|
||||||
touchLoc = t.Loc
|
|
||||||
}
|
|
||||||
|
|
||||||
func onDraw(c config.Event) {
|
func onDraw(c config.Event) {
|
||||||
gl.ClearColor(1, 0, 0, 1)
|
gl.ClearColor(1, 0, 0, 1)
|
||||||
gl.Clear(gl.COLOR_BUFFER_BIT)
|
gl.Clear(gl.COLOR_BUFFER_BIT)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user