From a2a766744240b1f5aa77e2092ab700a6b28cd8b9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Jan 2024 19:25:25 +0100 Subject: [PATCH] added render backend selection to the new IWAD picker. Unlike VkDoom we still need this. --- .../widgets/checkboxlabel/checkboxlabel.h | 4 + .../widgets/checkboxlabel/checkboxlabel.cpp | 4 +- src/common/platform/win32/i_system.cpp | 134 ------------------ src/common/widgets/launcherwindow.cpp | 62 ++++++++ src/common/widgets/launcherwindow.h | 9 ++ 5 files changed, 78 insertions(+), 135 deletions(-) diff --git a/libraries/ZWidget/include/zwidget/widgets/checkboxlabel/checkboxlabel.h b/libraries/ZWidget/include/zwidget/widgets/checkboxlabel/checkboxlabel.h index 8bcaf5efbe..03d9089ebe 100644 --- a/libraries/ZWidget/include/zwidget/widgets/checkboxlabel/checkboxlabel.h +++ b/libraries/ZWidget/include/zwidget/widgets/checkboxlabel/checkboxlabel.h @@ -16,6 +16,8 @@ public: void Toggle(); double GetPreferredHeight() const; + std::function FuncChanged; + void SetRadioStyle(bool on) { radiostyle = on; } protected: void OnPaint(Canvas* canvas) override; @@ -27,5 +29,7 @@ protected: private: std::string text; bool checked = false; + bool radiostyle = false; bool mouseDownActive = false; + }; diff --git a/libraries/ZWidget/src/widgets/checkboxlabel/checkboxlabel.cpp b/libraries/ZWidget/src/widgets/checkboxlabel/checkboxlabel.cpp index 29c62cced4..deed9d5078 100644 --- a/libraries/ZWidget/src/widgets/checkboxlabel/checkboxlabel.cpp +++ b/libraries/ZWidget/src/widgets/checkboxlabel/checkboxlabel.cpp @@ -84,6 +84,8 @@ void CheckboxLabel::OnKeyUp(EInputKey key) void CheckboxLabel::Toggle() { - checked = !checked; + bool oldchecked = checked; + checked = radiostyle? true : !checked; Update(); + if (checked != oldchecked && FuncChanged) FuncChanged(checked); } diff --git a/src/common/platform/win32/i_system.cpp b/src/common/platform/win32/i_system.cpp index e2d57b51d4..b6ea656e78 100644 --- a/src/common/platform/win32/i_system.cpp +++ b/src/common/platform/win32/i_system.cpp @@ -344,131 +344,6 @@ static void SetQueryIWad(HWND dialog) queryiwad = query; } -//========================================================================== -// -// IWADBoxCallback -// -// Dialog proc for the IWAD selector. -// -//========================================================================== -static int* pAutoloadflags; - -BOOL CALLBACK IWADBoxCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - int& flags = *pAutoloadflags;; - - HWND ctrl; - int i; - - switch (message) - { - case WM_INITDIALOG: - // Add our program name to the window title - { - WCHAR label[256]; - FString newlabel; - - GetWindowTextW(hDlg, label, countof(label)); - FString alabel(label); - newlabel.Format(GAMENAME " %s: %s", GetVersionString(), alabel.GetChars()); - auto wlabel = newlabel.WideString(); - SetWindowTextW(hDlg, wlabel.c_str()); - } - - // [SP] Upstreamed from Zandronum - char szString[256]; - - // Check the current video settings. - SendDlgItemMessage( hDlg, IDC_WELCOME_FULLSCREEN, BM_SETCHECK, vid_fullscreen ? BST_CHECKED : BST_UNCHECKED, 0 ); - switch (vid_preferbackend) - { - case 1: - SendDlgItemMessage( hDlg, IDC_WELCOME_VULKAN2, BM_SETCHECK, BST_CHECKED, 0 ); - break; -#ifdef HAVE_GLES2 - case 2: - case 3: - SendDlgItemMessage( hDlg, IDC_WELCOME_VULKAN4, BM_SETCHECK, BST_CHECKED, 0 ); - break; -#endif - default: - SendDlgItemMessage( hDlg, IDC_WELCOME_VULKAN1, BM_SETCHECK, BST_CHECKED, 0 ); - break; - } - - - // [SP] This is our's - SendDlgItemMessage( hDlg, IDC_WELCOME_NOAUTOLOAD, BM_SETCHECK, (flags & 1) ? BST_CHECKED : BST_UNCHECKED, 0); - SendDlgItemMessage( hDlg, IDC_WELCOME_LIGHTS, BM_SETCHECK, (flags & 2) ? BST_CHECKED : BST_UNCHECKED, 0 ); - SendDlgItemMessage( hDlg, IDC_WELCOME_BRIGHTMAPS, BM_SETCHECK, (flags & 4) ? BST_CHECKED : BST_UNCHECKED, 0 ); - SendDlgItemMessage( hDlg, IDC_WELCOME_WIDESCREEN, BM_SETCHECK, (flags & 8) ? BST_CHECKED : BST_UNCHECKED, 0 ); - - // Set up our version string. - snprintf(szString, sizeof(szString), "Version %s.", GetVersionString()); - SetDlgItemTextA (hDlg, IDC_WELCOME_VERSION, szString); - - // Populate the list with all the IWADs found - ctrl = GetDlgItem(hDlg, IDC_IWADLIST); - for (i = 0; i < NumWads; i++) - { - const char *filepart = strrchr(WadList[i].Path.GetChars(), '/'); - if (filepart == NULL) - filepart = WadList[i].Path.GetChars(); - else - filepart++; - - FString work; - if (*filepart) work.Format("%s (%s)", WadList[i].Name.GetChars(), filepart); - else work = WadList[i].Name.GetChars(); - std::wstring wide = work.WideString(); - SendMessage(ctrl, LB_ADDSTRING, 0, (LPARAM)wide.c_str()); - SendMessage(ctrl, LB_SETITEMDATA, i, (LPARAM)i); - } - SendMessage(ctrl, LB_SETCURSEL, DefaultWad, 0); - SetFocus(ctrl); - // Set the state of the "Don't ask me again" checkbox - ctrl = GetDlgItem(hDlg, IDC_DONTASKIWAD); - SendMessage(ctrl, BM_SETCHECK, queryiwad ? BST_UNCHECKED : BST_CHECKED, 0); - // Make sure the dialog is in front. If SHIFT was pressed to force it visible, - // then the other window will normally be on top. - SetForegroundWindow(hDlg); - break; - - case WM_COMMAND: - if (LOWORD(wParam) == IDCANCEL) - { - EndDialog (hDlg, -1); - } - else if (LOWORD(wParam) == IDOK || - (LOWORD(wParam) == IDC_IWADLIST && HIWORD(wParam) == LBN_DBLCLK)) - { - SetQueryIWad(hDlg); - // [SP] Upstreamed from Zandronum - vid_fullscreen = SendDlgItemMessage( hDlg, IDC_WELCOME_FULLSCREEN, BM_GETCHECK, 0, 0 ) == BST_CHECKED; -#ifdef HAVE_GLES2 - if (SendDlgItemMessage(hDlg, IDC_WELCOME_VULKAN4, BM_GETCHECK, 0, 0) == BST_CHECKED) - vid_preferbackend = 2; - else -#endif - if (SendDlgItemMessage(hDlg, IDC_WELCOME_VULKAN2, BM_GETCHECK, 0, 0) == BST_CHECKED) - vid_preferbackend = 1; - else if (SendDlgItemMessage(hDlg, IDC_WELCOME_VULKAN1, BM_GETCHECK, 0, 0) == BST_CHECKED) - vid_preferbackend = 0; - - // [SP] This is our's. - flags = 0; - if (SendDlgItemMessage(hDlg, IDC_WELCOME_NOAUTOLOAD, BM_GETCHECK, 0, 0) == BST_CHECKED) flags |= 1; - if (SendDlgItemMessage(hDlg, IDC_WELCOME_LIGHTS, BM_GETCHECK, 0, 0) == BST_CHECKED) flags |= 2; - if (SendDlgItemMessage(hDlg, IDC_WELCOME_BRIGHTMAPS, BM_GETCHECK, 0, 0) == BST_CHECKED) flags |= 4; - if (SendDlgItemMessage(hDlg, IDC_WELCOME_WIDESCREEN, BM_GETCHECK, 0, 0) == BST_CHECKED) flags |= 8; - ctrl = GetDlgItem (hDlg, IDC_IWADLIST); - EndDialog(hDlg, SendMessage (ctrl, LB_GETCURSEL, 0, 0)); - } - break; - } - return FALSE; -} - //========================================================================== // // I_PickIWad @@ -480,7 +355,6 @@ BOOL CALLBACK IWADBoxCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa int I_PickIWad(WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags) { int vkey; - pAutoloadflags = &autoloadflags; if (stricmp(queryiwad_key, "shift") == 0) { vkey = VK_SHIFT; @@ -495,14 +369,6 @@ int I_PickIWad(WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& } if (showwin || (vkey != 0 && GetAsyncKeyState(vkey))) { - /* - WadList = wads; - NumWads = numwads; - DefaultWad = defaultiwad; - - return (int)DialogBox(g_hInst, MAKEINTRESOURCE(IDD_IWADDIALOG), - (HWND)mainwindow.GetHandle(), (DLGPROC)IWADBoxCallback); - */ return LauncherWindow::ExecModal(wads, numwads, defaultiwad, &autoloadflags); } return defaultiwad; diff --git a/src/common/widgets/launcherwindow.cpp b/src/common/widgets/launcherwindow.cpp index 607835b05c..663eb03a75 100644 --- a/src/common/widgets/launcherwindow.cpp +++ b/src/common/widgets/launcherwindow.cpp @@ -12,6 +12,10 @@ #include #include +#ifdef RENDER_BACKENDS +EXTERN_CVAR(Int, vid_preferbackend); +#endif + EXTERN_CVAR(Bool, queryiwad); int LauncherWindow::ExecModal(WadStuff* wads, int numwads, int defaultiwad, int* autoloadflags) @@ -73,6 +77,17 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int WidescreenCheckbox->SetText("Widescreen"); ParametersLabel->SetText("Additional Parameters:"); +#ifdef RENDER_BACKENDS + BackendLabel = new TextLabel(this); + VulkanCheckbox = new CheckboxLabel(this); + OpenGLCheckbox = new CheckboxLabel(this); + GLESCheckbox = new CheckboxLabel(this); + BackendLabel->SetText("Render Backend"); + VulkanCheckbox->SetText("Vulkan"); + OpenGLCheckbox->SetText("OpenGL"); + GLESCheckbox->SetText("OpenGL ES"); +#endif + FString welcomeText, versionText; welcomeText.Format("Welcome to %s!", GAMENAME); versionText.Format("Version %s.", GetVersionString()); @@ -88,6 +103,27 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int BrightmapsCheckbox->SetChecked(flags & 4); WidescreenCheckbox->SetChecked(flags & 8); +#ifdef RENDER_BACKENDS + OpenGLCheckbox->SetRadioStyle(true); + VulkanCheckbox->SetRadioStyle(true); + GLESCheckbox->SetRadioStyle(true); + OpenGLCheckbox->FuncChanged = [this](bool on) { if (on) { VulkanCheckbox->SetChecked(false); GLESCheckbox->SetChecked(false); }}; + VulkanCheckbox->FuncChanged = [this](bool on) { if (on) { OpenGLCheckbox->SetChecked(false); GLESCheckbox->SetChecked(false); }}; + GLESCheckbox->FuncChanged = [this](bool on) { if (on) { VulkanCheckbox->SetChecked(false); OpenGLCheckbox->SetChecked(false); }}; + switch (vid_preferbackend) + { + case 0: + OpenGLCheckbox->SetChecked(true); + break; + case 1: + VulkanCheckbox->SetChecked(true); + break; + case 2: + GLESCheckbox->SetChecked(true); + break; + } +#endif + for (int i = 0; i < numwads; i++) { const char* filepart = strrchr(wads[i].Path.GetChars(), '/'); @@ -125,6 +161,14 @@ void LauncherWindow::OnPlayButtonClicked() if (WidescreenCheckbox->GetChecked()) flags |= 8; *AutoloadFlags = flags; +#ifdef RENDER_BACKENDS + int v = 1; + if (OpenGLCheckbox->GetChecked()) v = 0; + else if (VulkanCheckbox->GetChecked()) v = 1; + else if (GLESCheckbox->GetChecked()) v = 2; + if (v != vid_preferbackend) vid_preferbackend = v; +#endif + std::string extraargs = ParametersEdit->GetText(); if (!extraargs.empty()) { @@ -185,6 +229,24 @@ void LauncherWindow::OnGeometryChanged() y -= 10.0; double panelWidth = 150.0; + +#ifdef RENDER_BACKENDS + auto yy = y; + y -= GLESCheckbox->GetPreferredHeight(); + double x = GetWidth() / 2 - panelWidth / 2; + GLESCheckbox->SetFrameGeometry(x, y, 190.0, GLESCheckbox->GetPreferredHeight()); + + y -= OpenGLCheckbox->GetPreferredHeight(); + OpenGLCheckbox->SetFrameGeometry(x, y, 190.0, OpenGLCheckbox->GetPreferredHeight()); + + y -= VulkanCheckbox->GetPreferredHeight(); + VulkanCheckbox->SetFrameGeometry(x, y, 190.0, VulkanCheckbox->GetPreferredHeight()); + + y -= BackendLabel->GetPreferredHeight(); + BackendLabel->SetFrameGeometry(x, y, 190.0, BackendLabel->GetPreferredHeight()); + + y = yy; +#endif y -= DontAskAgainCheckbox->GetPreferredHeight(); DontAskAgainCheckbox->SetFrameGeometry(20.0, y, 190.0, DontAskAgainCheckbox->GetPreferredHeight()); WidescreenCheckbox->SetFrameGeometry(GetWidth() - 20.0 - panelWidth, y, panelWidth, WidescreenCheckbox->GetPreferredHeight()); diff --git a/src/common/widgets/launcherwindow.h b/src/common/widgets/launcherwindow.h index d34bf8ee7b..6f48a05254 100644 --- a/src/common/widgets/launcherwindow.h +++ b/src/common/widgets/launcherwindow.h @@ -2,6 +2,9 @@ #include + +#define RENDER_BACKENDS + class ImageBox; class TextLabel; class CheckboxLabel; @@ -38,6 +41,12 @@ private: CheckboxLabel* LightsCheckbox = nullptr; CheckboxLabel* BrightmapsCheckbox = nullptr; CheckboxLabel* WidescreenCheckbox = nullptr; +#ifdef RENDER_BACKENDS + TextLabel* BackendLabel = nullptr; + CheckboxLabel* VulkanCheckbox = nullptr; + CheckboxLabel* OpenGLCheckbox = nullptr; + CheckboxLabel* GLESCheckbox = nullptr; +#endif PushButton* PlayButton = nullptr; PushButton* ExitButton = nullptr; ListView* GamesList = nullptr;