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_MessageBoxButtonFlags
Flags for SDL_MessageBoxButtonData.
@ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
@ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT

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

74 {
SDL_MessageBoxColorType
@ SDL_MESSAGEBOX_COLOR_MAX
@ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND
@ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED
@ SDL_MESSAGEBOX_COLOR_BACKGROUND
@ SDL_MESSAGEBOX_COLOR_TEXT
@ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER

◆ 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 */
SDL_MessageBoxFlags
SDL_MessageBox flags. If supported will display warning icon, etc.
@ SDL_MESSAGEBOX_ERROR
@ SDL_MESSAGEBOX_WARNING
@ SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT
@ SDL_MESSAGEBOX_INFORMATION
@ SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT

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 3993 of file SDL_video.c.

3994 {
3995  int dummybutton;
3996  int retval = -1;
3997  SDL_bool relative_mode;
3998  int show_cursor_prev;
3999  SDL_bool mouse_captured;
4000  SDL_Window *current_window;
4001  SDL_MessageBoxData mbdata;
4002 
4003  if (!messageboxdata) {
4004  return SDL_InvalidParamError("messageboxdata");
4005  } else if (messageboxdata->numbuttons < 0) {
4006  return SDL_SetError("Invalid number of buttons");
4007  }
4008 
4009  current_window = SDL_GetKeyboardFocus();
4010  mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
4011  relative_mode = SDL_GetRelativeMouseMode();
4014  show_cursor_prev = SDL_ShowCursor(1);
4016 
4017  if (!buttonid) {
4018  buttonid = &dummybutton;
4019  }
4020 
4021  SDL_memcpy(&mbdata, messageboxdata, sizeof(*messageboxdata));
4022  if (!mbdata.title) mbdata.title = "";
4023  if (!mbdata.message) mbdata.message = "";
4024  messageboxdata = &mbdata;
4025 
4026  if (_this && _this->ShowMessageBox) {
4027  retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
4028  }
4029 
4030  /* It's completely fine to call this function before video is initialized */
4031 #if SDL_VIDEO_DRIVER_ANDROID
4032  if (retval == -1 &&
4033  Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
4034  retval = 0;
4035  }
4036 #endif
4037 #if SDL_VIDEO_DRIVER_WINDOWS
4038  if (retval == -1 &&
4040  WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
4041  retval = 0;
4042  }
4043 #endif
4044 #if SDL_VIDEO_DRIVER_WINRT
4045  if (retval == -1 &&
4046  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
4047  WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
4048  retval = 0;
4049  }
4050 #endif
4051 #if SDL_VIDEO_DRIVER_COCOA
4052  if (retval == -1 &&
4053  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
4054  Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
4055  retval = 0;
4056  }
4057 #endif
4058 #if SDL_VIDEO_DRIVER_UIKIT
4059  if (retval == -1 &&
4060  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
4061  UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
4062  retval = 0;
4063  }
4064 #endif
4065 #if SDL_VIDEO_DRIVER_X11
4066  if (retval == -1 &&
4067  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
4068  X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
4069  retval = 0;
4070  }
4071 #endif
4072 #if SDL_VIDEO_DRIVER_HAIKU
4073  if (retval == -1 &&
4074  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_HAIKU) &&
4075  HAIKU_ShowMessageBox(messageboxdata, buttonid) == 0) {
4076  retval = 0;
4077  }
4078 #endif
4079 #if SDL_VIDEO_DRIVER_OS2
4080  if (retval == -1 &&
4081  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_OS2) &&
4082  OS2_ShowMessageBox(messageboxdata, buttonid) == 0) {
4083  retval = 0;
4084  }
4085 #endif
4086  if (retval == -1) {
4087  SDL_SetError("No message system available");
4088  }
4089 
4090  if (current_window) {
4091  SDL_RaiseWindow(current_window);
4092  if (mouse_captured) {
4094  }
4095  }
4096 
4097  SDL_ShowCursor(show_cursor_prev);
4098  SDL_SetRelativeMouseMode(relative_mode);
4099 
4100  return retval;
4101 }
#define SDL_SetError
#define SDL_ShowCursor
#define SDL_SetRelativeMouseMode
#define SDL_CaptureMouse
#define SDL_GetKeyboardFocus
#define SDL_memcpy
#define SDL_GetRelativeMouseMode
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:90
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:576
SDL_bool
Definition: SDL_stdinc.h:168
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
@ SDL_SYSWM_X11
Definition: SDL_syswm.h:131
@ SDL_SYSWM_OS2
Definition: SDL_syswm.h:140
@ SDL_SYSWM_HAIKU
Definition: SDL_syswm.h:141
@ SDL_SYSWM_WINDOWS
Definition: SDL_syswm.h:130
@ SDL_SYSWM_UIKIT
Definition: SDL_syswm.h:134
@ SDL_SYSWM_COCOA
Definition: SDL_syswm.h:133
@ SDL_SYSWM_WINRT
Definition: SDL_syswm.h:137
Uint32 SDL_GetWindowFlags(SDL_Window *window)
Get the window flags.
Definition: SDL_video.c:1852
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
Definition: SDL_video.c:3974
void SDL_RaiseWindow(SDL_Window *window)
Raise a window above other windows and set the input focus.
Definition: SDL_video.c:2298
@ SDL_WINDOW_MOUSE_CAPTURE
Definition: SDL_video.h:115
MessageBox structure containing title, text, window, etc.
const char * title
const char * message
int(* ShowMessageBox)(_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid)
Definition: SDL_sysvideo.h:313
The type used to identify a window.
Definition: SDL_sysvideo.h:75
SDL_bool retval

References _this, SDL_MessageBoxData::message, SDL_MessageBoxData::numbuttons, retval, SDL_CaptureMouse, SDL_FALSE, SDL_GetKeyboardFocus, SDL_GetRelativeMouseMode, SDL_GetWindowFlags(), SDL_InvalidParamError, SDL_memcpy, SDL_MessageboxValidForDriver(), SDL_RaiseWindow(), SDL_ResetKeyboard(), SDL_SetError, SDL_SetRelativeMouseMode, SDL_ShowCursor, SDL_SYSWM_COCOA, SDL_SYSWM_HAIKU, SDL_SYSWM_OS2, SDL_SYSWM_UIKIT, SDL_SYSWM_WINDOWS, SDL_SYSWM_WINRT, SDL_SYSWM_X11, SDL_TRUE, SDL_WINDOW_MOUSE_CAPTURE, SDL_VideoDevice::ShowMessageBox, and SDL_MessageBoxData::title.

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 4104 of file SDL_video.c.

4105 {
4106 #ifdef __EMSCRIPTEN__
4107  /* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
4108  /* Web browsers don't (currently) have an API for a custom message box
4109  that can block, but for the most common case (SDL_ShowSimpleMessageBox),
4110  we can use the standard Javascript alert() function. */
4111  if (!title) title = "";
4112  if (!message) message = "";
4113  EM_ASM_({
4114  alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
4115  }, title, message);
4116  return 0;
4117 #else
4120 
4121  SDL_zero(data);
4122  data.flags = flags;
4123  data.title = title;
4124  data.message = message;
4125  data.numbuttons = 1;
4126  data.buttons = &button;
4127  data.window = window;
4128 
4129  SDL_zero(button);
4132  button.text = "OK";
4133 
4134  return SDL_ShowMessageBox(&data, NULL);
4135 #endif
4136 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLuint GLsizei const GLchar * message
GLbitfield flags
#define SDL_zero(x)
Definition: SDL_stdinc.h:426
int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
Create a modal message box.
Definition: SDL_video.c:3993
#define NULL
Definition: begin_code.h:163
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
Individual button data.
SDL_Texture * button

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