Message box function suggestion

Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.

I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);

Name was just a placeholder for the example, come up with a better one
if needed :stuck_out_tongue:

I completely understand the suggestion here, as it’s very useful for
getting your app up and running with some quick error checking, BUT it
really sits on the fence as far as if it’s something overly appropriate for
the SDL api, because it’s more of an OS/Gui function which doesn’t sit at
the same low-level that the rest of SDL tends to operate.

The typical solution to this from what I’ve seen is either having/building
an in-app gui of some sort, or write to stderr/a custom file with an error
message. If you’re creating a C++ app, you could wrap most of your code in
try/catch statements, and either do as I suggested, or include the OS-gui
and show a messagebox, which is at least pretty simple on windows (I can’t
speak for unix-based systems).

Otherwise, I wouldn’t be opposed to something like SDL_MsgBox, but I don’t
know if it would belong in the core of SDL, or as some sort of extension
library.

Just my thoughts, anyway.
-AlexOn Tue, Oct 23, 2012 at 11:58 AM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.

I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);

Name was just a placeholder for the example, come up with a better one
if needed :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, including a full-fledged GUI library just to output a message
box in case of error (when the rest of the program is made with only
SDL, which is the case for most games) is just plain overkill, not to
mention said library may as well fail to initialize, ruining
everything :stuck_out_tongue:

Using stderr could be done but should be used as a last resort,
because it requires the console to be opened. Considering SDL programs
usually are meant to be non-console programs, we can’t really rely on
this and should use a better way to communicate the problem if
available.

Making use of the OS API directly defeats the whole point of why one
would want to use SDL in the first place, i.e. portability. Sure, it
would be just a small piece of code you could wrap in #ifdefs, but I
think my solution would be cleaner in the long term (especially since
in some cases it may get tricky to cope with all the issues, e.g.
Windows message boxes only support UTF-16 instead of UTF-8 so you’d
have to convert the strings, etc.).

Allegro used to have an allegro_error function exclusively for this
purpose (no idea what it’s called in Allegro 5 now), I don’t see why
SDL can’t have a similar function.

2012/10/23 Alex Barry <alex.barry at gmail.com>:> I completely understand the suggestion here, as it’s very useful for getting

your app up and running with some quick error checking, BUT it really sits
on the fence as far as if it’s something overly appropriate for the SDL api,
because it’s more of an OS/Gui function which doesn’t sit at the same
low-level that the rest of SDL tends to operate.

The typical solution to this from what I’ve seen is either having/building
an in-app gui of some sort, or write to stderr/a custom file with an error
message. If you’re creating a C++ app, you could wrap most of your code in
try/catch statements, and either do as I suggested, or include the OS-gui
and show a messagebox, which is at least pretty simple on windows (I can’t
speak for unix-based systems).

Otherwise, I wouldn’t be opposed to something like SDL_MsgBox, but I don’t
know if it would belong in the core of SDL, or as some sort of extension
library.

Just my thoughts, anyway.
-Alex

On Tue, Oct 23, 2012 at 11:58 AM, Sik the hedgehog <@Sik_the_hedgehog> wrote:

Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.

I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);

Name was just a placeholder for the example, come up with a better one
if needed :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, if you’re already using some sort of text writing system (like
SDL_ttf), you could easily make a small function:

void SDL_MsgBox( const char *title, const char *msg )
{
SDL_Window *msgbox = SDL_CreateWindow( title, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 300, 100, SDL_WINDOW_SHOWN );
SDL_Renderer *msgboxR = SDL_CreateRenderer( msgbox,
0, SDL_RENDERER_ACCELERATED );
SDL_Color color={255,255,255};
SDL_Surface *text_surface = NULL;
SDL_RenderClear( msgboxR );
if((text_surface=TTF_RenderText_Solid( your_font,msg,color)) != NULL) {
SDL_Texture *texture = NULL
if((texture = SDL_CreateTextureFromSurface( msgboxR, text_surface ) !=
NULL) {
SDL_RenderCopy( msgboxR, texture, NULL, NULL );
SDL_RenderPresent( msgboxR );
SDL_DestroyTexture( texture );
}
SDL_FreeSurface(text_surface);
}

}

… and in your SDL event loop:

case SDL_WindowEvent:
if ( e->window.event == SDL_WINDOWEVENT_CLOSE ) {
if ( e->window.windowID != SDL_GetWindowID( your_main_SDL_Window_ptr )
) {
// Must be your message box
SDL_Window *wnd = SDL_GetWindowFromID( e->window.windowID );
SDL_DestroyRenderer( SDL_GetRenderer( wnd ) );
SDL_DestroyWindow( wnd );
}
}
break;

It’s not that bad at all :slight_smile:
-AlexOn Tue, Oct 23, 2012 at 12:36 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

Well, including a full-fledged GUI library just to output a message
box in case of error (when the rest of the program is made with only
SDL, which is the case for most games) is just plain overkill, not to
mention said library may as well fail to initialize, ruining
everything :stuck_out_tongue:

Using stderr could be done but should be used as a last resort,
because it requires the console to be opened. Considering SDL programs
usually are meant to be non-console programs, we can’t really rely on
this and should use a better way to communicate the problem if
available.

Making use of the OS API directly defeats the whole point of why one
would want to use SDL in the first place, i.e. portability. Sure, it
would be just a small piece of code you could wrap in #ifdefs, but I
think my solution would be cleaner in the long term (especially since
in some cases it may get tricky to cope with all the issues, e.g.
Windows message boxes only support UTF-16 instead of UTF-8 so you’d
have to convert the strings, etc.).

Allegro used to have an allegro_error function exclusively for this
purpose (no idea what it’s called in Allegro 5 now), I don’t see why
SDL can’t have a similar function.

2012/10/23 Alex Barry <@Alex_Barry>:

I completely understand the suggestion here, as it’s very useful for
getting
your app up and running with some quick error checking, BUT it really
sits
on the fence as far as if it’s something overly appropriate for the SDL
api,
because it’s more of an OS/Gui function which doesn’t sit at the same
low-level that the rest of SDL tends to operate.

The typical solution to this from what I’ve seen is either
having/building
an in-app gui of some sort, or write to stderr/a custom file with an
error
message. If you’re creating a C++ app, you could wrap most of your code
in
try/catch statements, and either do as I suggested, or include the OS-gui
and show a messagebox, which is at least pretty simple on windows (I
can’t
speak for unix-based systems).

Otherwise, I wouldn’t be opposed to something like SDL_MsgBox, but I
don’t
know if it would belong in the core of SDL, or as some sort of extension
library.

Just my thoughts, anyway.
-Alex

On Tue, Oct 23, 2012 at 11:58 AM, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:

Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.

I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);

Name was just a placeholder for the example, come up with a better one
if needed :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

And that defeats the point since the idea is that it can be used even
when SDL itself fails to work (e.g. you could use it to show a message
indicating there was a problem initializing SDL - good luck going with
your suggestion in that case).

2012/10/23 Alex Barry <alex.barry at gmail.com>:> Well, if you’re already using some sort of text writing system (like

SDL_ttf), you could easily make a small function:

void SDL_MsgBox( const char *title, const char *msg )
{
SDL_Window *msgbox = SDL_CreateWindow( title, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 300, 100, SDL_WINDOW_SHOWN );
SDL_Renderer *msgboxR = SDL_CreateRenderer( msgbox, 0,
SDL_RENDERER_ACCELERATED );
SDL_Color color={255,255,255};
SDL_Surface *text_surface = NULL;
SDL_RenderClear( msgboxR );
if((text_surface=TTF_RenderText_Solid( your_font,msg,color)) != NULL) {
SDL_Texture *texture = NULL
if((texture = SDL_CreateTextureFromSurface( msgboxR, text_surface ) !=
NULL) {
SDL_RenderCopy( msgboxR, texture, NULL, NULL );
SDL_RenderPresent( msgboxR );
SDL_DestroyTexture( texture );
}
SDL_FreeSurface(text_surface);
}

}

… and in your SDL event loop:

case SDL_WindowEvent:
if ( e->window.event == SDL_WINDOWEVENT_CLOSE ) {
if ( e->window.windowID != SDL_GetWindowID( your_main_SDL_Window_ptr ) )
{
// Must be your message box
SDL_Window *wnd = SDL_GetWindowFromID( e->window.windowID );
SDL_DestroyRenderer( SDL_GetRenderer( wnd ) );
SDL_DestroyWindow( wnd );
}
}
break;

It’s not that bad at all :slight_smile:
-Alex

On Tue, Oct 23, 2012 at 12:36 PM, Sik the hedgehog <@Sik_the_hedgehog> wrote:

Well, including a full-fledged GUI library just to output a message
box in case of error (when the rest of the program is made with only
SDL, which is the case for most games) is just plain overkill, not to
mention said library may as well fail to initialize, ruining
everything :stuck_out_tongue:

Using stderr could be done but should be used as a last resort,
because it requires the console to be opened. Considering SDL programs
usually are meant to be non-console programs, we can’t really rely on
this and should use a better way to communicate the problem if
available.

Making use of the OS API directly defeats the whole point of why one
would want to use SDL in the first place, i.e. portability. Sure, it
would be just a small piece of code you could wrap in #ifdefs, but I
think my solution would be cleaner in the long term (especially since
in some cases it may get tricky to cope with all the issues, e.g.
Windows message boxes only support UTF-16 instead of UTF-8 so you’d
have to convert the strings, etc.).

Allegro used to have an allegro_error function exclusively for this
purpose (no idea what it’s called in Allegro 5 now), I don’t see why
SDL can’t have a similar function.

2012/10/23 Alex Barry <alex.barry at gmail.com>:

I completely understand the suggestion here, as it’s very useful for
getting
your app up and running with some quick error checking, BUT it really
sits
on the fence as far as if it’s something overly appropriate for the SDL
api,
because it’s more of an OS/Gui function which doesn’t sit at the same
low-level that the rest of SDL tends to operate.

The typical solution to this from what I’ve seen is either
having/building
an in-app gui of some sort, or write to stderr/a custom file with an
error
message. If you’re creating a C++ app, you could wrap most of your code
in
try/catch statements, and either do as I suggested, or include the
OS-gui
and show a messagebox, which is at least pretty simple on windows (I
can’t
speak for unix-based systems).

Otherwise, I wouldn’t be opposed to something like SDL_MsgBox, but I
don’t
know if it would belong in the core of SDL, or as some sort of extension
library.

Just my thoughts, anyway.
-Alex

On Tue, Oct 23, 2012 at 11:58 AM, Sik the hedgehog <@Sik_the_hedgehog> wrote:

Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.

I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);

Name was just a placeholder for the example, come up with a better one
if needed :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Interestingly I’m working on that today. And yes, it’s designed to work
even if SDL itself fails to initialize for some reason.On Tue, Oct 23, 2012 at 8:58 AM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.

I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);

Name was just a placeholder for the example, come up with a better one
if needed :stuck_out_tongue:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Interestingly I’m working on that today.? And yes, it’s designed to work
even if SDL itself fails to initialize for some reason.

I wrote something like this for Windows, OSX and *nix in ioq3. Predictably the *nix implementation is the most awkward. Maybe it’s useful; look for Sys_Dialog:

http://svn.icculus.org/quake3/trunk/code/sys/sys_win32.c?revision=2304&view=markup
http://svn.icculus.org/quake3/trunk/code/sys/sys_osx.m?revision=2253&view=markup
http://svn.icculus.org/quake3/trunk/code/sys/sys_unix.c?revision=2300&view=markupOn Tue, 23 Oct 2012, 20:40:49 BST, Sam Lantinga wrote:

Here’s a first pass:

It’s for two specific use cases:

  1. Showing a dialog before game initialization or if game initialization
    fails
  2. Showing custom assertions where you might have your own button labels

It works on X11 right now and implementations for other systems need to be
done.

Eventually I plan to switch the existing SDL assertion code to use this.

Cheers!On Tue, Oct 23, 2012 at 1:03 PM, Tim Angus wrote:

On Tue, 23 Oct 2012, 20:40:49 BST, Sam Lantinga <@slouken> wrote:

Interestingly I’m working on that today. And yes, it’s designed to work
even if SDL itself fails to initialize for some reason.

I wrote something like this for Windows, OSX and *nix in ioq3. Predictably
the *nix implementation is the most awkward. Maybe it’s useful; look for
Sys_Dialog:

http://svn.icculus.org/quake3/trunk/code/sys/sys_win32.c?revision=2304&view=markup

http://svn.icculus.org/quake3/trunk/code/sys/sys_osx.m?revision=2253&view=markup

http://svn.icculus.org/quake3/trunk/code/sys/sys_unix.c?revision=2300&view=markup

Wow: It’s like Christmas has come early! This works great on KDE4, and
will certainly save lots of time dealing with stderr or things like zenity.

One nitpick: SDL_messagebox.h needs to be added to the various projects.
Otherwise it isn’t included when installed, and nothing builds. I’ve
attached a patch for the autotools build, but it’s probably required for
the other build systems as well. (Cannot wait for CMake! :slight_smile: )

Cheers,
– DavidOn 24/10/12 08:53, Sam Lantinga wrote:

Here’s a first pass:
http://hg.libsdl.org/SDL/rev/533131e24aeb

It’s for two specific use cases:

  1. Showing a dialog before game initialization or if game initialization
    fails
  2. Showing custom assertions where you might have your own button labels

It works on X11 right now and implementations for other systems need to
be done.

Eventually I plan to switch the existing SDL assertion code to use this.

Cheers!

On Tue, Oct 23, 2012 at 1:03 PM, Tim Angus <tim at ngus.net <mailto:tim at ngus.net>> wrote:

On Tue, 23 Oct 2012, 20:40:49 BST, Sam Lantinga <slouken at libsdl.org <mailto:slouken at libsdl.org>> wrote:

 > Interestingly I'm working on that today.   And yes, it's designed
to work
 > even if SDL itself fails to initialize for some reason.

I wrote something like this for Windows, OSX and *nix in ioq3.
Predictably the *nix implementation is the most awkward. Maybe it's
useful; look for Sys_Dialog:

http://svn.icculus.org/quake3/trunk/code/sys/sys_win32.c?revision=2304&view=markup
http://svn.icculus.org/quake3/trunk/code/sys/sys_osx.m?revision=2253&view=markup
http://svn.icculus.org/quake3/trunk/code/sys/sys_unix.c?revision=2300&view=markup

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDL-messagebox-autotools.patch
Type: text/x-patch
Size: 514 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20121024/cda123c7/attachment.bin

2012/10/23 Sam Lantinga :

It’s for two specific use cases:

  1. Showing a dialog before game initialization or if game initialization
    fails
  2. Showing custom assertions where you might have your own button labels

I assume that if there’s an fatal error in the middle of the program
and it decides to abort it works too, right? (I deinitialize
everything then show the error message, if that matters)

Yep!On Tue, Oct 23, 2012 at 7:54 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

2012/10/23 Sam Lantinga <@slouken>:

It’s for two specific use cases:

  1. Showing a dialog before game initialization or if game initialization
    fails
  2. Showing custom assertions where you might have your own button labels

I assume that if there’s an fatal error in the middle of the program
and it decides to abort it works too, right? (I deinitialize
everything then show the error message, if that matters)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks! I actually had this change locally but missed it when collecting
files for the commit.

Cheers!On Tue, Oct 23, 2012 at 7:45 PM, David Gow wrote:

Wow: It’s like Christmas has come early! This works great on KDE4, and
will certainly save lots of time dealing with stderr or things like zenity.

One nitpick: SDL_messagebox.h needs to be added to the various projects.
Otherwise it isn’t included when installed, and nothing builds. I’ve
attached a patch for the autotools build, but it’s probably required for
the other build systems as well. (Cannot wait for CMake! :slight_smile: )

Cheers,
– David

On 24/10/12 08:53, Sam Lantinga wrote:

Here’s a first pass:
http://hg.libsdl.org/SDL/rev/**533131e24aebhttp://hg.libsdl.org/SDL/rev/533131e24aeb

It’s for two specific use cases:

  1. Showing a dialog before game initialization or if game initialization
    fails
  2. Showing custom assertions where you might have your own button labels

It works on X11 right now and implementations for other systems need to
be done.

Eventually I plan to switch the existing SDL assertion code to use this.

Cheers!

On Tue, Oct 23, 2012 at 1:03 PM, Tim Angus <tim at ngus.net <mailto:tim at ngus.net>> wrote:

On Tue, 23 Oct 2012, 20:40:49 BST, Sam Lantinga <@slouken <mailto:@slouken>> wrote:

 > Interestingly I'm working on that today.   And yes, it's designed
to work
 > even if SDL itself fails to initialize for some reason.

I wrote something like this for Windows, OSX and *nix in ioq3.
Predictably the *nix implementation is the most awkward. Maybe it's
useful; look for Sys_Dialog:

http://svn.icculus.org/quake3/**trunk/code/sys/sys_win32.c?**

revision=2304&view=markuphttp://svn.icculus.org/quake3/trunk/code/sys/sys_win32.c?revision=2304&view=markup
http://svn.icculus.org/quake3/trunk/code/sys/sys_osx.m?
revision=2253&view=markuphttp://svn.icculus.org/quake3/trunk/code/sys/sys_osx.m?revision=2253&view=markup
http://svn.icculus.org/quake3/trunk/code/sys/sys_unix.c?
revision=2300&view=markuphttp://svn.icculus.org/quake3/trunk/code/sys/sys_unix.c?revision=2300&view=markup

_____________**
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.orghttp://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

On, Wed Oct 24, 2012, David Gow wrote:

Wow: It’s like Christmas has come early! This works great on KDE4, and
will certainly save lots of time dealing with stderr or things like zenity.

One nitpick: SDL_messagebox.h needs to be added to the various projects.
Otherwise it isn’t included when installed, and nothing builds. I’ve
attached a patch for the autotools build, but it’s probably required for
the other build systems as well. (Cannot wait for CMake! :slight_smile: )

The installation of the relevant SDL_messagebox.h file happens
automatically - no need for any modification or update of
CMakeLists.txt.

The example however are not covered by this.

Cheers
Marcus
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20121024/905ff990/attachment.pgp