shithub: dormer

ref: c40d66e369235ec021af570553b89bd101a42109
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);
}