Skip to content

Commit c508c6f

Browse files
committed
Fix in-game menu gamepad issue for Dx11 too
1 parent 69e3529 commit c508c6f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

OptiScaler/menu/menu_common.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static bool receivingWmInputs = false;
1717
static bool inputMenu = false;
1818
static bool inputFps = false;
1919
static bool inputFpsCycle = false;
20+
static bool hasGamepad = false;
2021

2122
void MenuCommon::ShowTooltip(const char* tip) {
2223
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
@@ -917,6 +918,14 @@ bool MenuCommon::RenderMenu()
917918
auto dllPath = Util::DllPath().parent_path() / "dlssg_to_fsr3_amd_is_better.dll";
918919
State::Instance().NukemsFilesAvailable = std::filesystem::exists(dllPath);
919920

921+
io.ClearEventsQueue();
922+
io.ClearInputCharacters();
923+
io.ClearInputKeys();
924+
io.ClearInputMouse();
925+
926+
if (hasGamepad)
927+
io.BackendFlags | ImGuiBackendFlags_HasGamepad;
928+
920929
io.ConfigFlags = ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad;
921930

922931
if (pfn_ClipCursor_hooked)
@@ -931,6 +940,8 @@ bool MenuCommon::RenderMenu()
931940
}
932941
else
933942
{
943+
hasGamepad = (io.BackendFlags | ImGuiBackendFlags_HasGamepad) > 0;
944+
io.BackendFlags &= 30;
934945
io.ConfigFlags = ImGuiConfigFlags_NavNoCaptureKeyboard | ImGuiConfigFlags_NoMouse | ImGuiConfigFlags_NoMouseCursorChange | ImGuiConfigFlags_NoKeyboard;
935946

936947
if (pfn_ClipCursor_hooked)
@@ -3151,7 +3162,8 @@ bool MenuCommon::RenderMenu()
31513162
if (ImGui::Button("Close"))
31523163
{
31533164
_isVisible = false;
3154-
3165+
hasGamepad = (io.BackendFlags | ImGuiBackendFlags_HasGamepad) > 0;
3166+
io.BackendFlags &= 30;
31553167
io.ConfigFlags = ImGuiConfigFlags_NavNoCaptureKeyboard | ImGuiConfigFlags_NoMouse | ImGuiConfigFlags_NoMouseCursorChange | ImGuiConfigFlags_NoKeyboard;
31563168

31573169
if (pfn_ClipCursor_hooked)
@@ -3364,14 +3376,17 @@ void MenuCommon::Init(HWND InHwnd)
33643376
ImGui::StyleColorsDark();
33653377

33663378
ImGuiIO& io = ImGui::GetIO(); (void)io;
3379+
3380+
hasGamepad = (io.BackendFlags | ImGuiBackendFlags_HasGamepad) > 0;
3381+
io.BackendFlags &= 30;
33673382
io.ConfigFlags = ImGuiConfigFlags_NavNoCaptureKeyboard | ImGuiConfigFlags_NoMouse | ImGuiConfigFlags_NoMouseCursorChange | ImGuiConfigFlags_NoKeyboard;
33683383

33693384
io.MouseDrawCursor = _isVisible;
33703385
io.WantCaptureKeyboard = _isVisible;
33713386
io.WantCaptureMouse = _isVisible;
33723387
io.WantSetMousePos = _isVisible;
33733388

3374-
io.IniFilename = io.LogFilename = nullptr;
3389+
io.IniFilename = io.LogFilename = nullptr;
33753390

33763391
bool initResult = ImGui_ImplWin32_Init(InHwnd);
33773392
LOG_DEBUG("ImGui_ImplWin32_Init result: {0}", initResult);

0 commit comments

Comments
 (0)