Integrating SDL with the Glib Mainloop

Name

Integrating SDL with the Glib Mainloop -- These functions provide a structure by which the Glib mainloop will automatically poll SDL for events.

Synopsis




int         hex_sdl_init                    (Uint32 flags,
                                             GMainContext *context_in);
void        hex_sdl_run                     ();
void        hex_sdl_quit                    ();

struct      HexPollSDL;
gboolean    (*HexPollSDLSourceFunc)         (SDL_Event *event,
                                             gpointer data);
HexPollSDL* hex_poll_sdl_add                (Uint32 event_mask,
                                             HexPollSDLSourceFunc callback,
                                             gpointer data,
                                             GDestroyNotify notify);
HexPollSDL* hex_poll_sdl_add_object         (Uint32 event_mask,
                                             HexPollSDLSourceFunc callback,
                                             GObject *data);
void        hex_poll_sdl_remove             (HexPollSDL *poll);

Description

These functions are a convienience for people writing programs from scratch. If you already have your own mainloop, you can provide equivalent functionality by: 1) Creating a Glib mainloop and polling it regularly. This will update the various timeouts used by the library. 2) Pass events which match HEX_DISPLAY_SDL_EVENT_MASK through hex_display_sdl_handle_event(). 3) Handle SDL_QUIT. The functions in this section do all of the above, and also provide a mechanism for you to add additional event handlers.

Details

hex_sdl_init ()

int         hex_sdl_init                    (Uint32 flags,
                                             GMainContext *context_in);

Initialize SDL, and set up the Glib mainloop to poll for SDL events

flags :

flags to be passed to SDL_Init()

context_in :

the GMainContext to run in, or NULL for the default context

Returns :

0 on success, -1 on failure


hex_sdl_run ()

void        hex_sdl_run                     ();

Run the mainloop set up in hex_sdl_init().


hex_sdl_quit ()

void        hex_sdl_quit                    ();

Shut down the Glib mainloop and SDL. This function is called by the default handler for SDL_QUIT.


struct HexPollSDL

struct HexPollSDL;

An event handler for SDL events


HexPollSDLSourceFunc ()

gboolean    (*HexPollSDLSourceFunc)         (SDL_Event *event,
                                             gpointer data);

A callback function for an SDL_Event handler. It is called after HexDisplaySDL has had a chance to handle mouse events, but before the default handler for SDL_QUIT.

event :

an SDL_Event

data :

the callback user data

Returns :

TRUE if the event should no longer be propagated


hex_poll_sdl_add ()

HexPollSDL* hex_poll_sdl_add                (Uint32 event_mask,
                                             HexPollSDLSourceFunc callback,
                                             gpointer data,
                                             GDestroyNotify notify);

Add an event handler for SDL events.

event_mask :

which SDL events to poll for

callback :

the poll callback function

data :

the user data to pass to the callback function

notify :

the function to call to free the user data when the poll is removed

Returns :

the newly created HexPollSDL


hex_poll_sdl_add_object ()

HexPollSDL* hex_poll_sdl_add_object         (Uint32 event_mask,
                                             HexPollSDLSourceFunc callback,
                                             GObject *data);

Add an event handler for SDL events.

event_mask :

which SDL events to poll for

callback :

the poll callback function

data :

a Gobject to pass as user data to the callback function

Returns :

the newly created HexPollSDL


hex_poll_sdl_remove ()

void        hex_poll_sdl_remove             (HexPollSDL *poll);

Remove an event handler for SDL events.

poll :

the event handler to remove