diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 8f889770b..8ea0f8d15 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1388,17 +1388,35 @@ void CommonHostInterface::DrawOSDMessages() { AcquirePendingOSDMessages(); - const float scale = ImGui::GetIO().DisplayFramebufferScale.x; - const float spacing = 5.0f * scale; - const float margin = 10.0f * scale; - const float padding = 8.0f * scale; - const float rounding = 5.0f * scale; - const float max_width = ImGui::GetIO().DisplaySize.x - margin; - float position_x = margin; - float position_y = margin; + float max_width, margin, spacing, padding, rounding, position_x, position_y; + ImFont* font; - EnumerateOSDMessages([max_width, spacing, padding, rounding, &position_x, &position_y](const std::string& message, - float time_remaining) -> bool { + if (m_fullscreen_ui_enabled) + { + max_width = ImGuiFullscreen::LayoutScale(1080.0f); + spacing = ImGuiFullscreen::LayoutScale(4.0f); + margin = ImGuiFullscreen::LayoutScale(10.0f); + padding = ImGuiFullscreen::LayoutScale(10.0f); + rounding = ImGuiFullscreen::LayoutScale(10.0f); + position_x = margin; + position_y = margin + ImGuiFullscreen::g_menu_bar_size; + font = ImGuiFullscreen::g_large_font; + } + else + { + const float scale = ImGui::GetIO().DisplayFramebufferScale.x; + spacing = 5.0f * scale; + margin = 10.0f * scale; + padding = 8.0f * scale; + rounding = 5.0f * scale; + max_width = ImGui::GetIO().DisplaySize.x - margin; + position_x = margin; + position_y = margin; + font = ImGui::GetFont(); + } + + EnumerateOSDMessages([max_width, spacing, padding, rounding, &position_x, &position_y, + font](const std::string& message, float time_remaining) -> bool { const float opacity = std::min(time_remaining, 1.0f); const u32 alpha = static_cast(opacity * 255.0f); @@ -1406,12 +1424,12 @@ void CommonHostInterface::DrawOSDMessages() return false; const ImVec2 pos(position_x, position_y); - const ImVec2 text_size(ImGui::CalcTextSize(message.c_str(), nullptr, false, max_width)); + const ImVec2 text_size( + font->CalcTextSizeA(font->FontSize, max_width, -1.0f, message.c_str(), message.c_str() + message.length())); const ImVec2 size(text_size.x + padding * 2.0f, text_size.y + padding * 2.0f); const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding); ImDrawList* dl = ImGui::GetBackgroundDrawList(); - ImFont* font = ImGui::GetFont(); dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x21, 0x21, 0x21, alpha), rounding); dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x48, 0x48, 0x48, alpha), rounding); dl->AddText(font, font->FontSize, ImVec2(text_rect.x, text_rect.y), IM_COL32(0xff, 0xff, 0xff, alpha), diff --git a/src/frontend-common/fullscreen_ui.cpp b/src/frontend-common/fullscreen_ui.cpp index 54a9c3008..fab917c98 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -92,7 +92,6 @@ static void DrawQuickMenu(MainWindowType type); static void DrawAchievementWindow(); static void DrawLeaderboardsWindow(); static void DrawDebugMenu(); -static void DrawOSDMessages(); static void DrawAboutWindow(); static void OpenAboutWindow(); static void SetDebugMenuEnabled(bool enabled); @@ -391,7 +390,7 @@ void Render() if (s_input_binding_type != InputBindingType::None) DrawInputBindingWindow(); - DrawOSDMessages(); + s_host_interface->DrawOSDMessages(); ImGuiFullscreen::EndLayout(); } @@ -3331,46 +3330,6 @@ HostDisplayTexture* GetCoverForCurrentGame() // Overlays ////////////////////////////////////////////////////////////////////////// -void DrawOSDMessages() -{ - s_host_interface->AcquirePendingOSDMessages(); - - ImGui::PushFont(g_large_font); - - const float max_width = LayoutScale(1080.0f); - const float spacing = LayoutScale(4.0f); - const float margin = LayoutScale(10.0f); - const float padding = LayoutScale(10.0f); - float position_x = margin; - float position_y = margin + ImGuiFullscreen::g_menu_bar_size; - - s_host_interface->EnumerateOSDMessages( - [max_width, spacing, padding, &position_x, &position_y](const std::string& message, float time_remaining) -> bool { - const float opacity = std::min(time_remaining, 1.0f); - const u32 alpha = static_cast(opacity * 255.0f); - - if (position_y >= ImGui::GetIO().DisplaySize.y) - return false; - - const ImVec2 pos(position_x, position_y); - const ImVec2 text_size(ImGui::CalcTextSize(message.c_str(), nullptr, false, max_width)); - const ImVec2 size(text_size + LayoutScale(20.0f, 20.0f)); - const ImVec4 text_rect(pos.x + padding, pos.y + padding, pos.x + size.x - padding, pos.y + size.y - padding); - - // If we're in the landing page, draw the OSD over the windows (since it covers it) - ImDrawList* dl = (s_current_main_window != MainWindowType::None) ? ImGui::GetForegroundDrawList() : - ImGui::GetBackgroundDrawList(); - dl->AddRectFilled(pos, pos + size, IM_COL32(0x21, 0x21, 0x21, alpha), LayoutScale(10.0f)); - dl->AddRect(pos, pos + size, IM_COL32(0x48, 0x48, 0x48, alpha), LayoutScale(10.0f)); - dl->AddText(g_large_font, g_large_font->FontSize, ImVec2(text_rect.x, text_rect.y), - IM_COL32(0xff, 0xff, 0xff, alpha), message.c_str(), nullptr, max_width, &text_rect); - position_y += size.y + spacing; - return true; - }); - - ImGui::PopFont(); -} - void OpenAboutWindow() { s_about_window_open = true;