Path: blob/master/thirdparty/sdl/include/SDL3/SDL_messagebox.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryMessagebox23*24* SDL offers a simple message box API, which is useful for simple alerts,25* such as informing the user when something fatal happens at startup without26* the need to build a UI for it (or informing the user _before_ your UI is27* ready).28*29* These message boxes are native system dialogs where possible.30*31* There is both a customizable function (SDL_ShowMessageBox()) that offers32* lots of options for what to display and reports on what choice the user33* made, and also a much-simplified version (SDL_ShowSimpleMessageBox()),34* merely takes a text message and title, and waits until the user presses a35* single "OK" UI button. Often, this is all that is necessary.36*/3738#ifndef SDL_messagebox_h_39#define SDL_messagebox_h_4041#include <SDL3/SDL_stdinc.h>42#include <SDL3/SDL_error.h>43#include <SDL3/SDL_video.h> /* For SDL_Window */4445#include <SDL3/SDL_begin_code.h>46/* Set up for C function definitions, even when using C++ */47#ifdef __cplusplus48extern "C" {49#endif5051/**52* Message box flags.53*54* If supported will display warning icon, etc.55*56* \since This datatype is available since SDL 3.2.0.57*/58typedef Uint32 SDL_MessageBoxFlags;5960#define SDL_MESSAGEBOX_ERROR 0x00000010u /**< error dialog */61#define SDL_MESSAGEBOX_WARNING 0x00000020u /**< warning dialog */62#define SDL_MESSAGEBOX_INFORMATION 0x00000040u /**< informational dialog */63#define SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT 0x00000080u /**< buttons placed left to right */64#define SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT 0x00000100u /**< buttons placed right to left */6566/**67* SDL_MessageBoxButtonData flags.68*69* \since This datatype is available since SDL 3.2.0.70*/71typedef Uint32 SDL_MessageBoxButtonFlags;7273#define SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT 0x00000001u /**< Marks the default button when return is hit */74#define SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT 0x00000002u /**< Marks the default button when escape is hit */7576/**77* Individual button data.78*79* \since This struct is available since SDL 3.2.0.80*/81typedef struct SDL_MessageBoxButtonData82{83SDL_MessageBoxButtonFlags flags;84int buttonID; /**< User defined button id (value returned via SDL_ShowMessageBox) */85const char *text; /**< The UTF-8 button text */86} SDL_MessageBoxButtonData;8788/**89* RGB value used in a message box color scheme90*91* \since This struct is available since SDL 3.2.0.92*/93typedef struct SDL_MessageBoxColor94{95Uint8 r, g, b;96} SDL_MessageBoxColor;9798/**99* An enumeration of indices inside the colors array of100* SDL_MessageBoxColorScheme.101*/102typedef enum SDL_MessageBoxColorType103{104SDL_MESSAGEBOX_COLOR_BACKGROUND,105SDL_MESSAGEBOX_COLOR_TEXT,106SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,107SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,108SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,109SDL_MESSAGEBOX_COLOR_COUNT /**< Size of the colors array of SDL_MessageBoxColorScheme. */110} SDL_MessageBoxColorType;111112/**113* A set of colors to use for message box dialogs114*115* \since This struct is available since SDL 3.2.0.116*/117typedef struct SDL_MessageBoxColorScheme118{119SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_COUNT];120} SDL_MessageBoxColorScheme;121122/**123* MessageBox structure containing title, text, window, etc.124*125* \since This struct is available since SDL 3.2.0.126*/127typedef struct SDL_MessageBoxData128{129SDL_MessageBoxFlags flags;130SDL_Window *window; /**< Parent window, can be NULL */131const char *title; /**< UTF-8 title */132const char *message; /**< UTF-8 message text */133134int numbuttons;135const SDL_MessageBoxButtonData *buttons;136137const SDL_MessageBoxColorScheme *colorScheme; /**< SDL_MessageBoxColorScheme, can be NULL to use system settings */138} SDL_MessageBoxData;139140/**141* Create a modal message box.142*143* If your needs aren't complex, it might be easier to use144* SDL_ShowSimpleMessageBox.145*146* This function should be called on the thread that created the parent147* window, or on the main thread if the messagebox has no parent. It will148* block execution of that thread until the user clicks a button or closes the149* messagebox.150*151* This function may be called at any time, even before SDL_Init(). This makes152* it useful for reporting errors like a failure to create a renderer or153* OpenGL context.154*155* On X11, SDL rolls its own dialog box with X11 primitives instead of a156* formal toolkit like GTK+ or Qt.157*158* Note that if SDL_Init() would fail because there isn't any available video159* target, this function is likely to fail for the same reasons. If this is a160* concern, check the return value from this function and fall back to writing161* to stderr if you can.162*163* \param messageboxdata the SDL_MessageBoxData structure with title, text and164* other options.165* \param buttonid the pointer to which user id of hit button should be166* copied.167* \returns true on success or false on failure; call SDL_GetError() for more168* information.169*170* \since This function is available since SDL 3.2.0.171*172* \sa SDL_ShowSimpleMessageBox173*/174extern SDL_DECLSPEC bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);175176/**177* Display a simple modal message box.178*179* If your needs aren't complex, this function is preferred over180* SDL_ShowMessageBox.181*182* `flags` may be any of the following:183*184* - `SDL_MESSAGEBOX_ERROR`: error dialog185* - `SDL_MESSAGEBOX_WARNING`: warning dialog186* - `SDL_MESSAGEBOX_INFORMATION`: informational dialog187*188* This function should be called on the thread that created the parent189* window, or on the main thread if the messagebox has no parent. It will190* block execution of that thread until the user clicks a button or closes the191* messagebox.192*193* This function may be called at any time, even before SDL_Init(). This makes194* it useful for reporting errors like a failure to create a renderer or195* OpenGL context.196*197* On X11, SDL rolls its own dialog box with X11 primitives instead of a198* formal toolkit like GTK+ or Qt.199*200* Note that if SDL_Init() would fail because there isn't any available video201* target, this function is likely to fail for the same reasons. If this is a202* concern, check the return value from this function and fall back to writing203* to stderr if you can.204*205* \param flags an SDL_MessageBoxFlags value.206* \param title UTF-8 title text.207* \param message UTF-8 message text.208* \param window the parent window, or NULL for no parent.209* \returns true on success or false on failure; call SDL_GetError() for more210* information.211*212* \since This function is available since SDL 3.2.0.213*214* \sa SDL_ShowMessageBox215*/216extern SDL_DECLSPEC bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window);217218219/* Ends C function definitions when using C++ */220#ifdef __cplusplus221}222#endif223#include <SDL3/SDL_close_code.h>224225#endif /* SDL_messagebox_h_ */226227228