Use Left Alt for ImGui toggle

This commit is contained in:
Luke Street 2022-08-09 18:29:12 -04:00
parent 5b6744e188
commit 1193bab7e4
3 changed files with 16 additions and 4 deletions

View File

@ -168,6 +168,7 @@ private:
bool m_firstFrame = true; bool m_firstFrame = true;
bool m_fullscreenToggleRequested = false; bool m_fullscreenToggleRequested = false;
bool m_quitRequested = false; bool m_quitRequested = false;
bool m_lAltHeld = false;
using delta_clock = std::chrono::high_resolution_clock; using delta_clock = std::chrono::high_resolution_clock;
delta_clock::time_point m_prevFrameTime; delta_clock::time_point m_prevFrameTime;
@ -220,10 +221,17 @@ public:
void onSdlEvent(const SDL_Event& event) noexcept { void onSdlEvent(const SDL_Event& event) noexcept {
switch (event.type) { switch (event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
m_lAltHeld = event.key.keysym.sym == SDLK_LALT;
// Toggle fullscreen on ALT+ENTER // Toggle fullscreen on ALT+ENTER
if (event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT) != 0u && event.key.repeat == 0u) { 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()); 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;
}
} }
} }

View File

@ -1301,6 +1301,12 @@ void ImGuiConsole::ShowAppMainMenuBar(bool canInspect, bool preLaunch) {
} }
} }
void ImGuiConsole::ToggleVisible() {
if (g_Main != nullptr) {
m_isVisible ^= 1;
}
}
void ImGuiConsole::PreUpdate() { void ImGuiConsole::PreUpdate() {
OPTICK_EVENT(); OPTICK_EVENT();
bool preLaunch = g_Main == nullptr; bool preLaunch = g_Main == nullptr;
@ -1332,7 +1338,7 @@ void ImGuiConsole::PreUpdate() {
} }
if (!preLaunch && !m_isLaunchInitialized) { if (!preLaunch && !m_isLaunchInitialized) {
if (m_developer) { 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; m_isLaunchInitialized = true;
} }
@ -1342,9 +1348,6 @@ void ImGuiConsole::PreUpdate() {
} }
if (!preLaunch) { if (!preLaunch) {
if (ImGui::IsKeyReleased(ImGuiKey_GraveAccent)) {
m_isVisible ^= 1;
}
if (m_stepFrame) { if (m_stepFrame) {
g_Main->SetPaused(true); g_Main->SetPaused(true);
m_stepFrame = false; m_stepFrame = false;

View File

@ -61,6 +61,7 @@ public:
void ControllerAdded(uint32_t idx); void ControllerAdded(uint32_t idx);
void ControllerRemoved(uint32_t idx); void ControllerRemoved(uint32_t idx);
void ToggleVisible();
std::optional<std::string> m_errorString; std::optional<std::string> m_errorString;
std::optional<std::string> m_gameDiscSelected; std::optional<std::string> m_gameDiscSelected;