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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <geometry.h>
#include "dat.h"
#include "fns.h"
Canvas*
newcanvas(char *name, 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->name = strdup(name);
c->image = eallocimage(display, r, chan, 0, alphachan(chan)? DTransparent: DWhite);
memset(&c->layers, 0, sizeof(Layer));
c->layers.next = &c->layers;
c->layers.prev = &c->layers;
c->curlayer = nil;
return c;
}
void
rmcanvas(Canvas *c)
{
Layer *l;
for(l = c->layers.next; l != &c->layers; l = l->next)
rmlayer(l);
freeimage(c->image);
free(c->name);
free(c);
}
Layer*
addlayer(Canvas *c, char *name)
{
Layer *l;
l = newlayer(name, c->image->r, RGBA32);
l->prev = c->layers.prev;
l->next = &c->layers;
c->layers.prev->next = l;
c->layers.prev = l;
if(c->curlayer == nil)
c->curlayer = l;
return l;
}
Layer*
getlayer(Canvas *c, char *name)
{
Layer *l;
for(l = c->layers.next; l != &c->layers; l = l->next)
if(strcmp(l->name, name) == 0)
return l;
return nil;
}
|