Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FullscreenUI: Properly account for multiline Rich Presence in Title Info #10330

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions pcsx2/ImGui/FullscreenUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4574,10 +4574,8 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)

// title info
{
const bool has_rich_presence = Achievements::IsActive() && !Achievements::GetRichPresenceString().empty();

const float image_width = has_rich_presence ? 60.0f : 50.0f;
const float image_height = has_rich_presence ? 90.0f : 75.0f;
const float image_width = 60.0f;
const float image_height = 90.0f;
const std::string_view path_string(Path::GetFileName(s_current_disc_path));
const ImVec2 title_size(
g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits<float>::max(), -1.0f, s_current_game_title.c_str()));
Expand All @@ -4596,43 +4594,42 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
(path_string.empty() ? title_pos.y : path_pos.y) + g_medium_font->FontSize + LayoutScale(4.0f));

float rp_height = 0.0f;

DrawShadowedText(dl, g_large_font, title_pos, text_color, s_current_game_title.c_str());
if (!path_string.empty())
{
DrawShadowedText(dl, g_medium_font, path_pos, text_color, path_string.data(), path_string.data() + path_string.length());
}
DrawShadowedText(dl, g_medium_font, subtitle_pos, text_color, s_current_game_subtitle.c_str());

if (has_rich_presence)
{
const auto lock = Achievements::GetLock();
const std::string& rp = Achievements::GetRichPresenceString();
const std::string& rp = Achievements::IsActive() ? Achievements::GetRichPresenceString() : std::string();

if (!rp.empty())
{
const float wrap_width = LayoutScale(350.0f);
const ImVec2 rp_size = g_medium_font->CalcTextSizeA(
g_medium_font->FontSize, std::numeric_limits<float>::max(), wrap_width, rp.data(), rp.data() + rp.size());
g_medium_font->FontSize, std::numeric_limits<float>::max(), wrap_width, rp.data(), rp.data() + rp.length());

// we make the image one line higher, so we only need to compensate when it's multiline RP
rp_height = rp_size.y - g_medium_font->FontSize;
// Add a small extra gap if any Rich Presence is displayed
rp_height = rp_size.y - g_medium_font->FontSize + 2.0f;

const ImVec2 rp_pos(display_size.x - LayoutScale(20.0f + 50.0f + 20.0f) - rp_size.x - rp_height,
subtitle_pos.y + g_medium_font->FontSize + LayoutScale(4.0f));
const ImVec2 rp_pos(display_size.x - LayoutScale(20.0f + 50.0f + 20.0f) - rp_size.x,
subtitle_pos.y + g_medium_font->FontSize + LayoutScale(4.0f) - rp_height);

title_pos.y -= rp_height;
path_pos.y -= rp_height;
subtitle_pos.y -= rp_height;

DrawShadowedText(dl, g_medium_font, rp_pos, text_color, rp.data(), rp.data() + rp.size(), wrap_width);
DrawShadowedText(dl, g_medium_font, rp_pos, text_color, rp.data(), rp.data() + rp.length(), wrap_width);
}
}

DrawShadowedText(dl, g_large_font, title_pos, text_color, s_current_game_title.c_str());
if (!path_string.empty())
{
DrawShadowedText(dl, g_medium_font, path_pos, text_color, path_string.data(), path_string.data() + path_string.length());
}
DrawShadowedText(dl, g_medium_font, subtitle_pos, text_color, s_current_game_subtitle.c_str());


GSTexture* const cover = GetCoverForCurrentGame();
const ImVec2 image_min(
display_size.x - LayoutScale(10.0f + image_width) - rp_height, display_size.y - LayoutScale(10.0f + image_height) - rp_height);
const ImVec2 image_max(image_min.x + LayoutScale(image_width) + rp_height, image_min.y + LayoutScale(image_height) + rp_height);
display_size.x - LayoutScale(10.0f + image_width), display_size.y - LayoutScale(10.0f + image_height) - rp_height);
const ImVec2 image_max(image_min.x + LayoutScale(image_width), image_min.y + LayoutScale(image_height) + rp_height);
const ImRect image_rect(CenterImage(
ImRect(image_min, image_max), ImVec2(static_cast<float>(cover->GetWidth()), static_cast<float>(cover->GetHeight()))));
dl->AddImage(cover->GetNativeHandle(), image_rect.Min, image_rect.Max);
Expand Down