shithub: dormer

ref: c293a78c65a8bcadefae4e1f180286f87c69c930
dir: /canvas.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include "dormer.h"

Canvas*
canvas(int sn, int tn, long bgcol)
{
	int size;
	size = sizeof(Canvas) 	
		+ sizeof(Sprite) * sn
		+ sizeof(Text) * tn;
	Canvas *c = malloc(size);
	c->si = 0;
	c->ti = 0;
	c->spritev = (Sprite*)(c+1);
	c->textv = (Text*)(c->spritev+sn);
	c->bg = allocimagemix(display, bgcol, bgcol);

	vs.canvas = c;
	return c;
}

void
present(void)
{
	if(getwindow(display, Refmesg) < 0)
		fprint(2, "can't reattach to window");
	draw(screen, screen->r, vs.canvas->bg, 0, ZP);

	int i;
	for(i=0;i<vs.canvas->si;++i){
		Point p = {vs.canvas->spritev[i].x, vs.canvas->spritev[i].y};
		draw(screen, rectaddpt(screen->r, p), vs.canvas->spritev[i].image, 0, ZP);
	}
	for(i=0;i<vs.canvas->ti;++i){
		Point p = {vs.canvas->textv[i].x, vs.canvas->textv[i].y};
		draw(screen, rectaddpt(screen->r, p), vs.canvas->textv[i].image, 0, ZP);
	}

	flushimage(display, 1);
}