Cross-platform library for simple dialogues

In my game, I want to display dialogues for exceptions, and I don't really want to use something heavy like Qt, but then I also don't want to write and maintain my own platform-specific code to do it. Is there any library that can display simple message dialogues, just a few lines of text and an OK button, without being complete overkill like a full-blown GUI library?
I'm not aware of any. Best fit for this that I can think of (if you don't mind the ugly) is FLTK... which is a full GUI lib, but it's significantly smaller than Qt/wx.

Also... did I mention it's ugly? It's really ugly.


EDIT:

Or write your own? A simple messagebox style function would probably be pretty easy to accomplish on most platforms. Doing this would just take a bit of research, maybe ~30 lines of code, and a few tests.

EDIT2:

Doh you already said you didn't want to do that. Nevermind.
Last edited on
I'll probably have to roll my own, and I don't mind doing so, but I'm hoping someone knows of a simple library specifically for that purpose. If I don't find one, I'll make my own library for that specific purpose. That way it will help others.
Wait... what are you using to make the game? Just use the existing facilities to make a dialog.

Because, a modal dialogue is essentially just a procedure that displays a "window" and has its own event loop.

A non-modal dialogue is just like any other sprite.

Hope this helps.
I'm using SFML but I want the dialogue to display exception messages which could be caused by SFML itself failing, so it wouldn't be possible to use SFML.
I'm using SFML but I
want the dialogue to
display exception
messages which could
be caused by SFML itself
failing, so it wouldn't be
possible to use SFML

Why not ?
So an exception is raised by one object , that doesn't necessarily make the whole SFML useless (or does it ?) .
What you can do is just create a new small (render)window and draw the text and a rectangle shape with "OK".
EDIT:
I realised SFML doesn't have a default font anymore in 2.x. ,so you can't actually use it
Could it be something like this?
Edit: I'm really not sure about the xm stuff.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifdef WIN32
#include <windows.h>
#else ifdef QT
#include <QMessageBox>
#else
#include <Xm/Xm.h>
#include <Xm/PushB.h>
#endif


void SimpleDialog(std::string message, std::string caption)
{

#ifdef WIN32
    MessageBox(NULL, message.c_str(), caption.c_str(), MB_OK);
#else ifdef QT
    QMessageBox mb(QMessageBox::Question, caption.c_str(), message.c_str(), QMessageBox::OK);
    mb.exec();
#else
    XtAppContext app;

    Widget top_wid = XtVaAppInitialize(&app, message.c_str(), NULL, 0, 0 NULL, NULL, NULL);

    Widget button = XmCreatePushButton(top_wid, "OK", NULL, 0);

    XtManageChild(button);

    XtRealizeWidget(top_wid);
#endif

}
Last edited on
@ Stewbond:

Of course... if you're using std::string... you mean to call MessageBoxA, right? ;P
@Stewbond: I have never seen this "#else ifdef MACRO" syntax before, could you explain it?
Maybe he meant #elif defined( MACRO ) ?
@a k n
If something goes wrong with SFML, then I can't rely on it to display exception messages. You can almost always rely on the operating system, however.

@Stewbond
Something like that ought to work. Do you mind if I use your X11 code?

The problem is with the preprocessor stuff. I wanted to avoid that by using a library that would hide it all away for me.

[edit] Do you think I could just use QMessageBox without having to link the entire Qt library?
Last edited on
By statically linking, I believe you only bring in what you use. So if the Qt library is 4MB, you're not going to expand your executable by 4MB.
Stoopid internet keeps cutting out...

There is a design flaw in your program if you are expecting SFML to fail.

If SFML cannot be loaded and initialized, your application should fail to start with the normal system dialog (Windows/Mac) or stderr complaint (nix).

Otherwise, the only time the user should see anything is if you cannot load resources or some other critical error happens -- and you still have full use of SFML's capabilities.

I usually keep an error "screen" for such things, so that if anything fatal happens the user will get a simple error message and an apology, complete with a small error code that I can use to track down the problem in the source.

If you plan to handle the traffic, you can even add a button so the user can automatically email yourself with more specific error information.

Do you think I could just use QMessageBox without having to link the entire Qt library?

Qt is already very smart about what it links in. But I doubt you would just be able to link in QMessageBox without a significant penalty.

If you really want to do it this way, it really isn't hard to make a simple window in X11. It'd take you all of maybe ten lines of code. Same thing in Windows. You just need to adjust your build process to link in the proper compilation unit depending on your platform.

Good luck!
Duoas wrote:
Otherwise, the only time the user should see anything is if you cannot load resources or some other critical error happens -- and you still have full use of SFML's capabilities.

You're right, thanks. I'll make an in-game "error state" that gets set if something messes up. It was mostly resource load errors that I was looking to report.
Topic archived. No new replies allowed.