From 895c489f05b0da04938620d13f0e910c6a74930f Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 2 Sep 2024 00:27:48 +1000 Subject: [PATCH] ImGuiManager: Split OSD and debug window fonts Fixes the latter not fitting on screen anymore. --- src/core/imgui_overlays.cpp | 8 +++++--- src/util/imgui_fullscreen.cpp | 3 +-- src/util/imgui_fullscreen.h | 3 +-- src/util/imgui_manager.cpp | 28 +++++++++++++++++++--------- src/util/imgui_manager.h | 3 +++ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/core/imgui_overlays.cpp b/src/core/imgui_overlays.cpp index 99600e9fba..05c72aa9a8 100644 --- a/src/core/imgui_overlays.cpp +++ b/src/core/imgui_overlays.cpp @@ -232,7 +232,7 @@ void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, float const float shadow_offset = std::ceil(1.0f * scale); ImFont* fixed_font = ImGuiManager::GetFixedFont(); - ImFont* standard_font = ImGuiManager::GetStandardFont(); + ImFont* standard_font = ImGuiManager::GetOSDFont(); ImDrawList* dl = ImGui::GetBackgroundDrawList(); SmallString text; ImVec2 text_size; @@ -506,7 +506,7 @@ void ImGuiManager::DrawMediaCaptureOverlay(float& position_y, float scale, float return; const float shadow_offset = std::ceil(scale); - ImFont* const standard_font = ImGuiManager::GetStandardFont(); + ImFont* const standard_font = ImGuiManager::GetOSDFont(); ImDrawList* dl = ImGui::GetBackgroundDrawList(); static constexpr const char* ICON = ICON_PF_CIRCLE; @@ -614,7 +614,7 @@ void ImGuiManager::DrawInputsOverlay() const float shadow_offset = 1.0f * scale; const float margin = 10.0f * scale; const float spacing = 5.0f * scale; - ImFont* font = ImGuiManager::GetStandardFont(); + ImFont* font = ImGuiManager::GetOSDFont(); static constexpr u32 text_color = IM_COL32(0xff, 0xff, 0xff, 255); static constexpr u32 shadow_color = IM_COL32(0x00, 0x00, 0x00, 100); @@ -984,6 +984,7 @@ void SaveStateSelectorUI::Draw() ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, padding_and_rounding); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(padding_and_rounding, padding_and_rounding)); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.11f, 0.15f, 0.17f, 0.8f)); + ImGui::PushFont(ImGuiManager::GetOSDFont()); ImGui::SetNextWindowSize(ImVec2(width, height), ImGuiCond_Always); ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); @@ -1103,6 +1104,7 @@ void SaveStateSelectorUI::Draw() } ImGui::End(); + ImGui::PopFont(); ImGui::PopStyleVar(2); ImGui::PopStyleColor(); diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 4117df9ed9..0bc4cab8a2 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -202,9 +202,8 @@ static std::vector s_background_progress_dialogs; static std::mutex s_background_progress_lock; } // namespace ImGuiFullscreen -void ImGuiFullscreen::SetFonts(ImFont* standard_font, ImFont* medium_font, ImFont* large_font) +void ImGuiFullscreen::SetFonts(ImFont* medium_font, ImFont* large_font) { - g_standard_font = standard_font; g_medium_font = medium_font; g_large_font = large_font; } diff --git a/src/util/imgui_fullscreen.h b/src/util/imgui_fullscreen.h index d4f3ac04cf..a1bd4117b5 100644 --- a/src/util/imgui_fullscreen.h +++ b/src/util/imgui_fullscreen.h @@ -43,7 +43,6 @@ static constexpr float LAYOUT_HORIZONTAL_MENU_HEIGHT = 320.0f; static constexpr float LAYOUT_HORIZONTAL_MENU_PADDING = 30.0f; static constexpr float LAYOUT_HORIZONTAL_MENU_ITEM_WIDTH = 250.0f; -extern ImFont* g_standard_font; extern ImFont* g_medium_font; extern ImFont* g_large_font; @@ -121,7 +120,7 @@ ImRect CenterImage(const ImRect& fit_rect, const ImVec2& image_size); bool Initialize(const char* placeholder_image_path); void SetTheme(bool light); -void SetFonts(ImFont* standard_font, ImFont* medium_font, ImFont* large_font); +void SetFonts(ImFont* medium_font, ImFont* large_font); bool UpdateLayoutScale(); /// Shuts down, clearing all state. diff --git a/src/util/imgui_manager.cpp b/src/util/imgui_manager.cpp index cc10aec4d6..0911eee977 100644 --- a/src/util/imgui_manager.cpp +++ b/src/util/imgui_manager.cpp @@ -86,6 +86,7 @@ static std::vector s_font_range; static std::vector s_emoji_range; static ImFont* s_standard_font; +static ImFont* s_osd_font; static ImFont* s_fixed_font; static ImFont* s_medium_font; static ImFont* s_large_font; @@ -274,7 +275,7 @@ void ImGuiManager::Shutdown() s_fixed_font = nullptr; s_medium_font = nullptr; s_large_font = nullptr; - ImGuiFullscreen::SetFonts(nullptr, nullptr, nullptr); + ImGuiFullscreen::SetFonts(nullptr, nullptr); } float ImGuiManager::GetWindowWidth() @@ -654,20 +655,24 @@ bool ImGuiManager::AddIconFonts(float size) bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts) { - const float standard_font_size = std::ceil(18.0f * s_global_scale); - const float fixed_font_size = std::ceil(15.0f * s_global_scale); + const float standard_font_size = std::ceil(15.0f * s_global_scale); + const float osd_font_size = std::ceil(17.0f * s_global_scale); ImGuiIO& io = ImGui::GetIO(); io.Fonts->Clear(); s_standard_font = AddTextFont(standard_font_size); - if (!s_standard_font || !AddIconFonts(standard_font_size)) + if (!s_standard_font) return false; - s_fixed_font = AddFixedFont(fixed_font_size); + s_fixed_font = AddFixedFont(standard_font_size); if (!s_fixed_font) return false; + s_osd_font = AddTextFont(osd_font_size); + if (!s_osd_font || !AddIconFonts(osd_font_size)) + return false; + if (fullscreen_fonts) { const float medium_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE); @@ -686,7 +691,7 @@ bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts) s_large_font = nullptr; } - ImGuiFullscreen::SetFonts(s_standard_font, s_medium_font, s_large_font); + ImGuiFullscreen::SetFonts(s_medium_font, s_large_font); return io.Fonts->Build(); } @@ -837,11 +842,11 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time) { static constexpr float MOVE_DURATION = 0.5f; - ImFont* const font = ImGui::GetFont(); + ImFont* const font = s_osd_font; const float scale = s_global_scale; const float spacing = std::ceil(6.0f * scale); - const float margin = std::ceil(12.0f * scale); - const float padding = std::ceil(10.0f * scale); + const float margin = std::ceil(11.0f * scale); + const float padding = std::ceil(9.0f * scale); const float rounding = std::ceil(6.0f * scale); const float max_width = s_window_width - (margin + padding) * 2.0f; float position_x = margin; @@ -942,6 +947,11 @@ ImFont* ImGuiManager::GetStandardFont() return s_standard_font; } +ImFont* ImGuiManager::GetOSDFont() +{ + return s_osd_font; +} + ImFont* ImGuiManager::GetFixedFont() { return s_fixed_font; diff --git a/src/util/imgui_manager.h b/src/util/imgui_manager.h index 48d345caba..146dbd1b5a 100644 --- a/src/util/imgui_manager.h +++ b/src/util/imgui_manager.h @@ -69,6 +69,9 @@ bool AddFullscreenFontsIfMissing(); /// Returns the standard font for external drawing. ImFont* GetStandardFont(); +/// Returns the standard font for on-screen display drawing. +ImFont* GetOSDFont(); + /// Returns the fixed-width font for external drawing. ImFont* GetFixedFont();