File: buttonlist.h

package info (click to toggle)
maelstrom 1.4.3-L3.0.6%2Bmain-9
  • links: PTS
  • area: main
  • in suites: bullseye, buster
  • size: 4,356 kB
  • sloc: cpp: 10,822; ansic: 2,779; sh: 2,680; makefile: 196
file content (64 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (9)
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)) {
		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) {
		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) {
		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;
};