代码之家  ›  专栏  ›  技术社区  ›  Beyondo

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

  •  0
  • Beyondo  · 技术社区  · 8 年前
    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;
        }
    }
    

    但是,消息框没有颜色
    它可能也没有父级(不在主窗口顶部)
    难道这不应该阻止我点击家长吗?我的意思是,就像 。净额
    中父窗口的含义是什么 SDL公司 无论如何?

    Windows SDL2 MessageBox with no parent

    如你所见 最小化 游戏窗口中的游戏(消息框 没有 阻止我)
    还有这个 灰色 消息框为 ,它就在屏幕上的某个地方,没有家长来拿着它。

    我正在研究最新的 SDL2 ,使用 父母亲 颜色 就像让他们 NULL

    我甚至试着从 documentation 并替换所有 closeWindowMessageBox() 函数,除父函数外,替换为 主窗口

    ,现在父级已工作(在我单击按钮之前防止其他事件发生)。 enter image description here

    我想因为我需要 初始化 这个 主窗口 第一
    closeWindowMessageBox() 在初始化后调用 mainWindow 所以成功了

    区别在于,当在标题中定义它们时,它将采用 主窗口 这是 空值 ,希望如果有人有同样的问题,这会有所帮助。

    还是没有颜色 ,我错过了什么?,谢谢

    1 回复  |  直到 8 年前
        1
  •  1
  •   Beyondo    8 年前

    颜色方案功能在中不可用 Windows ,或者至少现在是这样。