Debian Codegraph @

common/arch/sdl/messagebox.cpp

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 /*
8 * Display an error or warning messagebox using the SDL2 messagebox function.
9 *
10 */
11
12 #include <SDL.h>
13 #include "window.h"
14 #include "event.h"
15 #include "messagebox.h"
16
17 namespace dcx {
18
19 static void display_sdl_alert(const char *message, int error)
20 {
21 window *wind;
22
23 // Handle Descent's windows properly
24 if ((wind = window_get_front()))
25 wind->send_event(d_event{event_type::window_deactivated});
26
27 int fullscreen = (grd_curscreen && gr_check_fullscreen());
28 if (fullscreen)
29 gr_toggle_fullscreen();
30
31 SDL_ShowSimpleMessageBox(error?SDL_MESSAGEBOX_ERROR:SDL_MESSAGEBOX_WARNING, error?"Sorry, a critical error has occurred.":"Attention!", message, NULL);
32
33 if ((wind = window_get_front()))
34 wind->send_event(d_event{event_type::window_activated});
35
36 if (!error && fullscreen)
37 gr_toggle_fullscreen();
38 }
39
40 void msgbox_warning(const std::span<const char> message)
41 {
42 display_sdl_alert(message.data(), 0);
43 }
44
45 void msgbox_error(const char *message)
46 {
47 display_sdl_alert(message, 1);
48 }
49
50 }