SDL  2.0
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_BUTTONS_LEFT_TO_RIGHT = 0x00000080,
  SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT = 0x00000100
}
 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

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 49 of file SDL_messagebox.h.

50 {
51  SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, /**< Marks the default button when return is hit */
52  SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 /**< Marks the default button when escape is hit */

◆ 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 73 of file SDL_messagebox.h.

◆ 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

SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT 

buttons placed left to right

SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT 

buttons placed right to left

Definition at line 37 of file SDL_messagebox.h.

38 {
39  SDL_MESSAGEBOX_ERROR = 0x00000010, /**< error dialog */
40  SDL_MESSAGEBOX_WARNING = 0x00000020, /**< warning dialog */
41  SDL_MESSAGEBOX_INFORMATION = 0x00000040, /**< informational dialog */
42  SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT = 0x00000080, /**< buttons placed left to right */
43  SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT = 0x00000100 /**< buttons placed right to left */

Function Documentation

◆ SDL_ShowMessageBox()

int SDL_ShowMessageBox ( const SDL_MessageBoxData messageboxdata,
int *  buttonid 
)

Create a modal message box.

Parameters
messageboxdataThe SDL_MessageBoxData structure with title, text, etc.
buttonidThe 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 3892 of file SDL_video.c.

3893 {
3894  int dummybutton;
3895  int retval = -1;
3896  SDL_bool relative_mode;
3897  int show_cursor_prev;
3898  SDL_bool mouse_captured;
3899  SDL_Window *current_window;
3900 
3901  if (!messageboxdata) {
3902  return SDL_InvalidParamError("messageboxdata");
3903  } else if (messageboxdata->numbuttons < 0) {
3904  return SDL_SetError("Invalid number of buttons");
3905  }
3906 
3907  current_window = SDL_GetKeyboardFocus();
3908  mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
3909  relative_mode = SDL_GetRelativeMouseMode();
3912  show_cursor_prev = SDL_ShowCursor(1);
3914 
3915  if (!buttonid) {
3916  buttonid = &dummybutton;
3917  }
3918 
3919  if (_this && _this->ShowMessageBox) {
3920  retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
3921  }
3922 
3923  /* It's completely fine to call this function before video is initialized */
3924 #if SDL_VIDEO_DRIVER_ANDROID
3925  if (retval == -1 &&
3926  Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
3927  retval = 0;
3928  }
3929 #endif
3930 #if SDL_VIDEO_DRIVER_WINDOWS
3931  if (retval == -1 &&
3933  WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
3934  retval = 0;
3935  }
3936 #endif
3937 #if SDL_VIDEO_DRIVER_WINRT
3938  if (retval == -1 &&
3939  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
3940  WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
3941  retval = 0;
3942  }
3943 #endif
3944 #if SDL_VIDEO_DRIVER_COCOA
3945  if (retval == -1 &&
3946  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
3947  Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
3948  retval = 0;
3949  }
3950 #endif
3951 #if SDL_VIDEO_DRIVER_UIKIT
3952  if (retval == -1 &&
3953  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
3954  UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
3955  retval = 0;
3956  }
3957 #endif
3958 #if SDL_VIDEO_DRIVER_X11
3959  if (retval == -1 &&
3960  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
3961  X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
3962  retval = 0;
3963  }
3964 #endif
3965 #if SDL_VIDEO_DRIVER_HAIKU
3966  if (retval == -1 &&
3967  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_HAIKU) &&
3968  HAIKU_ShowMessageBox(messageboxdata, buttonid) == 0) {
3969  retval = 0;
3970  }
3971 #endif
3972  if (retval == -1) {
3973  SDL_SetError("No message system available");
3974  }
3975 
3976  if (current_window) {
3977  SDL_RaiseWindow(current_window);
3978  if (mouse_captured) {
3980  }
3981  }
3982 
3983  SDL_ShowCursor(show_cursor_prev);
3984  SDL_SetRelativeMouseMode(relative_mode);
3985 
3986  return retval;
3987 }

References _this, SDL_MessageBoxData::numbuttons, 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_HAIKU, 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().

◆ SDL_ShowSimpleMessageBox()

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

Create a simple modal message box.

Parameters
flagsSDL_MessageBoxFlags
titleUTF-8 title text
messageUTF-8 message text
windowThe parent window, or NULL for no parent
Returns
0 on success, -1 on error
See also
SDL_ShowMessageBox

Definition at line 3990 of file SDL_video.c.

3991 {
3992 #ifdef __EMSCRIPTEN__
3993  /* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
3994  /* Web browsers don't (currently) have an API for a custom message box
3995  that can block, but for the most common case (SDL_ShowSimpleMessageBox),
3996  we can use the standard Javascript alert() function. */
3997  EM_ASM_({
3998  alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
3999  }, title, message);
4000  return 0;
4001 #else
4004 
4005  SDL_zero(data);
4006  data.flags = flags;
4007  data.title = title;
4008  data.message = message;
4009  data.numbuttons = 1;
4010  data.buttons = &button;
4011  data.window = window;
4012 
4013  SDL_zero(button);
4016  button.text = "OK";
4017 
4018  return SDL_ShowMessageBox(&data, NULL);
4019 #endif
4020 }

References button, NULL, SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, SDL_ShowMessageBox(), and SDL_zero.

SDL_MESSAGEBOX_COLOR_BUTTON_BORDER
@ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER
Definition: SDL_messagebox.h:77
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:418
SDL_WINDOW_MOUSE_CAPTURE
@ SDL_WINDOW_MOUSE_CAPTURE
Definition: SDL_video.h:115
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
@ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
Definition: SDL_messagebox.h:52
SDL_SYSWM_WINRT
@ SDL_SYSWM_WINRT
Definition: SDL_syswm.h:132
SDL_SYSWM_HAIKU
@ SDL_SYSWM_HAIKU
Definition: SDL_syswm.h:136
SDL_MessageBoxButtonFlags
SDL_MessageBoxButtonFlags
Flags for SDL_MessageBoxButtonData.
Definition: SDL_messagebox.h:50
NULL
#define NULL
Definition: begin_code.h:167
message
GLuint GLsizei const GLchar * message
Definition: SDL_opengl_glext.h:2486
SDL_MESSAGEBOX_COLOR_TEXT
@ SDL_MESSAGEBOX_COLOR_TEXT
Definition: SDL_messagebox.h:76
SDL_MESSAGEBOX_COLOR_BACKGROUND
@ SDL_MESSAGEBOX_COLOR_BACKGROUND
Definition: SDL_messagebox.h:75
SDL_InvalidParamError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_MESSAGEBOX_WARNING
@ SDL_MESSAGEBOX_WARNING
Definition: SDL_messagebox.h:40
SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT
@ SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT
Definition: SDL_messagebox.h:42
SDL_RaiseWindow
void SDL_RaiseWindow(SDL_Window *window)
Raise a window above other windows and set the input focus.
Definition: SDL_video.c:2208
SDL_MessageBoxFlags
SDL_MessageBoxFlags
SDL_MessageBox flags. If supported will display warning icon, etc.
Definition: SDL_messagebox.h:38
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_SetRelativeMouseMode
#define SDL_SetRelativeMouseMode
Definition: SDL_dynapi_overrides.h:249
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:75
SDL_GetKeyboardFocus
#define SDL_GetKeyboardFocus
Definition: SDL_dynapi_overrides.h:216
SDL_ResetKeyboard
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:572
SDL_GetWindowFlags
Uint32 SDL_GetWindowFlags(SDL_Window *window)
Get the window flags.
Definition: SDL_video.c:1762
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
SDL_SYSWM_COCOA
@ SDL_SYSWM_COCOA
Definition: SDL_syswm.h:128
SDL_MessageBoxColorType
SDL_MessageBoxColorType
Definition: SDL_messagebox.h:74
SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND
@ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND
Definition: SDL_messagebox.h:78
retval
SDL_bool retval
Definition: testgamecontroller.c:65
SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
@ SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
Definition: SDL_messagebox.h:43
window
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_GetRelativeMouseMode
#define SDL_GetRelativeMouseMode
Definition: SDL_dynapi_overrides.h:250
SDL_VideoDevice::ShowMessageBox
int(* ShowMessageBox)(_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid)
Definition: SDL_sysvideo.h:311
SDL_SYSWM_X11
@ SDL_SYSWM_X11
Definition: SDL_syswm.h:126
SDL_MessageBoxData
MessageBox structure containing title, text, window, etc.
Definition: SDL_messagebox.h:95
SDL_MESSAGEBOX_ERROR
@ SDL_MESSAGEBOX_ERROR
Definition: SDL_messagebox.h:39
SDL_MessageBoxButtonData
Individual button data.
Definition: SDL_messagebox.h:59
SDL_SYSWM_UIKIT
@ SDL_SYSWM_UIKIT
Definition: SDL_syswm.h:129
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_MESSAGEBOX_INFORMATION
@ SDL_MESSAGEBOX_INFORMATION
Definition: SDL_messagebox.h:41
SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED
@ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED
Definition: SDL_messagebox.h:79
SDL_MessageboxValidForDriver
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
Definition: SDL_video.c:3873
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
@ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
Definition: SDL_messagebox.h:51
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_CaptureMouse
#define SDL_CaptureMouse
Definition: SDL_dynapi_overrides.h:584
SDL_ShowMessageBox
int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
Create a modal message box.
Definition: SDL_video.c:3892
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_ShowCursor
#define SDL_ShowCursor
Definition: SDL_dynapi_overrides.h:258
SDL_MESSAGEBOX_COLOR_MAX
@ SDL_MESSAGEBOX_COLOR_MAX
Definition: SDL_messagebox.h:80
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1483
button
SDL_Texture * button
Definition: testgamecontroller.c:67
SDL_MessageBoxData::numbuttons
int numbuttons
Definition: SDL_messagebox.h:101
SDL_SYSWM_WINDOWS
@ SDL_SYSWM_WINDOWS
Definition: SDL_syswm.h:125