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 #ifndef _GUI_C_h 8 #define _GUI_C_h 9 10 #include "SDL.h" 11 #include "GUI_status.h" 12 13 #include "begin_code.h" 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /* Definitions for the C versions of the GUI and widget objects */ 19 struct CGUI; 20 typedef struct CGUI CGUI; 21 22 struct CGUI_Widget; 23 typedef struct CGUI_Widget CGUI_Widget; 24 25 typedef struct widget_info { 26 /* A generic pointer to user-specified data for the widget. 27 */ 28 void *widget_data; 29 30 /* The display surface for the widget */ 31 SDL_Surface *screen; 32 33 /* The area covered by the widget */ 34 SDL_Rect area; 35 36 } widget_info; 37 38 /* Generic widget callback functions (used by C interface) */ 39 typedef void (*GUI_DrawProc)(widget_info *info); 40 typedef GUI_status (*GUI_EventProc)(widget_info *info, const SDL_Event *event); 41 typedef void (*GUI_FreeProc)(widget_info *info); 42 43 44 /* Create a GUI */ 45 extern CGUI *GUI_Create(SDL_Surface *screen); 46 47 /* Create a generic widget */ 48 extern CGUI_Widget *GUI_Widget_Create(void *data, int x, int y, int w, int h, 49 GUI_DrawProc drawproc, GUI_EventProc eventproc, GUI_FreeProc freeproc); 50 51 /* Add a widget to a GUI. 52 Once the widget has been added, it doesn't need to be freed. 53 This function returns 0, or -1 if it ran out of memory. 54 */ 55 extern int GUI_AddWidget(CGUI *gui, CGUI_Widget *widget); 56 57 /* Move or resize a widget 58 If any of the parameters are -1, that parameter is not changed. 59 */ 60 extern void GUI_MoveWidget(CGUI_Widget *widget, int x, int y, int w, int h); 61 62 /* Run a GUI until the widgets or idleproc request a quit */ 63 extern void GUI_Run(CGUI *gui, GUI_IdleProc idle); 64 65 /* Delete a previously created GUI */ 66 extern void GUI_Destroy(CGUI *gui); 67 68 #ifdef __cplusplus 69 }; 70 #endif 71 #include "close_code.h" 72 73 #endif /* _GUI_C_h */ 74