From 1193bab7e4b4a9b3ed2e5af6c7d104047b662c78 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 9 Aug 2022 18:29:12 -0400 Subject: [PATCH] Use Left Alt for ImGui toggle --- Runtime/CMain.cpp | 8 ++++++++ Runtime/ImGuiConsole.cpp | 11 +++++++---- Runtime/ImGuiConsole.hpp | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index 04469bdd5..4fc5171b6 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -168,6 +168,7 @@ private: bool m_firstFrame = true; bool m_fullscreenToggleRequested = false; bool m_quitRequested = false; + bool m_lAltHeld = false; using delta_clock = std::chrono::high_resolution_clock; delta_clock::time_point m_prevFrameTime; @@ -220,10 +221,17 @@ public: void onSdlEvent(const SDL_Event& event) noexcept { switch (event.type) { case SDL_KEYDOWN: + m_lAltHeld = event.key.keysym.sym == SDLK_LALT; // Toggle fullscreen on ALT+ENTER if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT) != 0u && event.key.repeat == 0u) { m_cvarCommons.m_fullscreen->fromBoolean(!m_cvarCommons.m_fullscreen->toBoolean()); } + break; + case SDL_KEYUP: + if (m_lAltHeld && event.key.keysym.sym == SDLK_LALT) { + m_imGuiConsole.ToggleVisible(); + m_lAltHeld = false; + } } } diff --git a/Runtime/ImGuiConsole.cpp b/Runtime/ImGuiConsole.cpp index f24845a1b..d560ef622 100644 --- a/Runtime/ImGuiConsole.cpp +++ b/Runtime/ImGuiConsole.cpp @@ -1301,6 +1301,12 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect, bool preLaunch) { } } +void ImGuiConsole::ToggleVisible() { + if (g_Main != nullptr) { + m_isVisible ^= 1; + } +} + void ImGuiConsole::PreUpdate() { OPTICK_EVENT(); bool preLaunch = g_Main == nullptr; @@ -1332,7 +1338,7 @@ void ImGuiConsole::PreUpdate() { } if (!preLaunch && !m_isLaunchInitialized) { if (m_developer) { - m_toasts.emplace_back("Press ` to toggle menu"s, 5.f); + m_toasts.emplace_back("Press Left Alt to toggle menu"s, 5.f); } m_isLaunchInitialized = true; } @@ -1342,9 +1348,6 @@ void ImGuiConsole::PreUpdate() { } if (!preLaunch) { - if (ImGui::IsKeyReleased(ImGuiKey_GraveAccent)) { - m_isVisible ^= 1; - } if (m_stepFrame) { g_Main->SetPaused(true); m_stepFrame = false; diff --git a/Runtime/ImGuiConsole.hpp b/Runtime/ImGuiConsole.hpp index 1f5cfc242..1954ed353 100644 --- a/Runtime/ImGuiConsole.hpp +++ b/Runtime/ImGuiConsole.hpp @@ -61,6 +61,7 @@ public: void ControllerAdded(uint32_t idx); void ControllerRemoved(uint32_t idx); + void ToggleVisible(); std::optional m_errorString; std::optional m_gameDiscSelected;