SDL_messagebox.h File Reference
`#include "SDL_stdinc.h"`
`#include "SDL_video.h"`
`#include "begin_code.h"`
`#include "close_code.h"`
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
| Individual button data. More...
struct | SDL_MessageBoxColor
| RGB value used in a message box color scheme. More...
struct | SDL_MessageBoxColorScheme
| A set of colors to use for message box dialogs. More...
struct | SDL_MessageBoxData
| MessageBox structure containing title, text, window, etc. More...

## Enumerations

enum | SDL_MessageBoxFlags { SDL_MESSAGEBOX_ERROR = 0x00000010, SDL_MESSAGEBOX_WARNING = 0x00000020, SDL_MESSAGEBOX_INFORMATION = 0x00000040 }
| SDL_MessageBox flags. If supported will display warning icon, etc. More...
enum | SDL_MessageBoxButtonFlags { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 }
| Flags for SDL_MessageBoxButtonData. More...
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_MAX }

## Functions

int | SDL_ShowMessageBox (const SDL_MessageBoxData *messageboxdata, int *buttonid)
| Create a modal message box. More...
int | SDL_ShowSimpleMessageBox (Uint32 flags, const char *title, const char *message, SDL_Window *window)
| Create a simple modal message box. More...

## Enumeration Type Documentation

## SDL_MessageBoxButtonFlags

enum SDL_MessageBoxButtonFlags

Flags for SDL_MessageBoxButtonData.

Enumerator
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT | Marks the default button when return is hit
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT | Marks the default button when escape is hit

Definition at line 47 of file SDL_messagebox.h.

{
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, /**< Marks the default button when return is hit */
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 /**< Marks the default button when escape is hit */
} SDL_MessageBoxButtonFlags;
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Definition: SDL_messagebox.h:50
SDL_MessageBoxButtonFlags
SDL_MessageBoxButtonFlags
Flags for SDL_MessageBoxButtonData.
Definition: SDL_messagebox.h:47
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Definition: SDL_messagebox.h:49

## SDL_MessageBoxColorType

enum SDL_MessageBoxColorType

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_MAX |

Definition at line 71 of file SDL_messagebox.h.

{
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_MAX
} SDL_MessageBoxColorType;
SDL_MESSAGEBOX_COLOR_BACKGROUND
Definition: SDL_messagebox.h:73
SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED
Definition: SDL_messagebox.h:77
SDL_MESSAGEBOX_COLOR_TEXT
Definition: SDL_messagebox.h:74
SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND
Definition: SDL_messagebox.h:76
SDL_MESSAGEBOX_COLOR_MAX
Definition: SDL_messagebox.h:78
SDL_MessageBoxColorType
SDL_MessageBoxColorType
Definition: SDL_messagebox.h:71
SDL_MESSAGEBOX_COLOR_BUTTON_BORDER
Definition: SDL_messagebox.h:75

## SDL_MessageBoxFlags

enum SDL_MessageBoxFlags

SDL_MessageBox flags. If supported will display warning icon, etc.

Enumerator
SDL_MESSAGEBOX_ERROR | error dialog
SDL_MESSAGEBOX_WARNING | warning dialog
SDL_MESSAGEBOX_INFORMATION | informational dialog

Definition at line 37 of file SDL_messagebox.h.

{
SDL_MESSAGEBOX_ERROR = 0x00000010, /**< error dialog */
SDL_MESSAGEBOX_WARNING = 0x00000020, /**< warning dialog */
SDL_MESSAGEBOX_INFORMATION = 0x00000040 /**< informational dialog */
} SDL_MessageBoxFlags;
SDL_MESSAGEBOX_WARNING
Definition: SDL_messagebox.h:40
SDL_MESSAGEBOX_INFORMATION
Definition: SDL_messagebox.h:41
SDL_MESSAGEBOX_ERROR
Definition: SDL_messagebox.h:39
SDL_MessageBoxFlags
SDL_MessageBoxFlags
SDL_MessageBox flags. If supported will display warning icon, etc.
Definition: SDL_messagebox.h:37

## Function Documentation

## SDL_ShowMessageBox()

int SDL_ShowMessageBox | ( | const SDL_MessageBoxData * | messageboxdata,
|  | int * | buttonid
| ) |  |

Create a modal message box.

Parameters

  messageboxdata | The SDL_MessageBoxData structure with title, text, etc.
  buttonid | The pointer to which user id of hit button should be copied.

Returns
  -1 on error, otherwise 0 and buttonid contains user id of button hit or -1 if dialog was closed.

Note
  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.

Definition at line 3766 of file SDL_video.c.

References retval, SDL_CaptureMouse, SDL_FALSE, SDL_GetKeyboardFocus, SDL_GetRelativeMouseMode, SDL_GetWindowFlags(), SDL_InvalidParamError, SDL_MessageboxValidForDriver(), SDL_RaiseWindow(), SDL_ResetKeyboard(), SDL_SetError, SDL_SetRelativeMouseMode, SDL_ShowCursor, SDL_SYSWM_COCOA, SDL_SYSWM_UIKIT, SDL_SYSWM_WINDOWS, SDL_SYSWM_WINRT, SDL_SYSWM_X11, SDL_TRUE, SDL_WINDOW_MOUSE_CAPTURE, and SDL_VideoDevice::ShowMessageBox.

Referenced by SDL_ShowSimpleMessageBox().

{
int dummybutton;
int retval = -1;
SDL_bool relative_mode;
int show_cursor_prev;
SDL_bool mouse_captured;
SDL_Window *current_window;
if (!messageboxdata) {
return SDL_InvalidParamError("messageboxdata");
}
current_window = SDL_GetKeyboardFocus();
mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
relative_mode = SDL_GetRelativeMouseMode();
SDL_CaptureMouse(SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
show_cursor_prev = SDL_ShowCursor(1);
SDL_ResetKeyboard();
if (!buttonid) {
buttonid = &dummybutton;
}
if (_this && _this->ShowMessageBox) {
retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
}
/* It's completely fine to call this function before video is initialized */
#if SDL_VIDEO_DRIVER_ANDROID
if (retval == -1 &&
Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_WINDOWS
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINDOWS) &&
WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_WINRT
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_COCOA
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_UIKIT
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
#if SDL_VIDEO_DRIVER_X11
if (retval == -1 &&
SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
retval = 0;
}
#endif
if (retval == -1) {
SDL_SetError("No message system available");
}
if (current_window) {
SDL_RaiseWindow(current_window);
if (mouse_captured) {
SDL_CaptureMouse(SDL_TRUE);
}
}
SDL_ShowCursor(show_cursor_prev);
SDL_SetRelativeMouseMode(relative_mode);
return retval;
}
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_SetRelativeMouseMode
#define SDL_SetRelativeMouseMode
Definition: SDL_dynapi_overrides.h:249
SDL_SYSWM_X11
Definition: SDL_syswm.h:120
SDL_GetKeyboardFocus
#define SDL_GetKeyboardFocus
Definition: SDL_dynapi_overrides.h:216
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_SYSWM_WINRT
Definition: SDL_syswm.h:126
SDL_RaiseWindow
void SDL_RaiseWindow(SDL_Window *window)
Raise a window above other windows and set the input focus.
Definition: SDL_video.c:2107
SDL_GetWindowFlags
Uint32 SDL_GetWindowFlags(SDL_Window *window)
Get the window flags.
Definition: SDL_video.c:1660
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
SDL_SYSWM_WINDOWS
Definition: SDL_syswm.h:119
retval
SDL_bool retval
Definition: testgamecontroller.c:65
SDL_WINDOW_MOUSE_CAPTURE
Definition: SDL_video.h:116
SDL_GetRelativeMouseMode
#define SDL_GetRelativeMouseMode
Definition: SDL_dynapi_overrides.h:250
SDL_MessageboxValidForDriver
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
Definition: SDL_video.c:3747
SDL_VideoDevice::ShowMessageBox
int(* ShowMessageBox)(_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid)
Definition: SDL_sysvideo.h:302
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:73
SDL_ResetKeyboard
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:572
SDL_CaptureMouse
#define SDL_CaptureMouse
Definition: SDL_dynapi_overrides.h:584
SDL_SYSWM_UIKIT
Definition: SDL_syswm.h:123
SDL_ShowCursor
#define SDL_ShowCursor
Definition: SDL_dynapi_overrides.h:258
SDL_SYSWM_COCOA
Definition: SDL_syswm.h:122

## SDL_ShowSimpleMessageBox()

int SDL_ShowSimpleMessageBox | ( | Uint32 | flags,
|  | const char * | title,
|  | const char * | message,
|  | SDL_Window * | window
| ) |  |

Create a simple modal message box.

Parameters

  flags | SDL_MessageBoxFlags
  title | UTF-8 title text
  message | UTF-8 message text
  window | The parent window, or NULL for no parent

Returns
  0 on success, -1 on error

See also
  SDL_ShowMessageBox

Definition at line 3855 of file SDL_video.c.

References button, SDL_MessageBoxData::buttons, SDL_MessageBoxButtonData::flags, SDL_MessageBoxData::flags, SDL_MessageBoxData::message, NULL, SDL_MessageBoxData::numbuttons, SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, SDL_ShowMessageBox(), SDL_zero, SDL_MessageBoxButtonData::text, SDL_MessageBoxData::title, and SDL_MessageBoxData::window.

{
#ifdef __EMSCRIPTEN__
/* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
/* Web browsers don't (currently) have an API for a custom message box
that can block, but for the most common case (SDL_ShowSimpleMessageBox),
we can use the standard Javascript alert() function. */
EM_ASM_({
alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
}, title, message);
return 0;
#else
SDL_MessageBoxData data;
SDL_MessageBoxButtonData button;
SDL_zero(data);
data.flags = flags;
data.title = title;
data.message = message;
data.numbuttons = 1;
data.buttons = &button;
data.window = window;
SDL_zero(button);
button.flags |= SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
button.flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
button.text = "OK";
return SDL_ShowMessageBox(&data, NULL);
#endif
}
SDL_MessageBoxData::message
const char * message
Definition: SDL_messagebox.h:97
button
SDL_Texture * button
Definition: testgamecontroller.c:67
SDL_MessageBoxData::title
const char * title
Definition: SDL_messagebox.h:96
SDL_MessageBoxData::window
SDL_Window * window
Definition: SDL_messagebox.h:95
message
GLuint GLsizei const GLchar * message
Definition: SDL_opengl_glext.h:2483
SDL_MessageBoxData::flags
Uint32 flags
Definition: SDL_messagebox.h:94
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_MessageBoxButtonData
Individual button data.
Definition: SDL_messagebox.h:56
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Definition: SDL_messagebox.h:50
SDL_MessageBoxData::numbuttons
int numbuttons
Definition: SDL_messagebox.h:99
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_MessageBoxButtonData::flags
Uint32 flags
Definition: SDL_messagebox.h:58
SDL_MessageBoxData::buttons
const SDL_MessageBoxButtonData * buttons
Definition: SDL_messagebox.h:100
SDL_MessageBoxData
MessageBox structure containing title, text, window, etc.
Definition: SDL_messagebox.h:92
NULL
#define NULL
Definition: begin_code.h:164
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1480
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_ShowMessageBox
int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
Create a modal message box.
Definition: SDL_video.c:3766
SDL_MessageBoxButtonData::text
const char * text
Definition: SDL_messagebox.h:60
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Definition: SDL_messagebox.h:49