event/config: rename to event/size.

Change-Id: I908b5f0818da32b2b040f430ebcc3762eb6f7570
Reviewed-on: https://go-review.googlesource.com/13601
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Nigel Tao
2015-08-13 19:59:18 +10:00
parent b5583e233e
commit f632204bcc
20 changed files with 113 additions and 114 deletions

View File

@ -41,9 +41,9 @@ import (
"golang.org/x/mobile/app"
"golang.org/x/mobile/asset"
"golang.org/x/mobile/event/config"
"golang.org/x/mobile/event/lifecycle"
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/exp/app/debug"
"golang.org/x/mobile/exp/audio"
"golang.org/x/mobile/exp/f32"
@ -66,7 +66,7 @@ var (
player *audio.Player
cfg config.Event
sz size.Event
)
func main() {
@ -80,8 +80,8 @@ func main() {
case lifecycle.CrossOff:
onStop()
}
case config.Event:
cfg = e
case size.Event:
sz = e
case paint.Event:
onPaint()
a.EndPaint(e)
@ -112,8 +112,8 @@ func onPaint() {
gl.ClearColor(1, 1, 1, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
now := clock.Time(time.Since(startTime) * 60 / time.Second)
eng.Render(scene, now, cfg)
debug.DrawFPS(cfg)
eng.Render(scene, now, sz)
debug.DrawFPS(sz)
}
func newNode() *sprite.Node {
@ -136,7 +136,7 @@ func loadScene() {
dx, dy := float32(1), float32(1)
n := newNode()
// TODO: Shouldn't arranger pass the config.Event?
// TODO: Shouldn't arranger pass the size.Event?
n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
eng.SetSubTex(n, gopher)
@ -148,11 +148,11 @@ func loadScene() {
dy = 1
boing()
}
if x+width > float32(cfg.WidthPt) {
if x+width > float32(sz.WidthPt) {
dx = -1
boing()
}
if y+height > float32(cfg.HeightPt) {
if y+height > float32(sz.HeightPt) {
dy = -1
boing()
}

View File

@ -33,9 +33,9 @@ import (
"log"
"golang.org/x/mobile/app"
"golang.org/x/mobile/event/config"
"golang.org/x/mobile/event/lifecycle"
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/event/touch"
"golang.org/x/mobile/exp/app/debug"
"golang.org/x/mobile/exp/f32"
@ -57,7 +57,7 @@ var (
func main() {
app.Main(func(a app.App) {
var c config.Event
var sz size.Event
for e := range a.Events() {
switch e := app.Filter(e).(type) {
case lifecycle.Event:
@ -67,12 +67,12 @@ func main() {
case lifecycle.CrossOff:
onStop()
}
case config.Event:
c = e
touchX = float32(c.WidthPx / 2)
touchY = float32(c.HeightPx / 2)
case size.Event:
sz = e
touchX = float32(sz.WidthPx / 2)
touchY = float32(sz.HeightPx / 2)
case paint.Event:
onPaint(c)
onPaint(sz)
a.EndPaint(e)
case touch.Event:
touchX = e.X
@ -107,7 +107,7 @@ func onStop() {
gl.DeleteBuffer(buf)
}
func onPaint(c config.Event) {
func onPaint(sz size.Event) {
gl.ClearColor(1, 0, 0, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
@ -119,7 +119,7 @@ func onPaint(c config.Event) {
}
gl.Uniform4f(color, 0, green, 0, 1)
gl.Uniform2f(offset, touchX/float32(c.WidthPx), touchY/float32(c.HeightPx))
gl.Uniform2f(offset, touchX/float32(sz.WidthPx), touchY/float32(sz.HeightPx))
gl.BindBuffer(gl.ARRAY_BUFFER, buf)
gl.EnableVertexAttribArray(position)
@ -127,7 +127,7 @@ func onPaint(c config.Event) {
gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)
gl.DisableVertexAttribArray(position)
debug.DrawFPS(c)
debug.DrawFPS(sz)
}
var triangleData = f32.Bytes(binary.LittleEndian,

View File

@ -43,8 +43,8 @@ import (
"net/http"
"golang.org/x/mobile/app"
"golang.org/x/mobile/event/config"
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/exp/app/debug"
"golang.org/x/mobile/gl"
)
@ -54,13 +54,13 @@ func main() {
go checkNetwork()
app.Main(func(a app.App) {
var c config.Event
var sz size.Event
for e := range a.Events() {
switch e := app.Filter(e).(type) {
case config.Event:
c = e
case size.Event:
sz = e
case paint.Event:
onDraw(c)
onDraw(sz)
a.EndPaint(e)
}
}
@ -82,7 +82,7 @@ func checkNetwork() {
ok = true
}
func onDraw(c config.Event) {
func onDraw(sz size.Event) {
select {
case <-determined:
if ok {
@ -95,5 +95,5 @@ func onDraw(c config.Event) {
}
gl.Clear(gl.COLOR_BUFFER_BIT)
debug.DrawFPS(c)
debug.DrawFPS(sz)
}

View File

@ -38,8 +38,8 @@ import (
"golang.org/x/mobile/app"
"golang.org/x/mobile/asset"
"golang.org/x/mobile/event/config"
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/exp/app/debug"
"golang.org/x/mobile/exp/f32"
"golang.org/x/mobile/exp/sprite"
@ -56,28 +56,28 @@ var (
func main() {
app.Main(func(a app.App) {
var c config.Event
var sz size.Event
for e := range a.Events() {
switch e := app.Filter(e).(type) {
case config.Event:
c = e
case size.Event:
sz = e
case paint.Event:
onPaint(c)
onPaint(sz)
a.EndPaint(e)
}
}
})
}
func onPaint(c config.Event) {
func onPaint(sz size.Event) {
if scene == nil {
loadScene()
}
gl.ClearColor(1, 1, 1, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
now := clock.Time(time.Since(startTime) * 60 / time.Second)
eng.Render(scene, now, c)
debug.DrawFPS(c)
eng.Render(scene, now, sz)
debug.DrawFPS(sz)
}
func newNode() *sprite.Node {