1 /*
2     GUILIB:  An example GUI framework library for use with SDL
3 */
4 
5 /* This file provides a simple C interface to the C++ GUI classes */
6 
7 #include "GUI.h"
8 #include "GUI_generic.h"
9 
10 extern "C" {
11 
12 /* Create a GUI */
GUI_Create(SDL_Surface * screen)13 CGUI *GUI_Create(SDL_Surface *screen)
14 {
15 	return((CGUI *)new GUI(screen));
16 }
17 
18 /* Create a generic widget */
GUI_Widget_Create(void * data,int x,int y,int w,int h,GUI_DrawProc drawproc,GUI_EventProc eventproc,GUI_FreeProc freeproc)19 CGUI_Widget *GUI_Widget_Create(void *data, int x, int y, int w, int h,
20 	GUI_DrawProc drawproc, GUI_EventProc eventproc, GUI_FreeProc freeproc)
21 {
22 	GUI_Widget *widget;
23 
24 	widget = new GUI_GenericWidget(data, drawproc, eventproc, freeproc);
25 	widget->SetRect(x, y, w, h);
26 	return((CGUI_Widget *)widget);
27 }
28 
29 /* Add a widget to a GUI */
GUI_AddWidget(CGUI * gui,CGUI_Widget * widget)30 int GUI_AddWidget(CGUI *gui, CGUI_Widget *widget)
31 {
32 	return(((GUI *)gui)->AddWidget((GUI_Widget *)widget));
33 }
34 
35 /* Move or resize a widget
36    If any of the parameters are -1, that parameter is not changed.
37  */
GUI_MoveWidget(CGUI_Widget * widget,int x,int y,int w,int h)38 void GUI_MoveWidget(CGUI_Widget *widget, int x, int y, int w, int h)
39 {
40 	((GUI_Widget *)widget)->SetRect(x, y, w, h);
41 	((GUI_Widget *)widget)->Display();
42 }
43 
44 /* Run a GUI until the widgets request a quit */
GUI_Run(CGUI * gui,GUI_IdleProc idle)45 void GUI_Run(CGUI *gui, GUI_IdleProc idle)
46 {
47 	((GUI *)gui)->Run(idle);
48 }
49 
50 /* Delete a previously created GUI */
GUI_Destroy(CGUI * gui)51 void GUI_Destroy(CGUI *gui)
52 {
53 	delete (GUI *)gui;
54 }
55 
56 /* End of extern C declaration */
57 };
58