SDL2消息框未显示颜色,父级不起作用

时间:2018-03-11 01:23:10

标签: windows colors parent sdl-2 messagebox

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;
    }
}

但是,消息框没有颜色
它也可能没有父母(不在主窗口的顶部)
不应该阻止我点击父母,我的意思就像 .NET 中的对话框一样 无论如何, SDL 中父窗口的含义是什么?

Windows SDL2 MessageBox with no parent

正如您所见,我从游戏窗口最小化游戏(消息框 阻止我) 这个灰色消息框不是,它只是屏幕上的某个地方,没有父母可以持有它。

我正在处理最新的 SDL2 ,使用颜色就像将它们设置为NULL一样

我甚至尝试从documentation复制整个示例并用它替换所有closeWindowMessageBox()函数,除了父项,替换为 mainWindow

,现在父母工作了(在我点击按钮之前阻止其他事件发生)。 enter image description here

我认为因为我需要首先初始化 mainWindow closeWindowMessageBox()初始化后调用mainWindow,因此它可以正常工作

不同之处在于,当在标题中定义它们时,它会取mainWindow的当前值NULL,希望如果有人遇到同样的问题会有帮助。

仍然没有颜色,我错过了什么?谢谢。

1 个答案:

答案 0 :(得分:1)

Windows 中无法使用配色方案功能,或者至少暂时无法使用。