Pete Shinners wrote:
i am thinking it would be nice for some sort of
cross platform error messagebox type functionality.
I’ve been down this road too, and I agree that it’s really nice to have
a simple messagebox function available.
However, after thinking about it for I while, I decided that I’d rather
not have it as part of SDL:
It’s easy to implement for win32 using MessageBox(), and I’d guess that
MacOS and Beos have similar calls available, but under unix-style
systems it gets a bit muddier.
Here are some options (assuming X windows and ignoring SVGAlib, AALib
and other display targets):
Output to stdout - useful and unixy, but a little un-userfriendly.
The user will be focused on your app window, not the terminal window.
The app will just appear to freeze up and it might take a while before
the message on stdout is spotted.
Implement a messagebox using a widget set like GTK+ or QT. Will look
nice, pop up in a way that draws the users attention and will probably
respect the look and feel the user has chosen for their desktop. The
downside is that it’d tie SDL in to that particular widget library,
which I think is probably unacceptable.
Implement a messagebox using vanilla X calls. Doesn’t tie SDL to
anything extra, but will probably look like crap and not observe
user-selected look and feel.
Implement a messagebox entirely within SDL, using the existing SDL
window. Nicely cross-platform, works in fullscreen mode, but hard to
implement in a way that will keep all apps happy (eg what if the app
doesn’t open a display?). Also, looks very different to messageboxes
popped up by other apps - eg under windows, most errors appear in the
same way - ie a small window in the middle of your screen demanding your
None of these options will suit all programs. Depends on the type of
app, target audience etc etc…
I think you’re probably best to just write your own function eg:
void ShowMessage( const char* title, const char* message )
#if defined( WIN32 )
MessageBox( message, title, MB_OK );
#elif defined( BEOS )
BFunkyModalMessageBox dlg( title, message ); // I’m making this up!
#elif defined( MACOS )
ShowMessageThing( title,message ); // I’m making this up too!
#elif defined( X11_AND_GTK )
ShowMyHomemadeGtkDlg( title, message );
printf( “%s: %s\n”, title, message ); // fallback for all other
For the (commercial) game I’m hacking about on, I had the following
requirements for messageboxes:
- must work on win32 and X11+Linux (x86).
- must be user friendly and fit in with desktop appearances.
The win32 version was already using MessageBox(), and for the Linux port
I just rolled my own Gtk+ messagebox.
If the game is running in fullscreen mode, it pops itself out into
windowed mode before invoking the messagebox.
Ben Campbell (Antipodean Straggler)
Programmer, Creature Labs
ben.campbell at creaturelabs.com