SDL_Window* mainWindow = NULL;
void cleanup();
const SDL_MessageBoxButtonData msgBox_CloseWindow_Buttons [] = {
{0, 0, "Nope"},
{SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "Yup"},
{SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "Cancel it"},
};
const SDL_MessageBoxColorScheme msgBox_CloseWindow_ColorScheme = {
{
// SDL_MESSAGEBOX_COLOR_BACKGROUND
{255, 0, 0},
// SDL_MESSAGEBOX_COLOR_TEXT
{0, 255, 0},
// SDL_MESSAGEBOX_COLOR_BUTTON_BORDER
{255, 255, 0},
// SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND
{0, 0, 255},
// SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED
{255, 0, 255}
}
};
const SDL_MessageBoxData msgBox_CloseWindow_Data = {
// flag
SDL_MESSAGEBOX_INFORMATION,
// window
mainWindow,
// title
"Game Terminating",
// message
"Do you really want to close this way?",
// number of buttons
SDL_arraysize(msgBox_CloseWindow_Buttons),
msgBox_CloseWindow_Buttons,
&msgBox_CloseWindow_ColorScheme
};
void closeWindowMessageBox()
{
if(SDL_ShowMessageBox(&msgBox_CloseWindow_Data, &nbutton) < 0)
{
SDL_Log("error displaying box");
exit(1);
}
switch (nbutton)
{
case -1:
SDL_Log("Game Closing - No Selection");
break;
case 0:
SDL_Log("Game Closing - Rejected");
break;
case 1:
SDL_Log("Game Closing - Approved");
cleanup();
break;
case 2:
SDL_Log("Game Closing - Canceled");
break;
}
}
void Game::ProcessEvents(SDL_Event event)
{
switch(event.key.keysym.sym)
{
...
}
switch(event.type)
{
case SDL_QUIT:
closeWindowMessageBox();
break;
}
}
However, The message box is with no colors
It's likely no parent too (Not on the top of the main window)
Shouldn't it prevent me from clicking on the parent, I mean like a Dialog Box in .NET
What's the meaning of a parent window in SDL anyways?
As you can see, I minimized the game from the game window (message box did not prevent me)
and this gray message box is not, it's just somewhere on the screen alone with no parent to hold it.
I'm working on the latest SDL2, using a parent or colors is like setting them to NULL
.
I even tried copying the whole example from the documentation and replacing all the closeWindowMessageBox()
function with it, except the parent, replaced with mainWindow.
Well, now the parent worked (prevents other events from occurring until I click a button).
I think cause I needed to initialize the mainWindow first
closeWindowMessageBox()
is called after the initialization of mainWindow
so it worked
the difference is that when defining them in the header it'd take the current value of mainWindow
which is NULL
, hope it helps if someone had the same problem.
Still no colors, What do I missed?, thanks.
The color schemes features aren't available in Windows, or at least for now.