Exemple #1
0
func (m *Module) Display(display Display, sz size.Event, glctx gl.Context, images *glutil.Images) {
	im := images.NewImage(sz.WidthPx, sz.HeightPx)

	switch {
	case m.err != nil:
		// There was an error of some kind. We should display the error indication until the error
		// is removed from the module by a timeout.
		m.renderInformation(im.RGBA, sz.Size(), errorBackground, "T_T", "T_T")
	case !display.Loaded:
		// We haven't loaded any predictions yet. Dislay the loading screen.
		loadingStr := "Loading" + strings.Repeat(".", int(time.Now().Unix()%4))
		m.renderInformation(im.RGBA, sz.Size(), loadingBackground, loadingStr, "Loading...")
	case !display.NextOK:
		// We don't have a prediction for the next train. This is probably because there are no
		// trains coming for a while (ex., after nightly shutdown).
		m.renderInformation(im.RGBA, sz.Size(), loadingBackground, "No trains :(", "No trains :(")
	default:
		// If everything else is ok, then we have at least 1 prediction. Display it.
		m.render(im.RGBA, display, sz.Size())
	}

	if display.TransitRouteName != "" {
		m.renderTransitRouteName(im.RGBA, sz.Size(), display.TransitRouteName)
	}

	im.Upload()
	im.Draw(
		sz,
		geom.Point{},
		geom.Point{X: sz.WidthPt},
		geom.Point{Y: sz.HeightPt},
		sz.Bounds())
	im.Release()
}
Exemple #2
0
// main is the entry point of the application. This is function gets registered
// as the main function of the application.
func (m *Module) main(a app.App) {
	var images *glutil.Images
	var glctx gl.Context
	sz := size.Event{}

	m.Render.InitApp(a)

	ticker := time.NewTicker(time.Second)

	for {
		select {
		case <-ticker.C:
			a.Send(paint.Event{})

		case <-m.Network.Updated():
			m.loaded = true

		case e := <-a.Events():
			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				glctx, _ = e.DrawContext.(gl.Context)
				if glctx != nil {
					glctx = e.DrawContext.(gl.Context)
					if images != nil {
						images.Release()
					}
					images = glutil.NewImages(glctx)
				}
			case size.Event:
				sz = e
			case paint.Event:
				m.draw(glctx, sz, images)
				a.Publish()
			}
		}
	}
}