18
#include <SDL3/SDL_main.h>
19
#include <SDL3/SDL_test.h>
33
button_messagebox(void *eventNumber)
35
const SDL_MessageBoxButtonData buttons[] = {
36
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
39
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
44
SDL_MessageBoxData data = {
45
SDL_MESSAGEBOX_INFORMATION,
48
"This is a custom messagebox",
56
data.buttons = buttons;
58
data.message = "This is a custom messagebox from a background thread.";
61
success = SDL_ShowMessageBox(&data, &button);
63
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
66
event.type = (Uint32)(intptr_t)eventNumber;
67
SDL_PushEvent(&event);
73
SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel"
78
event.type = (Uint32)(intptr_t)eventNumber;
79
SDL_PushEvent(&event);
85
int main(int argc, char *argv[])
88
SDLTest_CommonState *state;
91
state = SDLTest_CommonCreateState(argv, 0);
97
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
100
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
104
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
106
"This is a simple error MessageBox",
109
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
113
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
115
"This is a simple MessageBox with a newline:\r\nHello world!",
118
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
122
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
127
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
131
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
136
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
141
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
142
"UTF-8 Simple MessageBox",
143
"Unicode text: '牛肉西蘭花' ...",
146
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
151
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
152
"UTF-8 Simple MessageBox",
153
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
156
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
161
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
163
"Unicode text in the title.",
166
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
170
button_messagebox(NULL);
178
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
179
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
185
Uint32 eventNumber = SDL_RegisterEvents(1);
186
SDL_Thread *thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void *)(uintptr_t)eventNumber);
188
while (SDL_WaitEvent(&event)) {
189
if (event.type == eventNumber) {
194
SDL_WaitThread(thread, &status);
196
SDL_Log("Message box thread return %i\n", status);
202
SDL_Window *window = SDL_CreateWindow("Test", 640, 480, 0);
207
SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL);
208
SDL_RenderPresent(renderer);
210
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
212
"This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.",
215
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
219
while (SDL_WaitEvent(&event)) {
220
if (event.type == SDL_EVENT_QUIT || event.type == SDL_EVENT_KEY_UP) {
227
SDLTest_CommonDestroyState(state);