1 /*
2     GUILIB:  An example GUI framework library for use with SDL
3 */
4 
5 /* This is a C++ class for handling a GUI, and associated widgets */
6 
7 #ifndef _GUI_h
8 #define _GUI_h
9 
10 #include "SDL.h"
11 #include "GUI_status.h"
12 #include "GUI_widget.h"
13 
14 
15 class GUI {
16 
17 public:
18 	GUI(SDL_Surface *display);
19 	~GUI();
20 
21 	/* Add a widget to the GUI.
22 	   The widget will be automatically deleted when the GUI is deleted.
23 	   This function returns 0, or -1 if the function ran out of memory.
24 	 */
25 	int AddWidget(GUI_Widget *widget);
26 
27 	/* Display the GUI manually */
28 	void Display(void);
29 
30 	/* Returns will return true if the GUI is still ready to handle
31 	   events after a call to Run(), and false if a widget or idle
32 	   function requested a quit.
33 	 */
Running(void)34 	int Running(void) {
35 		return(running);
36 	}
37 
38 	/* Run the GUI.
39 	   This returns when either a widget requests a quit, the idle
40 	   function requests a quit, or the SDL window has been closed.
41 	   If 'once' is non-zero, you need to display the GUI yourself,
42 	   and the GUI event loop will run once and then return.
43 	   If 'multitaskfriendly' is non-zero AND idle is NULL,
44 	   a 'WaitEvent' will be used instead of the CPU time
45 	   consuming 'PollEvent'. CAVE: Any widget-'idle'-procs WON'T
46 	   be executed then.
47 	 */
48 	void Run(GUI_IdleProc idle = NULL, int once = 0, int multitaskfriendly = 0);
49 
50 protected:
51 	/* The display surface */
52 	SDL_Surface *screen;
53 
54 	/* Pointers for an array of widgets */
55 	int maxwidgets;
56 	int numwidgets;
57 	GUI_Widget **widgets;
58 
59 	/* Flag - whether or not the GUI is currently running */
60 	int running;
61 
62 	/* Flag - whether or not the GUI needs to be displayed */
63 	int display;
64 
65 	/* Function to handle a GUI status */
66 	void HandleStatus(GUI_status status);
67 
68 	/* Function to pass an event to the GUI widgets */
69 	void HandleEvent(const SDL_Event *event);
70 };
71 
72 #endif /* _GUI_h */
73