SDL 3.0
SDL_messagebox.h File Reference
+ Include dependency graph for SDL_messagebox.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_MessageBoxButtonData
 
struct  SDL_MessageBoxColor
 
struct  SDL_MessageBoxColorScheme
 
struct  SDL_MessageBoxData
 

Macros

#define SDL_MESSAGEBOX_ERROR   0x00000010u
 
#define SDL_MESSAGEBOX_WARNING   0x00000020u
 
#define SDL_MESSAGEBOX_INFORMATION   0x00000040u
 
#define SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT   0x00000080u
 
#define SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT   0x00000100u
 
#define SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT   0x00000001u
 
#define SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT   0x00000002u
 

Typedefs

typedef Uint32 SDL_MessageBoxFlags
 
typedef Uint32 SDL_MessageBoxButtonFlags
 

Enumerations

enum  SDL_MessageBoxColorType {
  SDL_MESSAGEBOX_COLOR_BACKGROUND ,
  SDL_MESSAGEBOX_COLOR_TEXT ,
  SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ,
  SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ,
  SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ,
  SDL_MESSAGEBOX_COLOR_COUNT
}
 

Functions

bool SDL_ShowMessageBox (const SDL_MessageBoxData *messageboxdata, int *buttonid)
 
bool SDL_ShowSimpleMessageBox (SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window)
 

Macro Definition Documentation

◆ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT

#define SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT   0x00000002u

Marks the default button when escape is hit

Definition at line 75 of file SDL_messagebox.h.

◆ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT

#define SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT   0x00000001u

Marks the default button when return is hit

Definition at line 74 of file SDL_messagebox.h.

◆ SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT

#define SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT   0x00000080u

buttons placed left to right

Definition at line 64 of file SDL_messagebox.h.

◆ SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT

#define SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT   0x00000100u

buttons placed right to left

Definition at line 65 of file SDL_messagebox.h.

◆ SDL_MESSAGEBOX_ERROR

#define SDL_MESSAGEBOX_ERROR   0x00000010u

error dialog

Definition at line 61 of file SDL_messagebox.h.

◆ SDL_MESSAGEBOX_INFORMATION

#define SDL_MESSAGEBOX_INFORMATION   0x00000040u

informational dialog

Definition at line 63 of file SDL_messagebox.h.

◆ SDL_MESSAGEBOX_WARNING

#define SDL_MESSAGEBOX_WARNING   0x00000020u

warning dialog

Definition at line 62 of file SDL_messagebox.h.

Typedef Documentation

◆ SDL_MessageBoxButtonFlags

SDL_MessageBoxButtonData flags.

Since
This datatype is available since SDL 3.2.0.

Definition at line 72 of file SDL_messagebox.h.

◆ SDL_MessageBoxFlags

CategoryMessagebox

SDL offers a simple message box API, which is useful for simple alerts, such as informing the user when something fatal happens at startup without the need to build a UI for it (or informing the user before your UI is ready).

These message boxes are native system dialogs where possible.

There is both a customizable function (SDL_ShowMessageBox()) that offers lots of options for what to display and reports on what choice the user made, and also a much-simplified version (SDL_ShowSimpleMessageBox()), merely takes a text message and title, and waits until the user presses a single "OK" UI button. Often, this is all that is necessary. Message box flags.

If supported will display warning icon, etc.

Since
This datatype is available since SDL 3.2.0.

Definition at line 59 of file SDL_messagebox.h.

Enumeration Type Documentation

◆ SDL_MessageBoxColorType

An enumeration of indices inside the colors array of SDL_MessageBoxColorScheme.

Enumerator
SDL_MESSAGEBOX_COLOR_BACKGROUND 
SDL_MESSAGEBOX_COLOR_TEXT 
SDL_MESSAGEBOX_COLOR_BUTTON_BORDER 
SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND 
SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED 
SDL_MESSAGEBOX_COLOR_COUNT 

Size of the colors array of SDL_MessageBoxColorScheme.

Definition at line 103 of file SDL_messagebox.h.

104{
110 SDL_MESSAGEBOX_COLOR_COUNT /**< Size of the colors array of SDL_MessageBoxColorScheme. */
SDL_MessageBoxColorType
@ SDL_MESSAGEBOX_COLOR_COUNT
@ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND
@ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED
@ SDL_MESSAGEBOX_COLOR_BACKGROUND
@ SDL_MESSAGEBOX_COLOR_TEXT
@ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER

Function Documentation

◆ SDL_ShowMessageBox()

bool SDL_ShowMessageBox ( const SDL_MessageBoxData messageboxdata,
int *  buttonid 
)

Create a modal message box.

If your needs aren't complex, it might be easier to use SDL_ShowSimpleMessageBox.

This function should be called on the thread that created the parent window, or on the main thread if the messagebox has no parent. It will block execution of that thread until the user clicks a button or closes the messagebox.

This function may be called at any time, even before SDL_Init(). This makes it useful for reporting errors like a failure to create a renderer or OpenGL context.

On X11, SDL rolls its own dialog box with X11 primitives instead of a formal toolkit like GTK+ or Qt.

Note that if SDL_Init() would fail because there isn't any available video target, this function is likely to fail for the same reasons. If this is a concern, check the return value from this function and fall back to writing to stderr if you can.

Parameters
messageboxdatathe SDL_MessageBoxData structure with title, text and other options.
buttonidthe pointer to which user id of hit button should be copied.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
SDL_ShowSimpleMessageBox

◆ SDL_ShowSimpleMessageBox()

bool SDL_ShowSimpleMessageBox ( SDL_MessageBoxFlags  flags,
const char *  title,
const char *  message,
SDL_Window window 
)

Display a simple modal message box.

If your needs aren't complex, this function is preferred over SDL_ShowMessageBox.

flags may be any of the following:

  • SDL_MESSAGEBOX_ERROR: error dialog
  • SDL_MESSAGEBOX_WARNING: warning dialog
  • SDL_MESSAGEBOX_INFORMATION: informational dialog

This function should be called on the thread that created the parent window, or on the main thread if the messagebox has no parent. It will block execution of that thread until the user clicks a button or closes the messagebox.

This function may be called at any time, even before SDL_Init(). This makes it useful for reporting errors like a failure to create a renderer or OpenGL context.

On X11, SDL rolls its own dialog box with X11 primitives instead of a formal toolkit like GTK+ or Qt.

Note that if SDL_Init() would fail because there isn't any available video target, this function is likely to fail for the same reasons. If this is a concern, check the return value from this function and fall back to writing to stderr if you can.

Parameters
flagsan SDL_MessageBoxFlags value.
titleUTF-8 title text.
messageUTF-8 message text.
windowthe parent window, or NULL for no parent.
Returns
true on success or false on failure; call SDL_GetError() for more information.
Since
This function is available since SDL 3.2.0.
See also
SDL_ShowMessageBox