示例#1
0
func render(sdlrenderer *clingon.SDLRenderer, updatedRects []sdl.Rect, y int16) {
	if updatedRects == nil {
		appSurface.Blit(nil, gopher, nil)
		appSurface.Blit(&sdl.Rect{consoleX, y, 0, 0}, sdlrenderer.GetSurface(), nil)
		appSurface.Flip()
	} else {
		for _, r := range updatedRects {
			appSurface.Blit(&sdl.Rect{r.X + consoleX, r.Y + consoleY, 0, 0}, gopher, &sdl.Rect{r.X + consoleX, r.Y + consoleY, r.W, r.H})
			appSurface.Blit(&sdl.Rect{consoleX, consoleY, 0, 0}, sdlrenderer.GetSurface(), &sdl.Rect{0, 0, consoleW, consoleH})
			appSurface.UpdateRect(int32(r.X+consoleX), int32(r.Y+consoleY), uint32(r.W), uint32(r.H))
		}
	}
}
示例#2
0
func newRenderingLoop(sdlrenderer *clingon.SDLRenderer) {
	go func() {
		var y int16
		breakLoop := make(chan byte)

		var animationValueCh <-chan float64 = nil
		var animationDirection int

	loop:
		for {
			select {
			case <-terminateRendering:
				go func() {
					done := make(chan bool)
					sdlrenderer.EventCh() <- clingon.Cmd_Terminate{done}
					<-done

					breakLoop <- 0
				}()

			case <-breakLoop:
				renderingLoopTerminated <- 0
				break loop

			case animationSpec := <-animationCh:
				animationValueCh = animationSpec.animation.ValueCh()
				animationDirection = animationSpec.direction

			case value := <-animationValueCh:
				if animationDirection == clingon.SCROLL_DOWN {
					y = 40 + int16(value)
				} else {
					y = appSurfaceH - int16(value)
				}
				render(sdlrenderer, nil, y)

			case rects := <-sdlrenderer.UpdatedRectsCh():
				render(sdlrenderer, rects, y)
			}
		}
	}()
}