ref: 4ae4cb2ec7d3fecf526b29d98eeb55d374a99dda
dir: /canvas.c/
#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; } static void tilesprite(Sprite *s) { Image *im = s->image; int x = im->r.max.x / s->tnum; int y = im->r.max.y; int n = s->tile; replclipr(im, 1, Rect((n-1)*x,0,n*x,y)); } 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){ tilesprite(&vs.canvas->spritev[i]); Point p = {vs.canvas->spritev[i].x, vs.canvas->spritev[i].y}; Rectangle r = Rect(0,0,800,600); /* This is to be fixed. */ r = rectaddpt(r, screen->r.min); draw(screen, rectaddpt(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); }