aboutsummaryrefslogtreecommitdiff
path: root/canvas.c
blob: abd00898d7823b9706879a5b169eabaac05ebf19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <geometry.h>
#include "dat.h"
#include "fns.h"

static int
alphachan(ulong chan)
{
	for(; chan; chan >>= 8)
		if(TYPE(chan) == CAlpha)
			return 1;
	return 0;
}

Canvas*
newcanvas(Point2 p, Rectangle r, ulong chan)
{
	Canvas *c;

	c = emalloc(sizeof(Canvas));
	c->p = p;
	c->bx = Vec2(1,0);
	c->by = Vec2(0,1);
	c->image = eallocimage(display, r, chan, 0, alphachan(chan)? DTransparent: DNofill);
	memset(&c->layers, 0, sizeof(Layer));
	c->layers.next = &c->layers;
	c->layers.prev = &c->layers;
	return c;
}