summaryrefslogtreecommitdiff
path: root/dumb/dumb-kode54/studio/src/dumbgui.c
blob: 4927a09c24f884ef7174613a53314739ed9f09b1 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdlib.h>

#include "dumbgui.h"



GUI *gui_active;



void gui_set_active(GUI *gui)
{
	gui_changed_active(gui_active);
	gui_active = gui;
	gui_changed_active(gui_active);
}



GUI *gui_create(GUI_COMMANDS *com, GUI *parent, int x, int y, int w, int h, void *param)
{
	GUI *gui = malloc(sizeof(*gui));

	if (!gui)
		return NULL;

	gui->com = com;

	gui->parent = parent;

	gui->x = x;
	gui->y = y;
	gui->w = w;
	gui->h = h;

	gui->flags = 0;

	if (com->create) {
		(*com->create)(gui, param);

		if (!gui->data) {
			free(gui);
			return NULL;
		}
	} else
		gui->data = NULL;

	gui_changed_all(gui);

	return gui;
}



void gui_destroy(GUI *gui)
{
	if (gui) {
		if (gui->com->destroy)
			(*gui->com->destroy)(gui);

		free(gui);
	}
}



void gui_key(GUI *gui, int k)
{
	if (gui && gui->com->key)
		(*gui->com->key)(gui, k);
}



void gui_update(GUI *gui)
{
	if (gui && gui->com->update)
		(*gui->com->update)(gui);
}



void gui_draw(GUI *gui)
{
	if (gui && gui->com->draw)
		(*gui->com->draw)(gui);
}



/* For use with subclip(). */
void gui_draw_void(void *gui)
{
	gui_draw(gui);
}



void gui_drawn(GUI *gui)
{
	if (gui && gui->com->drawn)
		(*gui->com->drawn)(gui);
}



void gui_changed_all(GUI *gui)
{
	if (gui && gui->com->changed_all)
		(*gui->com->changed_all)(gui);
}



void gui_changed_active(GUI *gui)
{
	if (gui && gui->com->changed_active)
		(*gui->com->changed_active)(gui);
}