Skip to content

Commit aeadd4c

Browse files
committed
FullscreenUI: Move game info to top of pause menu
1 parent d6ab840 commit aeadd4c

File tree

2 files changed

+64
-65
lines changed

2 files changed

+64
-65
lines changed

src/core/fullscreen_ui.cpp

+55-65
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ using ImGuiFullscreen::BeginMenuButtons;
101101
using ImGuiFullscreen::BeginNavBar;
102102
using ImGuiFullscreen::CancelPendingMenuClose;
103103
using ImGuiFullscreen::CenterImage;
104+
using ImGuiFullscreen::DarkerColor;
104105
using ImGuiFullscreen::DefaultActiveButton;
105106
using ImGuiFullscreen::DrawShadowedText;
106107
using ImGuiFullscreen::EndFixedPopupModal;
@@ -6399,106 +6400,95 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats)
63996400

64006401
void FullscreenUI::DrawPauseMenu()
64016402
{
6403+
static constexpr float top_bar_height = 90.0f;
6404+
static constexpr float top_bar_padding = 10.0f;
6405+
64026406
SmallString buffer;
64036407

64046408
ImDrawList* dl = ImGui::GetBackgroundDrawList();
64056409
const ImVec2 display_size(ImGui::GetIO().DisplaySize);
6406-
const ImU32 text_color = ImGui::GetColorU32(UIStyle.BackgroundTextColor) | IM_COL32_A_MASK;
6407-
dl->AddRectFilled(ImVec2(0.0f, 0.0f), display_size - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT),
6408-
(ImGui::GetColorU32(UIStyle.BackgroundColor) & ~IM_COL32_A_MASK) | (200 << IM_COL32_A_SHIFT));
6410+
const ImU32 title_text_color = ImGui::GetColorU32(UIStyle.BackgroundTextColor);
6411+
const ImU32 text_color = ImGui::GetColorU32(DarkerColor(UIStyle.BackgroundTextColor));
64096412

6410-
// title info
6413+
// top bar
6414+
const float scaled_top_bar_height = LayoutScale(top_bar_height);
64116415
{
6416+
const float scaled_text_spacing = LayoutScale(4.0f);
6417+
const float scaled_top_bar_padding = LayoutScale(top_bar_padding);
6418+
dl->AddRectFilled(ImVec2(0.0f, 0.0f), ImVec2(display_size.x, scaled_top_bar_height),
6419+
ImGui::GetColorU32(ModAlpha(UIStyle.BackgroundColor, 0.95f)), 0.0f);
6420+
6421+
GPUTexture* const cover = GetCoverForCurrentGame();
6422+
const float image_padding = LayoutScale(5.0f); // compensate for font baseline
6423+
const float image_size = scaled_top_bar_height - scaled_top_bar_padding - scaled_top_bar_padding - image_padding;
6424+
const ImRect image_rect(
6425+
CenterImage(ImRect(scaled_top_bar_padding + image_padding, scaled_top_bar_padding + image_padding,
6426+
scaled_top_bar_padding + image_size, scaled_top_bar_padding + image_size),
6427+
ImVec2(static_cast<float>(cover->GetWidth()), static_cast<float>(cover->GetHeight()))));
6428+
dl->AddImage(cover, image_rect.Min, image_rect.Max);
6429+
64126430
if (!s_state.current_game_serial.empty())
64136431
buffer.format("{} - {}", s_state.current_game_serial, Path::GetFileName(s_state.current_game_path));
64146432
else
64156433
buffer.assign(Path::GetFileName(s_state.current_game_path));
64166434

6417-
const float image_width = 60.0f;
6418-
const float image_height = 60.0f;
6419-
6420-
const ImVec2 title_size(UIStyle.LargeFont->CalcTextSizeA(
6421-
UIStyle.LargeFont->FontSize, std::numeric_limits<float>::max(), -1.0f, s_state.current_game_title.c_str(),
6422-
s_state.current_game_title.c_str() + s_state.current_game_title.size()));
6423-
const ImVec2 subtitle_size(UIStyle.MediumFont->CalcTextSizeA(
6424-
UIStyle.MediumFont->FontSize, std::numeric_limits<float>::max(), -1.0f, buffer.c_str(), buffer.end_ptr()));
6425-
6426-
ImVec2 title_pos(display_size.x - LayoutScale(10.0f + image_width + 20.0f) - title_size.x,
6427-
display_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT) - LayoutScale(10.0f + image_height));
6428-
ImVec2 subtitle_pos(display_size.x - LayoutScale(10.0f + image_width + 20.0f) - subtitle_size.x,
6429-
title_pos.y + UIStyle.LargeFont->FontSize + LayoutScale(4.0f));
6435+
ImVec2 text_pos = ImVec2(scaled_top_bar_padding + image_size + scaled_top_bar_padding, scaled_top_bar_padding);
6436+
DrawShadowedText(dl, UIStyle.LargeFont, text_pos, title_text_color, s_state.current_game_title.c_str(),
6437+
s_state.current_game_title.c_str() + s_state.current_game_title.size());
6438+
text_pos.y += UIStyle.LargeFont->FontSize + scaled_text_spacing;
64306439

6431-
float rp_height = 0.0f;
6440+
if (Achievements::IsActive())
64326441
{
64336442
const auto lock = Achievements::GetLock();
6434-
const std::string& rp = Achievements::IsActive() ? Achievements::GetRichPresenceString() : std::string();
6435-
6436-
if (!rp.empty())
6443+
if (const std::string& rp = Achievements::GetRichPresenceString(); !rp.empty())
64376444
{
6438-
const float wrap_width = LayoutScale(350.0f);
6439-
const ImVec2 rp_size =
6440-
UIStyle.MediumFont->CalcTextSizeA(UIStyle.MediumFont->FontSize, std::numeric_limits<float>::max(), wrap_width,
6441-
rp.data(), rp.data() + rp.length());
6442-
6443-
// Add a small extra gap if any Rich Presence is displayed
6444-
rp_height = rp_size.y - UIStyle.MediumFont->FontSize + LayoutScale(2.0f);
6445-
6446-
const ImVec2 rp_pos(display_size.x - LayoutScale(20.0f + 50.0f + 20.0f) - rp_size.x,
6447-
subtitle_pos.y + UIStyle.MediumFont->FontSize + LayoutScale(4.0f) - rp_height);
6448-
6449-
title_pos.y -= rp_height;
6450-
subtitle_pos.y -= rp_height;
6451-
6452-
DrawShadowedText(dl, UIStyle.MediumFont, rp_pos, text_color, rp.data(), rp.data() + rp.length(), wrap_width);
6445+
DrawShadowedText(dl, UIStyle.MediumFont, text_pos, title_text_color, rp.data(), rp.data() + rp.length());
6446+
text_pos.y += UIStyle.MediumFont->FontSize + scaled_text_spacing;
64536447
}
64546448
}
64556449

6456-
DrawShadowedText(dl, UIStyle.LargeFont, title_pos, text_color, s_state.current_game_title.c_str(),
6457-
s_state.current_game_title.c_str() + s_state.current_game_title.size());
6458-
DrawShadowedText(dl, UIStyle.MediumFont, subtitle_pos, text_color, buffer.c_str(), buffer.end_ptr());
6450+
DrawShadowedText(dl, UIStyle.MediumFont, text_pos, text_color, buffer.c_str(), buffer.end_ptr());
64596451

6460-
GPUTexture* const cover = GetCoverForCurrentGame();
6461-
const ImVec2 image_min(display_size.x - LayoutScale(10.0f + image_width),
6462-
display_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT) - LayoutScale(10.0f + image_height) -
6463-
rp_height);
6464-
const ImVec2 image_max(image_min.x + LayoutScale(image_width), image_min.y + LayoutScale(image_height) + rp_height);
6465-
const ImRect image_rect(CenterImage(ImRect(image_min, image_max), ImVec2(static_cast<float>(cover->GetWidth()),
6466-
static_cast<float>(cover->GetHeight()))));
6467-
dl->AddImage(cover, image_rect.Min, image_rect.Max);
6468-
}
6469-
6470-
// current time / play time
6471-
{
6452+
// current time / play time
64726453
buffer.format("{:%X}", fmt::localtime(std::time(nullptr)));
64736454

6474-
const ImVec2 time_size(UIStyle.LargeFont->CalcTextSizeA(
6475-
UIStyle.LargeFont->FontSize, std::numeric_limits<float>::max(), -1.0f, buffer.c_str(), buffer.end_ptr()));
6476-
const ImVec2 time_pos(display_size.x - LayoutScale(10.0f) - time_size.x, LayoutScale(10.0f));
6477-
DrawShadowedText(dl, UIStyle.LargeFont, time_pos, text_color, buffer.c_str(), buffer.end_ptr());
6455+
ImVec2 text_size = UIStyle.LargeFont->CalcTextSizeA(UIStyle.LargeFont->FontSize, std::numeric_limits<float>::max(),
6456+
-1.0f, buffer.c_str(), buffer.end_ptr());
6457+
text_pos = ImVec2(display_size.x - scaled_top_bar_padding - text_size.x, scaled_top_bar_padding);
6458+
DrawShadowedText(dl, UIStyle.LargeFont, text_pos, title_text_color, buffer.c_str(), buffer.end_ptr());
6459+
text_pos.y += UIStyle.LargeFont->FontSize + scaled_text_spacing;
64786460

64796461
if (!s_state.current_game_serial.empty())
64806462
{
64816463
const std::time_t cached_played_time = GameList::GetCachedPlayedTimeForSerial(s_state.current_game_serial);
64826464
const std::time_t session_time = static_cast<std::time_t>(System::GetSessionPlayedTime());
64836465

64846466
buffer.format(FSUI_FSTR("Session: {}"), GameList::FormatTimespan(session_time, true));
6485-
const ImVec2 session_size(UIStyle.MediumFont->CalcTextSizeA(
6467+
text_size = ImVec2(UIStyle.MediumFont->CalcTextSizeA(
64866468
UIStyle.MediumFont->FontSize, std::numeric_limits<float>::max(), -1.0f, buffer.c_str(), buffer.end_ptr()));
6487-
const ImVec2 session_pos(display_size.x - LayoutScale(10.0f) - session_size.x,
6488-
time_pos.y + UIStyle.LargeFont->FontSize + LayoutScale(4.0f));
6489-
DrawShadowedText(dl, UIStyle.MediumFont, session_pos, text_color, buffer.c_str(), buffer.end_ptr());
6469+
text_pos.x = display_size.x - scaled_top_bar_padding - text_size.x;
6470+
DrawShadowedText(dl, UIStyle.MediumFont, text_pos, text_color, buffer.c_str(), buffer.end_ptr());
6471+
text_pos.y += UIStyle.MediumFont->FontSize + scaled_text_spacing;
64906472

64916473
buffer.format(FSUI_FSTR("All Time: {}"), GameList::FormatTimespan(cached_played_time + session_time, true));
6492-
const ImVec2 total_size(UIStyle.MediumFont->CalcTextSizeA(
6474+
text_size = ImVec2(UIStyle.MediumFont->CalcTextSizeA(
64936475
UIStyle.MediumFont->FontSize, std::numeric_limits<float>::max(), -1.0f, buffer.c_str(), buffer.end_ptr()));
6494-
const ImVec2 total_pos(display_size.x - LayoutScale(10.0f) - total_size.x,
6495-
session_pos.y + UIStyle.MediumFont->FontSize + LayoutScale(4.0f));
6496-
DrawShadowedText(dl, UIStyle.MediumFont, total_pos, text_color, buffer.c_str(), buffer.end_ptr());
6476+
text_pos.x = display_size.x - scaled_top_bar_padding - text_size.x;
6477+
DrawShadowedText(dl, UIStyle.MediumFont, text_pos, text_color, buffer.c_str(), buffer.end_ptr());
6478+
text_pos.y += UIStyle.MediumFont->FontSize + scaled_text_spacing;
64976479
}
64986480
}
64996481

6500-
const ImVec2 window_size(LayoutScale(500.0f, LAYOUT_SCREEN_HEIGHT));
6501-
const ImVec2 window_pos(0.0f, display_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT) - window_size.y);
6482+
const ImVec2 window_size(LayoutScale(500.0f),
6483+
display_size.y - scaled_top_bar_height - LayoutScale(LAYOUT_FOOTER_HEIGHT));
6484+
const ImVec2 window_pos(0.0f, scaled_top_bar_height);
6485+
6486+
// background
6487+
dl->AddRectFilled(ImVec2(0.0f, scaled_top_bar_height),
6488+
ImVec2(display_size.x, display_size.x - scaled_top_bar_height - LayoutScale(LAYOUT_FOOTER_HEIGHT)),
6489+
ImGui::GetColorU32(ModAlpha(UIStyle.BackgroundColor, 0.85f)));
6490+
6491+
Achievements::DrawPauseMenuOverlays();
65026492

65036493
if (BeginFullscreenWindow(window_pos, window_size, "pause_menu", ImVec4(0.0f, 0.0f, 0.0f, 0.0f), 0.0f,
65046494
ImVec2(10.0f, 10.0f), ImGuiWindowFlags_NoBackground))

src/util/imgui_fullscreen.h

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ ALWAYS_INLINE static u32 ModAlpha(u32 col32, float a)
116116
return (col32 & ~IM_COL32_A_MASK) | (static_cast<u32>(a * 255.0f) << IM_COL32_A_SHIFT);
117117
}
118118

119+
// lighter in light themes
120+
ALWAYS_INLINE static ImVec4 DarkerColor(const ImVec4& v, float f = 0.75f)
121+
{
122+
// light theme
123+
f = (UIStyle.PrimaryTextColor.x < UIStyle.PrimaryColor.x) ? (1.0f / f) : f;
124+
return ImVec4(std::max(v.x, 1.0f / 255.0f) * f, std::max(v.y, 1.0f / 255.0f) * f, std::max(v.z, 1.0f / 255.0f) * f,
125+
v.w);
126+
}
127+
119128
ALWAYS_INLINE static ImVec4 MulAlpha(const ImVec4& v, float a)
120129
{
121130
return ImVec4(v.x, v.y, v.z, v.w * a);

0 commit comments

Comments
 (0)