예제 #1
0
파일: app.go 프로젝트: handong890/mobile
// Run starts the mobile application.
//
// It must be called directly from the main function and will block until the
// application exits.
//
// Deprecated: call Main directly instead.
func Run(cb Callbacks) {
	Main(func(a App) {
		var c event.Config
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Lifecycle:
				switch e.Crosses(event.LifecycleStageVisible) {
				case event.ChangeOn:
					if cb.Start != nil {
						cb.Start()
					}
				case event.ChangeOff:
					if cb.Stop != nil {
						cb.Stop()
					}
				}
			case event.Config:
				if cb.Config != nil {
					cb.Config(e, c)
				}
				c = e
			case event.Draw:
				if cb.Draw != nil {
					cb.Draw(c)
				}
				a.EndDraw()
			case event.Touch:
				if cb.Touch != nil {
					cb.Touch(e, c)
				}
			}
		}
	})
}
예제 #2
0
func main() {
	app.Main(func(a app.App) {
		var c event.Config
		var eng *WritableEngine
		var root *sprite.Node
		startClock := time.Now()
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Config:
				c = e
			case event.Draw:
				if eng == nil || root == nil {
					eng = NewWritableEngine(
						glsprite.Engine(),
						image.Rect(0, 0, int(c.Width.Px(c.PixelsPerPt)), int(c.Height.Px(c.PixelsPerPt))),
						color.White,
					)
					root = loadScene(eng, loadTextures(eng))
					go listen(eng, ":8080")
				}
				now := clock.Time(time.Since(startClock) * 60 / time.Second)
				gl.ClearColor(1, 1, 1, 1)
				gl.Clear(gl.COLOR_BUFFER_BIT)
				gl.Enable(gl.BLEND)
				gl.BlendEquation(gl.FUNC_ADD)
				gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
				if eng != nil && root != nil {
					eng.Render(root, now, c)
				}
				a.EndDraw()
			}
		}
	})
}
예제 #3
0
파일: app.go 프로젝트: SpruceHealth/mobile
// Run starts the mobile application.
//
// It must be called directly from the main function and will block until the
// application exits.
//
// Deprecated: call Main directly instead.
func Run(cb Callbacks) {
	Main(func(a App) {
		var c config.Event
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					if cb.Start != nil {
						cb.Start()
					}
				case lifecycle.CrossOff:
					if cb.Stop != nil {
						cb.Stop()
					}
				}
			case config.Event:
				if cb.Config != nil {
					cb.Config(e, c)
				}
				c = e
			case paint.Event:
				if cb.Draw != nil {
					cb.Draw(c)
				}
				a.EndDraw()
			case touch.Event:
				if cb.Touch != nil {
					cb.Touch(e, c)
				}
			}
		}
	})
}
예제 #4
0
파일: main.go 프로젝트: tendermint/mobile
func main() {
	// checkNetwork runs only once when the app first loads.
	go checkNetwork()

	app.Main(func(a app.App) {
		var c config.Event
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case config.Event:
				c = e
			case paint.Event:
				onDraw(c)
				a.EndPaint()
			}
		}
	})
}
예제 #5
0
func main() {
	app.Main(func(a app.App) {
		var c event.Config
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Lifecycle:
				switch e.Crosses(event.LifecycleStageVisible) {
				case event.ChangeOn:
					start()
				case event.ChangeOff:
					stop()
				}
			case event.Config:
				//config(e, c)
				c = e
			case event.Draw:
				draw(c)
				a.EndDraw()
			case event.Touch:
				touch(e, c)
			}
		}
	})
}
예제 #6
0
파일: main.go 프로젝트: SpruceHealth/mobile
func main() {
	app.Main(func(a app.App) {
		var c config.Event
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case lifecycle.Event:
				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
			}
		}
	})
}