SDL_messagebox.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryMessagebox
  20. *
  21. * SDL offers a simple message box API, which is useful for simple alerts,
  22. * such as informing the user when something fatal happens at startup without
  23. * the need to build a UI for it (or informing the user _before_ your UI is
  24. * ready).
  25. *
  26. * These message boxes are native system dialogs where possible.
  27. *
  28. * There is both a customizable function (SDL_ShowMessageBox()) that offers
  29. * lots of options for what to display and reports on what choice the user
  30. * made, and also a much-simplified version (SDL_ShowSimpleMessageBox()),
  31. * merely takes a text message and title, and waits until the user presses a
  32. * single "OK" UI button. Often, this is all that is necessary.
  33. */
  34. #ifndef SDL_messagebox_h_
  35. #define SDL_messagebox_h_
  36. #include <SDL3/SDL_stdinc.h>
  37. #include <SDL3/SDL_error.h>
  38. #include <SDL3/SDL_video.h> /* For SDL_Window */
  39. #include <SDL3/SDL_begin_code.h>
  40. /* Set up for C function definitions, even when using C++ */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /**
  45. * Message box flags.
  46. *
  47. * If supported will display warning icon, etc.
  48. *
  49. * \since This datatype is available since SDL 3.2.0.
  50. */
  51. typedef Uint32 SDL_MessageBoxFlags;
  52. #define SDL_MESSAGEBOX_ERROR 0x00000010u /**< error dialog */
  53. #define SDL_MESSAGEBOX_WARNING 0x00000020u /**< warning dialog */
  54. #define SDL_MESSAGEBOX_INFORMATION 0x00000040u /**< informational dialog */
  55. #define SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT 0x00000080u /**< buttons placed left to right */
  56. #define SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT 0x00000100u /**< buttons placed right to left */
  57. /**
  58. * SDL_MessageBoxButtonData flags.
  59. *
  60. * \since This datatype is available since SDL 3.2.0.
  61. */
  62. typedef Uint32 SDL_MessageBoxButtonFlags;
  63. #define SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT 0x00000001u /**< Marks the default button when return is hit */
  64. #define SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT 0x00000002u /**< Marks the default button when escape is hit */
  65. /**
  66. * Individual button data.
  67. *
  68. * \since This struct is available since SDL 3.2.0.
  69. */
  70. typedef struct SDL_MessageBoxButtonData
  71. {
  72. SDL_MessageBoxButtonFlags flags;
  73. int buttonID; /**< User defined button id (value returned via SDL_ShowMessageBox) */
  74. const char *text; /**< The UTF-8 button text */
  75. } SDL_MessageBoxButtonData;
  76. /**
  77. * RGB value used in a message box color scheme
  78. *
  79. * \since This struct is available since SDL 3.2.0.
  80. */
  81. typedef struct SDL_MessageBoxColor
  82. {
  83. Uint8 r, g, b;
  84. } SDL_MessageBoxColor;
  85. /**
  86. * An enumeration of indices inside the colors array of
  87. * SDL_MessageBoxColorScheme.
  88. */
  89. typedef enum SDL_MessageBoxColorType
  90. {
  91. SDL_MESSAGEBOX_COLOR_BACKGROUND,
  92. SDL_MESSAGEBOX_COLOR_TEXT,
  93. SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
  94. SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
  95. SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
  96. SDL_MESSAGEBOX_COLOR_COUNT /**< Size of the colors array of SDL_MessageBoxColorScheme. */
  97. } SDL_MessageBoxColorType;
  98. /**
  99. * A set of colors to use for message box dialogs
  100. *
  101. * \since This struct is available since SDL 3.2.0.
  102. */
  103. typedef struct SDL_MessageBoxColorScheme
  104. {
  105. SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_COUNT];
  106. } SDL_MessageBoxColorScheme;
  107. /**
  108. * MessageBox structure containing title, text, window, etc.
  109. *
  110. * \since This struct is available since SDL 3.2.0.
  111. */
  112. typedef struct SDL_MessageBoxData
  113. {
  114. SDL_MessageBoxFlags flags;
  115. SDL_Window *window; /**< Parent window, can be NULL */
  116. const char *title; /**< UTF-8 title */
  117. const char *message; /**< UTF-8 message text */
  118. int numbuttons;
  119. const SDL_MessageBoxButtonData *buttons;
  120. const SDL_MessageBoxColorScheme *colorScheme; /**< SDL_MessageBoxColorScheme, can be NULL to use system settings */
  121. } SDL_MessageBoxData;
  122. /**
  123. * Create a modal message box.
  124. *
  125. * If your needs aren't complex, it might be easier to use
  126. * SDL_ShowSimpleMessageBox.
  127. *
  128. * This function should be called on the thread that created the parent
  129. * window, or on the main thread if the messagebox has no parent. It will
  130. * block execution of that thread until the user clicks a button or closes the
  131. * messagebox.
  132. *
  133. * This function may be called at any time, even before SDL_Init(). This makes
  134. * it useful for reporting errors like a failure to create a renderer or
  135. * OpenGL context.
  136. *
  137. * On X11, SDL rolls its own dialog box with X11 primitives instead of a
  138. * formal toolkit like GTK+ or Qt.
  139. *
  140. * Note that if SDL_Init() would fail because there isn't any available video
  141. * target, this function is likely to fail for the same reasons. If this is a
  142. * concern, check the return value from this function and fall back to writing
  143. * to stderr if you can.
  144. *
  145. * \param messageboxdata the SDL_MessageBoxData structure with title, text and
  146. * other options.
  147. * \param buttonid the pointer to which user id of hit button should be
  148. * copied.
  149. * \returns true on success or false on failure; call SDL_GetError() for more
  150. * information.
  151. *
  152. * \since This function is available since SDL 3.2.0.
  153. *
  154. * \sa SDL_ShowSimpleMessageBox
  155. */
  156. extern SDL_DECLSPEC bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
  157. /**
  158. * Display a simple modal message box.
  159. *
  160. * If your needs aren't complex, this function is preferred over
  161. * SDL_ShowMessageBox.
  162. *
  163. * `flags` may be any of the following:
  164. *
  165. * - `SDL_MESSAGEBOX_ERROR`: error dialog
  166. * - `SDL_MESSAGEBOX_WARNING`: warning dialog
  167. * - `SDL_MESSAGEBOX_INFORMATION`: informational dialog
  168. *
  169. * This function should be called on the thread that created the parent
  170. * window, or on the main thread if the messagebox has no parent. It will
  171. * block execution of that thread until the user clicks a button or closes the
  172. * messagebox.
  173. *
  174. * This function may be called at any time, even before SDL_Init(). This makes
  175. * it useful for reporting errors like a failure to create a renderer or
  176. * OpenGL context.
  177. *
  178. * On X11, SDL rolls its own dialog box with X11 primitives instead of a
  179. * formal toolkit like GTK+ or Qt.
  180. *
  181. * Note that if SDL_Init() would fail because there isn't any available video
  182. * target, this function is likely to fail for the same reasons. If this is a
  183. * concern, check the return value from this function and fall back to writing
  184. * to stderr if you can.
  185. *
  186. * \param flags an SDL_MessageBoxFlags value.
  187. * \param title UTF-8 title text.
  188. * \param message UTF-8 message text.
  189. * \param window the parent window, or NULL for no parent.
  190. * \returns true on success or false on failure; call SDL_GetError() for more
  191. * information.
  192. *
  193. * \since This function is available since SDL 3.2.0.
  194. *
  195. * \sa SDL_ShowMessageBox
  196. */
  197. extern SDL_DECLSPEC bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window);
  198. /* Ends C function definitions when using C++ */
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #include <SDL3/SDL_close_code.h>
  203. #endif /* SDL_messagebox_h_ */