mirror of
https://github.com/netbirdio/gomobile-tvos-fork.git
synced 2026-05-22 18:43:29 -07:00
event/paint: mark paint events sent by the system
A paint.Event now has an External field. Whenever a paint event is sent by the x/mobile/app package, it is marked as external so users with an active paint loop can ignore them. Implemented on OS X and Android, with examples updated. Change-Id: Ibee8d65625c8818ff954936be48257ad30daa147 Reviewed-on: https://go-review.googlesource.com/15480 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
+13
-12
@@ -60,35 +60,36 @@ var (
|
||||
func main() {
|
||||
app.Main(func(a app.App) {
|
||||
var glctx gl.Context
|
||||
visible, sz := false, size.Event{}
|
||||
var sz size.Event
|
||||
for e := range a.Events() {
|
||||
switch e := a.Filter(e).(type) {
|
||||
case lifecycle.Event:
|
||||
switch e.Crosses(lifecycle.StageVisible) {
|
||||
case lifecycle.CrossOn:
|
||||
visible = true
|
||||
glctx, _ = e.DrawContext.(gl.Context)
|
||||
onStart(glctx)
|
||||
a.Send(paint.Event{})
|
||||
case lifecycle.CrossOff:
|
||||
visible = false
|
||||
onStop(glctx)
|
||||
glctx = nil
|
||||
}
|
||||
case size.Event:
|
||||
sz = e
|
||||
touchX = float32(sz.WidthPx / 2)
|
||||
touchY = float32(sz.HeightPx / 2)
|
||||
case paint.Event:
|
||||
if glctx == nil || e.External {
|
||||
// As we are actively painting as fast as
|
||||
// we can (usually 60 FPS), skip any paint
|
||||
// events sent by the system.
|
||||
continue
|
||||
}
|
||||
|
||||
onPaint(glctx, sz)
|
||||
a.Publish()
|
||||
if visible {
|
||||
// Drive the animation by preparing to paint the next frame
|
||||
// after this one is shown.
|
||||
//
|
||||
// TODO: is paint.Event the right thing to send? Should we
|
||||
// have a dedicated publish.Event type? Should App.Publish
|
||||
// take an optional event sender and send a publish.Event?
|
||||
a.Send(paint.Event{})
|
||||
}
|
||||
// Drive the animation by preparing to paint the next frame
|
||||
// after this one is shown.
|
||||
a.Send(paint.Event{})
|
||||
case touch.Event:
|
||||
touchX = e.X
|
||||
touchY = e.Y
|
||||
|
||||
Reference in New Issue
Block a user