1 /*
2     DSDL
3     Copyright (C) 2025 Inochi2D Project <luna@foxgirls.gay>
4 
5     This software is provided 'as-is', without any express or implied
6     warranty.  In no event will the authors be held liable for any damages
7     arising from the use of this software.
8 
9     Permission is granted to anyone to use this software for any purpose,
10     including commercial applications, and to alter it and redistribute it
11     freely, subject to the following restrictions:
12 
13     1. The origin of this software must not be misrepresented; you must not
14         claim that you wrote the original software. If you use this software
15         in a product, an acknowledgment in the product documentation would be
16         appreciated but is not required.
17     2. Altered source versions must be plainly marked as such, and must not be
18         misrepresented as being the original software.
19     3. This notice may not be removed or altered from any source distribution.
20 
21     ==========================================================================
22 
23     Simple DirectMedia Layer
24     Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
25 
26     This software is provided 'as-is', without any express or implied
27     warranty.  In no event will the authors be held liable for any damages
28     arising from the use of this software.
29 
30     Permission is granted to anyone to use this software for any purpose,
31     including commercial applications, and to alter it and redistribute it
32     freely, subject to the following restrictions:
33 
34     1. The origin of this software must not be misrepresented; you must not
35         claim that you wrote the original software. If you use this software
36         in a product, an acknowledgment in the product documentation would be
37         appreciated but is not required.
38     2. Altered source versions must be plainly marked as such, and must not be
39         misrepresented as being the original software.
40     3. This notice may not be removed or altered from any source distribution.
41 */
42 
43 /**
44     SDL MessageBox
45 
46     See_Also:
47         $(LINK2 https://wiki.libsdl.org/SDL3/CategoryMessageBox, SDL3 MessageBox Documentation)
48     
49     Copyright: © 2025 Inochi2D Project, © 1997-2025 Sam Lantinga
50     License: Subject to the terms of the Zlib License, as written in the LICENSE file.
51     Authors: 
52         Luna Nielsen
53 */
54 module sdl.messagebox;
55 import sdl.stdc;
56 import sdl.video;
57 
58 extern(C) nothrow @nogc:
59 
60 /**
61     Message box flags.
62 
63     If supported will display warning icon, etc.
64 */
65 enum SDL_MessageBoxFlags : Uint32 {
66     
67     /**
68         Error dialog
69     */
70     SDL_MESSAGEBOX_ERROR =                    0x00000010u,
71     
72     /**
73         Warning dialog
74     */
75     SDL_MESSAGEBOX_WARNING =                  0x00000020u,
76     
77     /**
78         Informational dialog
79     */
80     SDL_MESSAGEBOX_INFORMATION =              0x00000040u,
81     
82     /**
83         Buttons placed left to right
84     */
85     SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT =    0x00000080u,
86     
87     /**
88         Buttons placed right to left
89     */
90     SDL_MESSAGEBOX_BUTTONS_RIGHT_TO_LEFT =    0x00000100u,
91 }
92 
93 /**
94     SDL_MessageBoxButtonData flags.
95 */
96 alias SDL_MessageBoxButtonFlags = Uint32;
97 
98 /**
99     Marks the default button when return is hit
100 */
101 enum SDL_MessageBoxButtonFlags SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001u;
102 
103 /**
104     Marks the default button when escape is hit
105 */
106 enum SDL_MessageBoxButtonFlags SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002u;
107 
108 /**
109     Individual button data.
110 */
111 struct SDL_MessageBoxButtonData {
112     
113     /**
114         Flags
115     */
116     SDL_MessageBoxButtonFlags flags;
117     
118     /**
119         User defined button id (value returned via SDL_ShowMessageBox)
120     */
121     int buttonID;        
122     
123     /**
124         The UTF-8 button text
125     */
126     const(char)* text;   
127 } 
128 
129 /**
130     RGB value used in a message box color scheme
131 */
132 struct SDL_MessageBoxColor {
133 
134     /**
135         Red color channel.
136     */
137     Uint8 r;
138     
139     /**
140         Green color channel.
141     */
142     Uint8 g;
143     
144     /**
145         Blue color channel.
146     */
147     Uint8 b;
148 }
149 
150 /**
151     An enumeration of indices inside the colors array of
152     SDL_MessageBoxColorScheme.
153 */
154 enum SDL_MessageBoxColorType : size_t {
155     SDL_MESSAGEBOX_COLOR_BACKGROUND,
156     SDL_MESSAGEBOX_COLOR_TEXT,
157     SDL_MESSAGEBOX_COLOR_BUTTON_BORDER,
158     SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND,
159     SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED,
160     SDL_MESSAGEBOX_COLOR_COUNT                    /**< Size of the colors array of SDL_MessageBoxColorScheme. */
161 }
162 
163 /**
164     A set of colors to use for message box dialogs
165 */
166 struct SDL_MessageBoxColorScheme {
167 
168     /**
169         Colors
170     */
171     SDL_MessageBoxColor[cast(size_t)SDL_MessageBoxColorType.SDL_MESSAGEBOX_COLOR_COUNT] colors;
172 }
173 
174 /**
175     MessageBox structure containing title, text, window, etc.
176 */
177 struct SDL_MessageBoxData {
178 
179     /**
180         Flags
181     */
182     SDL_MessageBoxFlags flags;
183     
184     /**
185         Parent window, can be NULL
186     */
187     SDL_Window *window;                  
188     
189     /**
190         UTF-8 title
191     */
192     const(char)* title;                  
193     
194     /**
195         UTF-8 message text
196     */
197     const(char)* message;                
198 
199     /**
200         Number of window buttons
201     */
202     int numbuttons;
203 
204     /**
205         Array of window buttons
206     */
207     const(SDL_MessageBoxButtonData)* buttons;
208 
209     /**
210         SDL_MessageBoxColorScheme, can be NULL to use system settings
211     */
212     const(SDL_MessageBoxColorScheme)* colorScheme;
213 }
214 
215 /**
216     Create a modal message box.
217 
218     If your needs aren't complex, it might be easier to use
219     SDL_ShowSimpleMessageBox.
220 
221     This function should be called on the thread that created the parent
222     window, or on the main thread if the messagebox has no parent. It will
223     block execution of that thread until the user clicks a button or closes the
224     messagebox.
225 
226     This function may be called at any time, even before SDL_Init(). This makes
227     it useful for reporting errors like a failure to create a renderer or
228     OpenGL context.
229 
230     On X11, SDL rolls its own dialog box with X11 primitives instead of a
231     formal toolkit like GTK+ or Qt.
232 
233     Note that if SDL_Init() would fail because there isn't any available video
234     target, this function is likely to fail for the same reasons. If this is a
235     concern, check the return value from this function and fall back to writing
236     to stderr if you can.
237 
238     Params:
239         messageboxdata =    the SDL_MessageBoxData structure with title, text and
240                             other options.
241         buttonid =          the pointer to which user id of hit button should be
242                             copied.
243     
244     Returns:
245         true on success or false on failure; call SDL_GetError() for more
246         information.
247 
248     See_Also:
249         $(D SDL_ShowSimpleMessageBox)
250 */
251 extern bool SDL_ShowMessageBox(const(SDL_MessageBoxData)* messageboxdata, int *buttonid);
252 
253 /**
254     Display a simple modal message box.
255 
256     If your needs aren't complex, this function is preferred over
257     SDL_ShowMessageBox.
258 
259     `flags` may be any of the following:
260 
261     - `SDL_MESSAGEBOX_ERROR`: error dialog
262     - `SDL_MESSAGEBOX_WARNING`: warning dialog
263     - `SDL_MESSAGEBOX_INFORMATION`: informational dialog
264 
265     This function should be called on the thread that created the parent
266     window, or on the main thread if the messagebox has no parent. It will
267     block execution of that thread until the user clicks a button or closes the
268     messagebox.
269 
270     This function may be called at any time, even before SDL_Init(). This makes
271     it useful for reporting errors like a failure to create a renderer or
272     OpenGL context.
273 
274     On X11, SDL rolls its own dialog box with X11 primitives instead of a
275     formal toolkit like GTK+ or Qt.
276 
277     Note that if SDL_Init() would fail because there isn't any available video
278     target, this function is likely to fail for the same reasons. If this is a
279     concern, check the return value from this function and fall back to writing
280     to stderr if you can.
281 
282     Params:
283         flags =     an SDL_MessageBoxFlags value.
284         title =     UTF-8 title text.
285         message =   UTF-8 message text.
286         window =    the parent window, or NULL for no parent.
287     
288     Returns:
289         true on success or false on failure; call SDL_GetError() for more
290         information.
291 
292     See_Also:
293         $(D SDL_ShowMessageBox)
294 */
295 extern bool SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const(char)* title, const(char)* message, SDL_Window *window);