Exemple #1
0
func NewSDLRenderer(surface *sdl.Surface, font *ttf.Font) *SDLRenderer {
	renderer := &SDLRenderer{
		Color:          sdl.Color{255, 255, 255, 0},
		visibleSurface: surface,
		Font:           font,
		eventCh:        make(chan interface{}),
		updatedRectsCh: make(chan []sdl.Rect),
		updatedRects:   make([]sdl.Rect, 0),
		width:          uint(surface.W),
		height:         uint(surface.H),
	}

	fontWidth, fontHeight, err := font.SizeText("A")
	if err != 0 {
		panic("failed to determine font dimensions: " + sdl.GetError())
	}

	renderer.fontWidth = uint(fontWidth)
	renderer.fontHeight = uint(fontHeight)

	renderer.lastVisibleLine = (renderer.height / renderer.fontHeight) * MAX_INTERNAL_SIZE_FACTOR

	renderer.internalSurfaceHeight = uint(renderer.fontHeight)
	renderer.internalSurfaceMaxHeight = renderer.height * MAX_INTERNAL_SIZE_FACTOR
	renderer.internalSurface = sdl.CreateRGBSurface(sdl.SWSURFACE,
		int(renderer.width), int(renderer.internalSurfaceHeight), 32, 0, 0, 0, 0)

	renderer.calcCommandLineRect()

	renderer.updatedRects = append(renderer.updatedRects, sdl.Rect{0, 0, uint16(renderer.width), uint16(renderer.height)})

	go renderer.loop()

	return renderer
}
func initSDL() {
	if sdl.Init(sdl.INIT_VIDEO) != 0 {
		panic(sdl.GetError())
	}

	if ttf.Init() != 0 {
		panic(sdl.GetError())
	}

	font := ttf.OpenFont("testdata/VeraMono.ttf", 20)

	if font == nil {
		panic(sdl.GetError())
	}

	appSurface = sdl.SetVideoMode(640, 480, 32, 0)
	sdlrenderer = NewSDLRenderer(sdl.CreateRGBSurface(sdl.SRCALPHA, 640, 480, 32, 0, 0, 0, 0), font)
	sdlrenderer.GetSurface().SetAlpha(sdl.SRCALPHA, 0xaa)
	console = NewConsole(nil)

	go func() {
		for {
			select {
			case rects := <-sdlrenderer.UpdatedRectsCh():
				render(rects)
			}

		}
	}()

	render(nil)
}
Exemple #3
0
func newSDLSurface(app *spectrum.Application, w, h int) *SDLSurface {
	surface := sdl.CreateRGBSurface(sdl.SWSURFACE, w, h, 32, 0, 0, 0, 0)
	if surface == nil {
		app.PrintfMsg("%s", sdl.GetError())
		app.RequestExit()
		return nil
	}
	return &SDLSurface{surface}
}
Exemple #4
0
func newCLISurface(scale2x, fullscreen bool) *clingon.SDLRenderer {
	cliSurface := clingon.NewSDLRenderer(
		sdl.CreateRGBSurface(
			sdl.SRCALPHA,
			width(scale2x, fullscreen),
			height(scale2x, fullscreen)/2, 32, 0, 0, 0, 0),
		newFont(scale2x, fullscreen),
	)
	cliSurface.GetSurface().SetAlpha(sdl.SRCALPHA, 0xdd)
	return cliSurface
}
Exemple #5
0
func (renderer *SDLRenderer) resizeInternalSurface(console *Console) {
	h := uint(len(console.lines)+1) * renderer.fontHeight
	if h > renderer.internalSurfaceMaxHeight {
		h = renderer.internalSurfaceMaxHeight
	}

	if renderer.internalSurfaceHeight != h {
		renderer.internalSurface.Free()

		renderer.internalSurface = sdl.CreateRGBSurface(sdl.SWSURFACE, int(renderer.width), int(h), 32, 0, 0, 0, 0)
		renderer.calcCommandLineRect()
		renderer.cursorY = int(renderer.commandLineRect.Y)
		renderer.viewportY = int(renderer.internalSurface.H - renderer.visibleSurface.H)
		renderer.internalSurfaceHeight = h
		renderer.internalSurface.SetClipRect(&sdl.Rect{0, 0, uint16(renderer.width), uint16(h)})
	}
}