SDL_messagebox.h 7.1 KB

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