What kind of GUI's are there for SDL?

There are several GUI libraries written for SDL available from the SDL libraries page at http://www.libsdl.org/libraries.php .

This thread (1) mentions Guichan (C++) and Agar (C).

How to integrate SDL into an existing GUI application?

Sometimes, for exemple in the case of a game editor, it may be useful to use a windowed SDL for the graphics and a general-purpose GUI toolkit for the user interface.

There is no perfect solution for this, but there exists various ways to work around this.

Manually copy from non-window SDL_Surface to the GUI toolkit

You manipulate a SDL_Surface as usual, but you manually copy it as a pixel array to your tookit widget. This is the only technique that allow you to use SDL in several windows.

There is a nice demo for wxWidgets at http://code.technoplaza.net/wx-sdl/part1/ . The demo has some limitations:

The mouse or keyboard events are caught by the GUI toolkit only, not by SDL.

Use MDI instead of SDI

That is, Multiple Document Interface instead of Single Document Interface (think Gimp vs. Photoshop).

You initialize SDL as usual, and call your favorite toolkit to create toolbars around the main SDL window.

See the double loop section for examples and limitations.

The SDL_WINDOWID hack

This makes SDL use an existing window instead of creating a new one. This works under X11 and Win32. Basically you putenv("SDL_WINDOWID=XXX") where XXX is an existing window's ID. You can only use it on one existing window (not several).

Code can be found for various toolkits:

You do not receive the usual SDL events for this solution.

Gtk socket

Using Gtk socket is mentioned in the SDL_WINDOWID section, because you can put SDL in a socket by passing the socket id to SDL_WINDOWID.

The other way around, does not involved SDL_WINDOWID, somewhat works too: passing the SDL window ID (pygame.display.get_wm_info().get("window")) to a Gtk socket (socket.add_id()). Since you "steal" SDL out of an existing window, you get a now-empty original SDL window lying around.

1 implies input can work with the Gtk socket technique. According to my tests, the window events are handled by the original empty window, and the mouse / keyboard events by the stolen graphics display in the socket window.

Double event loop issue

When combining SDL and a GUI, and where your technique supports SDL events, there will be two event loops. Both need to run at the same time!

Work-arounds:

You'll need to read the events if you want SDL to refresh the window when it's repainted (hidden behind another window, etc.).

putenv or SDL_putenv?

Apparently SDL_putenv takes care of tricky situations where the environment is not the same in the application and in the library: http://lists.libsdl.org/htdig.cgi/sdl-libsdl.org/2005-September/051604.html

Not tested though.

FAQ_GUI (last edited 2008-04-17 08:18:53 by localhost)