aboutsummaryrefslogtreecommitdiff
path: root/layer.cpp
blob: d0516abf6303eb7d1b049bbfae5c2f7beae384e8 (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
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
#include <string.h>
#include <bsd/sys/queue.h>

#include <SDL.h>

#include "osc_graphics.h"
#include "layer.h"

void
LayerList::insert(int pos, Layer *layer)
{
	Layer *cur, **prev;

	lock();

	SLIST_FOREACH_PREVPTR(cur, prev, &head, layers)
		if (!pos--)
			break;

	SLIST_NEXT(layer, layers) = cur;
	*prev = layer;

	unlock();
}

bool
LayerList::delete_by_name(const char *name)
{
	Layer *cur, **prev;

	lock();

	SLIST_FOREACH_PREVPTR(cur, prev, &head, layers)
		if (!strcmp(cur->name, name)) {
			*prev = SLIST_NEXT(cur, layers);
			delete cur;
			break;
		}

	unlock();

	return cur == NULL;
}

void
LayerList::render(SDL_Surface *target)
{
	SDL_FillRect(target, NULL, SDL_MapRGB(target->format, 0, 0, 0));

	lock();

	Layer *cur;
	SLIST_FOREACH(cur, &head, layers) {
		cur->lock();
		cur->frame(target);
		cur->unlock();
	}

	unlock();
}