SDL_messagebox.h 6.7 KB

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