aboutsummaryrefslogtreecommitdiff
path: root/layer.h
blob: 1bbe7e6143746e79f8c97c9e18e37e76c166f422 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef __HAVE_LAYER_H
#define __HAVE_LAYER_H

#include <string.h>
#include <bsd/sys/queue.h>

#include <SDL.h>
#include <SDL_thread.h>

class Layer {
	SDL_mutex *mutex;

public:
	SLIST_ENTRY(Layer) layers;

	char *name;

	Layer(const char *name)
	{
		mutex = SDL_CreateMutex();
		Layer::name = strdup(name);
	}
	~Layer()
	{
		free(name);
		SDL_DestroyMutex(mutex);
	}

	inline void
	lock()
	{
		SDL_LockMutex(mutex);
	}
	inline void
	unlock()
	{
		SDL_UnlockMutex(mutex);
	}

	virtual void geo(SDL_Rect geo) = 0;
	virtual void alpha(float opacity) = 0;

	virtual void frame(SDL_Surface *target) = 0;
};

class LayerList {
	SLIST_HEAD(layers_head, Layer) head;

	SDL_mutex *mutex;

	inline void
	lock()
	{
		SDL_LockMutex(mutex);
	}
	inline void
	unlock()
	{
		SDL_UnlockMutex(mutex);
	}

public:
	LayerList()
	{
		SLIST_INIT(&head);
		mutex = SDL_CreateMutex();
	}
	~LayerList()
	{
		SDL_DestroyMutex(mutex);
	}

	void insert(int pos, Layer *layer);
	bool delete_by_name(const char *name);
	void render(SDL_Surface *target);
};

#endif