diff --git a/src/ui.cpp b/src/ui.cpp index e05b1d7..46bb253 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -946,8 +946,8 @@ void Ui::catalog_draw(Play& play) style_pop(); } -// The open window (stats, catalog or settings): one at a time, fixed in size above the taskbar, closed by its X or -// escape, and holding the mouse while open. +// The open window (stats, catalog, settings or cheats): one at a time, fixed in size above the taskbar, closed by its +// X, escape or a click off it, and holding the mouse while open. void Ui::window_draw(Play& play, Settings& settings, ImVec2 screen) { if (play.text.isScene) @@ -973,7 +973,12 @@ void Ui::window_draw(Play& play, Settings& settings, ImVec2 screen) cheats_draw(play); else settings_draw(settings); - if (ImGui::IsKeyPressed(ImGuiKey_Escape)) + ImVec2 min = ImGui::GetWindowPos(); + ImVec2 max = {min.x + ImGui::GetWindowWidth(), min.y + ImGui::GetWindowHeight()}; + bool isFocused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy); + bool isClickedOff = + isFocused && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !ImGui::IsMouseHoveringRect(min, max, false); + if (ImGui::IsKeyPressed(ImGuiKey_Escape) || isClickedOff) { isOpen = false; ImGui::CloseCurrentPopup();