MCPcopy Create free account
hub / github.com/ddnet/ddnet / ShowMessageBoxImpl

Function ShowMessageBoxImpl

src/engine/client/backend_sdl.cpp:846–879  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

844}
845
846static std::optional<int> ShowMessageBoxImpl(const IGraphics::CMessageBox &MessageBox, SDL_Window *pWindow)
847{
848 dbg_assert(!MessageBox.m_vButtons.empty(), "At least one button is required");
849
850 std::vector<SDL_MessageBoxButtonData> vButtonData;
851 vButtonData.reserve(MessageBox.m_vButtons.size());
852 for(const auto &Button : MessageBox.m_vButtons)
853 {
854 SDL_MessageBoxButtonData ButtonData{};
855 ButtonData.buttonid = vButtonData.size();
856 ButtonData.flags = (Button.m_Confirm ? SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT : 0) | (Button.m_Cancel ? SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT : 0);
857 ButtonData.text = Button.m_pLabel;
858 vButtonData.emplace_back(ButtonData);
859 }
860#if defined(CONF_FAMILY_WINDOWS)
861 // TODO SDL3: The order of buttons is not defined by default, but the flags returned by MessageBoxTypeToSdlFlags do not work together
862 // with SDL_MESSAGEBOX_BUTTONS_LEFT_TO_RIGHT with SDL2 on various platforms. Windows appears to be the only platform that
863 // lays out buttons from right to left by default, so we reverse the order manually.
864 std::reverse(vButtonData.begin(), vButtonData.end());
865#endif
866 SDL_MessageBoxData MessageBoxData{};
867 MessageBoxData.title = MessageBox.m_pTitle;
868 MessageBoxData.message = MessageBox.m_pMessage;
869 MessageBoxData.flags = MessageBoxTypeToSdlFlags(MessageBox.m_Type);
870 MessageBoxData.numbuttons = vButtonData.size();
871 MessageBoxData.buttons = vButtonData.data();
872 MessageBoxData.window = pWindow;
873 int ButtonId = -1;
874 if(SDL_ShowMessageBox(&MessageBoxData, &ButtonId) != 0)
875 {
876 return std::nullopt;
877 }
878 return ButtonId;
879}
880
881std::optional<int> ShowMessageBoxWithoutGraphics(const IGraphics::CMessageBox &MessageBox)
882{

Callers 2

ShowMessageBoxMethod · 0.85

Calls 3

MessageBoxTypeToSdlFlagsFunction · 0.85
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected