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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <bsd/sys/queue.h>
#include <SDL.h>
#include "osc_graphics.h"
#include "osc_server.h"
#include "layer.h"
Layer::Layer(const char *_name) : mutex(SDL_CreateMutex()), name(strdup(_name))
{
geo_osc_id = register_method("geo", GEO_TYPES, geo_osc);
alpha_osc_id = register_method("alpha", "f", alpha_osc);
}
void
LayerList::insert(int pos, Layer *layer)
{
Layer *cur, *prev = NULL;
lock();
LIST_FOREACH(cur, &head, layers) {
if (!pos--)
break;
prev = cur;
}
if (prev)
LIST_INSERT_AFTER(prev, layer, layers);
else
LIST_INSERT_HEAD(&head, layer, layers);
unlock();
}
void
LayerList::delete_layer(Layer *layer)
{
lock();
LIST_REMOVE(layer, layers);
unlock();
/* layer is guaranteed not to be rendered */
delete layer;
}
void
LayerList::render(SDL_Surface *target)
{
SDL_FillRect(target, NULL, SDL_MapRGB(target->format, 0, 0, 0));
lock();
Layer *cur;
LIST_FOREACH(cur, &head, layers) {
cur->lock();
cur->frame(target);
cur->unlock();
}
unlock();
}
Layer::~Layer()
{
unregister_method(alpha_osc_id);
unregister_method(geo_osc_id);
free(name);
SDL_DestroyMutex(mutex);
}
|