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

48 {
49  SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, /**< Marks the default button when return is hit */
50  SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 /**< Marks the default button when escape is hit */
SDL_MessageBoxButtonFlags
Flags for SDL_MessageBoxButtonData.

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

38 {
39  SDL_MESSAGEBOX_ERROR = 0x00000010, /**< error dialog */
40  SDL_MESSAGEBOX_WARNING = 0x00000020, /**< warning dialog */
41  SDL_MESSAGEBOX_INFORMATION = 0x00000040 /**< informational dialog */
SDL_MessageBoxFlags
SDL_MessageBox flags. If supported will display warning icon, etc.

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 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().

3767 {
3768  int dummybutton;
3769  int retval = -1;
3770  SDL_bool relative_mode;
3771  int show_cursor_prev;
3772  SDL_bool mouse_captured;
3773  SDL_Window *current_window;
3774 
3775  if (!messageboxdata) {
3776  return SDL_InvalidParamError("messageboxdata");
3777  }
3778 
3779  current_window = SDL_GetKeyboardFocus();
3780  mouse_captured = current_window && ((SDL_GetWindowFlags(current_window) & SDL_WINDOW_MOUSE_CAPTURE) != 0);
3781  relative_mode = SDL_GetRelativeMouseMode();
3784  show_cursor_prev = SDL_ShowCursor(1);
3786 
3787  if (!buttonid) {
3788  buttonid = &dummybutton;
3789  }
3790 
3791  if (_this && _this->ShowMessageBox) {
3792  retval = _this->ShowMessageBox(_this, messageboxdata, buttonid);
3793  }
3794 
3795  /* It's completely fine to call this function before video is initialized */
3796 #if SDL_VIDEO_DRIVER_ANDROID
3797  if (retval == -1 &&
3798  Android_ShowMessageBox(messageboxdata, buttonid) == 0) {
3799  retval = 0;
3800  }
3801 #endif
3802 #if SDL_VIDEO_DRIVER_WINDOWS
3803  if (retval == -1 &&
3805  WIN_ShowMessageBox(messageboxdata, buttonid) == 0) {
3806  retval = 0;
3807  }
3808 #endif
3809 #if SDL_VIDEO_DRIVER_WINRT
3810  if (retval == -1 &&
3811  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_WINRT) &&
3812  WINRT_ShowMessageBox(messageboxdata, buttonid) == 0) {
3813  retval = 0;
3814  }
3815 #endif
3816 #if SDL_VIDEO_DRIVER_COCOA
3817  if (retval == -1 &&
3818  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_COCOA) &&
3819  Cocoa_ShowMessageBox(messageboxdata, buttonid) == 0) {
3820  retval = 0;
3821  }
3822 #endif
3823 #if SDL_VIDEO_DRIVER_UIKIT
3824  if (retval == -1 &&
3825  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_UIKIT) &&
3826  UIKit_ShowMessageBox(messageboxdata, buttonid) == 0) {
3827  retval = 0;
3828  }
3829 #endif
3830 #if SDL_VIDEO_DRIVER_X11
3831  if (retval == -1 &&
3832  SDL_MessageboxValidForDriver(messageboxdata, SDL_SYSWM_X11) &&
3833  X11_ShowMessageBox(messageboxdata, buttonid) == 0) {
3834  retval = 0;
3835  }
3836 #endif
3837  if (retval == -1) {
3838  SDL_SetError("No message system available");
3839  }
3840 
3841  if (current_window) {
3842  SDL_RaiseWindow(current_window);
3843  if (mouse_captured) {
3845  }
3846  }
3847 
3848  SDL_ShowCursor(show_cursor_prev);
3849  SDL_SetRelativeMouseMode(relative_mode);
3850 
3851  return retval;
3852 }
#define SDL_SetRelativeMouseMode
#define SDL_GetKeyboardFocus
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
void SDL_RaiseWindow(SDL_Window *window)
Raise a window above other windows and set the input focus.
Definition: SDL_video.c:2107
Uint32 SDL_GetWindowFlags(SDL_Window *window)
Get the window flags.
Definition: SDL_video.c:1660
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
SDL_bool retval
#define SDL_GetRelativeMouseMode
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
Definition: SDL_video.c:3747
int(* ShowMessageBox)(_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid)
Definition: SDL_sysvideo.h:302
SDL_bool
Definition: SDL_stdinc.h:139
#define SDL_SetError
The type used to identify a window.
Definition: SDL_sysvideo.h:73
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:572
#define SDL_CaptureMouse
#define SDL_ShowCursor

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

3856 {
3857 #ifdef __EMSCRIPTEN__
3858  /* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
3859  /* Web browsers don't (currently) have an API for a custom message box
3860  that can block, but for the most common case (SDL_ShowSimpleMessageBox),
3861  we can use the standard Javascript alert() function. */
3862  EM_ASM_({
3863  alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1));
3864  }, title, message);
3865  return 0;
3866 #else
3869 
3870  SDL_zero(data);
3871  data.flags = flags;
3872  data.title = title;
3873  data.message = message;
3874  data.numbuttons = 1;
3875  data.buttons = &button;
3876  data.window = window;
3877 
3878  SDL_zero(button);
3881  button.text = "OK";
3882 
3883  return SDL_ShowMessageBox(&data, NULL);
3884 #endif
3885 }
const char * message
SDL_Texture * button
const char * title
SDL_Window * window
GLuint GLsizei const GLchar * message
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
Individual button data.
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
const SDL_MessageBoxButtonData * buttons
MessageBox structure containing title, text, window, etc.
#define NULL
Definition: begin_code.h:164
GLbitfield flags
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
Create a modal message box.
Definition: SDL_video.c:3766