Notes
All functions which create objects will return the object with the refcount at 1. All functions to which you pass objects will, if they keep a reference to the object, increment it's refcount.
Functions which only passively use an object may increment and decrement the refcount any number of times during the call to the function, but the number of increments and decrements will be equal.
GUI top-level functions
int GUI_Init(int w, int h, int d, int v);
Initialize the SDL_gui library, and create a screen of size (w) by (h), with depth (d). (v) is the video flags. You should probably at least pass in SDL_HWSURFACE.
void GUI_Run();
Run the gui. This will run the event loop.
void GUI_Quit()
Cleanup after the gui. This will destroy the screen widget.
Callback
GUI_Callback *GUI_CallbackCreate(GUI_CallbackFunction *function, GUI_CallbackFunction *freefunc, void *data);
Create a callback object. A callback is used by widgets which need to call back to the application code when some event has occurred. The application function is passed the data pointer when it is called.
When the callback is eventually freed, the "freefunc" function will be called to allow the application to free the data pointer.
void GUI_CallbackIncRef(GUI_Callback *callback);
Increment the reference count.
int GUI_CallbackDecRef(GUI_Callback *callback);
Decrement the reference count.
void GUI_CallbackCall(GUI_Callback *callback);
Font
GUI_Font *GUI_FontLoad(char *fn, int size);
This function will load a truetype font using the SDL_ttf library, and return a font object which contains it. If the font fails to load, this function will return NULL.
void GUI_FontIncRef(GUI_Font *font);
Increment the reference count.
int GUI_FontDecRef(GUI_Font *font);
Decrement the reference count.
GUI_Surface *GUI_FontRenderSolid(GUI_Font *font, const char *s, SDL_Color fg);
This will use the given font to render the given text, using the given foreground color, and return a surface with the rendered text. The application must decrement the reference count of this surface when it is finished using it. The background will be transparent.
GUI_Surface *GUI_FontRenderShaded(GUI_Font *font, const char *s, SDL_Color fg, SDL_Color bg);
This will use the given font to render the given text, using the given foreground and background colors, and return a surface with the rendered text. The application must decrement the reference count of this surface when it is finished using it.
FastFont
GUI_FastFont *GUI_FastFontLoad(char *fn);
This function will load a bitmapped font using the SDL_image library, and return a font object which contains it. If the bitmap fails to load, this function will return NULL. The font should be a single row of characters, and all 256 characters must be present (or blank). The character size is fixed, and will be the width of the font image divided by 256. This is exactly like in the SDL_console example.
void GUI_FastFontIncRef(GUI_FastFont *font);
Increment the reference count.
int GUI_FastFontDecRef(GUI_FastFont *font);
Decrement the reference count.
void GUI_FastFontDrawText(GUI_FastFont *font, GUI_Surface *surface, const char *s, int x, int y);
This function will draw on the target surface using the given font.
Surface
This object wraps a SDL_Surface, so that they can be reference counted. The internal SDL_Surface can be referenced as a field inside the object structure.
GUI_Surface *GUI_SurfaceLoad(char *fn);
This function will load a bitmap using the SDL_image library, and return a surface object to wrap it. If the load fails, this function will return NULL.
GUI_Surface *GUI_SurfaceCreate(int f, int w, int h, int d, int rm, int gm, int bm, int am);
This function will create a surface by calling SDL_AllocSurface. If SDL_AllocSurface fails, this function will return NULL.
GUI_Surface *GUI_SurfaceWrap(SDL_Surface *image);
This function will create a new surface object which wraps the given SDL_Surface pointer. If the pointer passed in is NULL, this function will return NULL.
void GUI_SurfaceIncRef(GUI_Surface *surface);
Increment the reference count.
int GUI_SurfaceDecRef(GUI_Surface *surface);
Decrement the reference count.
void GUI_SurfaceBlit(GUI_Surface *src, SDL_Rect *src_r, GUI_Surface *dst, SDL_Rect *dst_r);
This function performs a blit between two surfaces. It has the same rules as SDL_BlitSurface.
void GUI_SurfaceUpdateRect(GUI_Surface *surface, int x, int y, int w, int h);
void GUI_SurfaceFill(GUI_Surface *surface, SDL_Rect *r, Uint32 c);
int GUI_SurfaceGetWidth(GUI_Surface *surface);
int GUI_SurfaceGetHeight(GUI_Surface *surface);
Uint32 GUI_SurfaceMapRGB(GUI_Surface *surface, int r, int g, int b);
Widget
These functions work on any widget.
GUI_Widget *GUI_WidgetAlloc(GUI_WidgetType *type, const char *name, int x, int y, int w, int h);
void GUI_WidgetIncRef(GUI_Widget *widget);
Increment the reference count.
int GUI_WidgetDecRef(GUI_Widget *widget);
Decrement the reference count.
void GUI_WidgetUpdate(GUI_Widget *widget, int force);
SDL_Rect GUI_WidgetAdjust(GUI_Widget *widget, const SDL_Rect *area);
void GUI_WidgetDraw(GUI_Widget *widget, GUI_Surface *image, const SDL_Rect *sr, const SDL_Rect *dr);
void GUI_WidgetErase(GUI_Widget *widget, const SDL_Rect *dr);
int GUI_WidgetEvent(GUI_Widget *widget, const SDL_Event *event, int xoffset, int yoffset);
void GUI_WidgetKeep(GUI_Widget *parent, GUI_Widget **target, GUI_Widget *source);
void GUI_WidgetClicked(GUI_Widget *widget, int x, int y);
void GUI_WidgetSetName(GUI_Widget *widget, const char *name);
const char *GUI_WidgetGetName(GUI_Widget *widget);
Container
These functions work on any widget that is a container.