SDL_messagebox.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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. * Message box support routines.
  22. */
  23. #ifndef SDL_messagebox_h_
  24. #define SDL_messagebox_h_
  25. #include <SDL3/SDL_stdinc.h>
  26. #include <SDL3/SDL_error.h>
  27. #include <SDL3/SDL_video.h> /* For SDL_Window */
  28. #include <SDL3/SDL_begin_code.h>
  29. /* Set up for C function definitions, even when using C++ */
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /**
  34. * SDL_MessageBox flags.
  35. *
  36. * If supported will display warning icon, etc.
  37. *
  38. * \since This datatype is available since SDL 3.0.0.
  39. */
  40. typedef Uint32 SDL_MessageBoxFlags;
  41. #define SDL_MESSAGEBOX_ERROR 0x00000010u /**< error dialog */
  42. #define SDL_MESSAGEBOX_WARNING 0x00000020u /**< warning dialog */
  43. #define SDL_MESSAGEBOX_INFORMATION 0x00000040u /**< informational dialog */
  44. #define SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT 0x00000080u /**< buttons placed left to right */
  45. #define SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT 0x00000100u /**< buttons placed right to left */
  46. /**
  47. * SDL_MessageBoxButtonData flags.
  48. *
  49. * \since This datatype is available since SDL 3.0.0.
  50. */
  51. typedef Uint32 SDL_MessageBoxButtonFlags;
  52. #define SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT 0x00000001u /**< Marks the default button when return is hit */
  53. #define SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT 0x00000002u /**< Marks the default button when escape is hit */
  54. /**
  55. * Individual button data.
  56. *
  57. * \since This struct is available since SDL 3.0.0.
  58. */
  59. typedef struct SDL_MessageBoxButtonData
  60. {
  61. SDL_MessageBoxButtonFlags flags;
  62. int buttonID; /**< User defined button id (value returned via SDL_ShowMessageBox) */
  63. const char *text; /**< The UTF-8 button text */
  64. } SDL_MessageBoxButtonData;
  65. /**
  66. * RGB value used in a message box color scheme
  67. *
  68. * \since This struct is available since SDL 3.0.0.
  69. */
  70. typedef struct SDL_MessageBoxColor
  71. {
  72. Uint8 r, g, b;
  73. } SDL_MessageBoxColor;
  74. /**
  75. * An enumeration of indices inside the colors array of
  76. * SDL_MessageBoxColorScheme.
  77. */
  78. typedef enum SDL_MessageBoxColorType
  79. {
  80. SDL_MESSAGEBOX_COLOR_BACKGROUND,
  81. SDL_MESSAGEBOX_COLOR_TEXT,
  82. SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
  83. SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
  84. SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
  85. SDL_MESSAGEBOX_COLOR_COUNT /**< Size of the colors array of SDL_MessageBoxColorScheme. */
  86. } SDL_MessageBoxColorType;
  87. /**
  88. * A set of colors to use for message box dialogs
  89. *
  90. * \since This struct is available since SDL 3.0.0.
  91. */
  92. typedef struct SDL_MessageBoxColorScheme
  93. {
  94. SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_COUNT];
  95. } SDL_MessageBoxColorScheme;
  96. /**
  97. * MessageBox structure containing title, text, window, etc.
  98. *
  99. * \since This struct is available since SDL 3.0.0.
  100. */
  101. typedef struct SDL_MessageBoxData
  102. {
  103. SDL_MessageBoxFlags flags;
  104. SDL_Window *window; /**< Parent window, can be NULL */
  105. const char *title; /**< UTF-8 title */
  106. const char *message; /**< UTF-8 message text */
  107. int numbuttons;
  108. const SDL_MessageBoxButtonData *buttons;
  109. const SDL_MessageBoxColorScheme *colorScheme; /**< SDL_MessageBoxColorScheme, can be NULL to use system settings */
  110. } SDL_MessageBoxData;
  111. /**
  112. * Create a modal message box.
  113. *
  114. * If your needs aren't complex, it might be easier to use
  115. * SDL_ShowSimpleMessageBox.
  116. *
  117. * This function should be called on the thread that created the parent
  118. * window, or on the main thread if the messagebox has no parent. It will
  119. * block execution of that thread until the user clicks a button or closes the
  120. * messagebox.
  121. *
  122. * This function may be called at any time, even before SDL_Init(). This makes
  123. * it useful for reporting errors like a failure to create a renderer or
  124. * OpenGL context.
  125. *
  126. * On X11, SDL rolls its own dialog box with X11 primitives instead of a
  127. * formal toolkit like GTK+ or Qt.
  128. *
  129. * Note that if SDL_Init() would fail because there isn't any available video
  130. * target, this function is likely to fail for the same reasons. If this is a
  131. * concern, check the return value from this function and fall back to writing
  132. * to stderr if you can.
  133. *
  134. * \param messageboxdata the SDL_MessageBoxData structure with title, text and
  135. * other options.
  136. * \param buttonid the pointer to which user id of hit button should be
  137. * copied.
  138. * \returns true on success or false on failure; call SDL_GetError() for more
  139. * information.
  140. *
  141. * \since This function is available since SDL 3.0.0.
  142. *
  143. * \sa SDL_ShowSimpleMessageBox
  144. */
  145. extern SDL_DECLSPEC bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid);
  146. /**
  147. * Display a simple modal message box.
  148. *
  149. * If your needs aren't complex, this function is preferred over
  150. * SDL_ShowMessageBox.
  151. *
  152. * `flags` may be any of the following:
  153. *
  154. * - `SDL_MESSAGEBOX_ERROR`: error dialog
  155. * - `SDL_MESSAGEBOX_WARNING`: warning dialog
  156. * - `SDL_MESSAGEBOX_INFORMATION`: informational dialog
  157. *
  158. * This function should be called on the thread that created the parent
  159. * window, or on the main thread if the messagebox has no parent. It will
  160. * block execution of that thread until the user clicks a button or closes the
  161. * messagebox.
  162. *
  163. * This function may be called at any time, even before SDL_Init(). This makes
  164. * it useful for reporting errors like a failure to create a renderer or
  165. * OpenGL context.
  166. *
  167. * On X11, SDL rolls its own dialog box with X11 primitives instead of a
  168. * formal toolkit like GTK+ or Qt.
  169. *
  170. * Note that if SDL_Init() would fail because there isn't any available video
  171. * target, this function is likely to fail for the same reasons. If this is a
  172. * concern, check the return value from this function and fall back to writing
  173. * to stderr if you can.
  174. *
  175. * \param flags an SDL_MessageBoxFlags value.
  176. * \param title uTF-8 title text.
  177. * \param message uTF-8 message text.
  178. * \param window the parent window, or NULL for no parent.
  179. * \returns true on success or false on failure; call SDL_GetError() for more
  180. * information.
  181. *
  182. * \since This function is available since SDL 3.0.0.
  183. *
  184. * \sa SDL_ShowMessageBox
  185. */
  186. extern SDL_DECLSPEC bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window);
  187. /* Ends C function definitions when using C++ */
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #include <SDL3/SDL_close_code.h>
  192. #endif /* SDL_messagebox_h_ */