-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonlist.h
64 lines (52 loc) · 1.22 KB
/
buttonlist.h
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
/* A simple menu button class -- only handles mouse input */
#include "SDL_types.h"
class ButtonList {
public:
ButtonList() {
button_list.next = NULL;
}
~ButtonList() {
Delete_Buttons();
}
void Add_Button(Uint16 x, Uint16 y, Uint16 width, Uint16 height,
void (*callback)(void)) {
struct button *belem;
for ( belem=&button_list; belem->next; belem=belem->next );
belem->next = new button;
belem = belem->next;
belem->x1 = x;
belem->y1 = y;
belem->x2 = x+width;
belem->y2 = y+height;
belem->callback = callback;
belem->next = NULL;
}
void Activate_Button(Uint16 x, Uint16 y) {
struct button *belem;
for ( belem=button_list.next; belem; belem=belem->next ) {
if ( (x >= belem->x1) && (x <= belem->x2) &&
(y >= belem->y1) && (y <= belem->y2) ) {
if ( belem->callback )
(*belem->callback)();
}
}
}
void Delete_Buttons(void) {
struct button *belem, *btemp;
for ( belem=button_list.next; belem; ) {
btemp = belem;
belem = belem->next;
delete btemp;
};
button_list.next = NULL;
}
private:
typedef struct button {
/* Sensitive area */
Uint16 x1, y1;
Uint16 x2, y2;
void (*callback)(void);
struct button *next;
} button;
button button_list;
};