SDL_messagebox.h 6.6 KB

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