FSUI: Make use of scalable fonts

This commit is contained in:
TheLastRar 2025-07-05 20:03:45 +01:00 committed by lightningterror
parent bb1e6d06e4
commit b069f51e6f
8 changed files with 401 additions and 431 deletions

View File

@ -2170,7 +2170,7 @@ void Achievements::DrawGameOverlays()
const char* text_start = s_active_progress_indicator->achievement->measured_progress;
const char* text_end = text_start + std::strlen(text_start);
const ImVec2 text_size = g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, text_start, text_end);
const ImVec2 text_size = g_medium_font.first->CalcTextSizeA(g_medium_font.second, FLT_MAX, 0.0f, text_start, text_end);
const ImVec2 progress_box_size = ImVec2(image_size.x + text_size.x + spacing + padding * 2.0f, image_size.y + padding * 2.0f);
const ImVec2 stack_direction = GetStackingDirection(EmuConfig.Achievements.OverlayPosition);
@ -2193,7 +2193,7 @@ void Achievements::DrawGameOverlays()
const ImVec2 text_pos = box_min + ImVec2(padding + image_size.x + spacing, (box_max.y - box_min.y - text_size.y) * 0.5f);
const ImVec4 text_clip_rect(text_pos.x, text_pos.y, box_max.x, box_max.y);
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, col, text_start, text_end, 0.0f, &text_clip_rect);
dl->AddText(g_medium_font.first, g_medium_font.second, text_pos, col, text_start, text_end, 0.0f, &text_clip_rect);
if (!indicator.active && opacity <= 0.01f)
{
@ -2219,8 +2219,8 @@ void Achievements::DrawGameOverlays()
width_string.append(ICON_FA_STOPWATCH);
for (u32 i = 0; i < indicator.text.length(); i++)
width_string.append('0');
const ImVec2 size = ImGuiFullscreen::g_medium_font->CalcTextSizeA(
ImGuiFullscreen::g_medium_font->FontSize, FLT_MAX, 0.0f, width_string.c_str(), width_string.end_ptr());
const ImVec2 size = g_medium_font.first->CalcTextSizeA(
g_medium_font.second, FLT_MAX, 0.0f, width_string.c_str(), width_string.end_ptr());
const ImVec2 tracker_box_size = ImVec2(size.x + padding * 2.0f, size.y + padding * 2.0f);
const ImVec2 box_position = AdjustPositionForAlignment(position, tracker_box_size, EmuConfig.Achievements.OverlayPosition);
@ -2232,16 +2232,16 @@ void Achievements::DrawGameOverlays()
dl->AddRect(box_min, box_max, ImGui::GetColorU32(ImVec4(0.8f, 0.8f, 0.8f, opacity)), box_rounding);
const u32 text_col = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, opacity));
const ImVec2 text_size = ImGuiFullscreen::g_medium_font->CalcTextSizeA(
ImGuiFullscreen::g_medium_font->FontSize, FLT_MAX, 0.0f, indicator.text.c_str(),
const ImVec2 text_size = g_medium_font.first->CalcTextSizeA(
g_medium_font.second, FLT_MAX, 0.0f, indicator.text.c_str(),
indicator.text.c_str() + indicator.text.length());
const ImVec2 text_pos = ImVec2(box_max.x - padding - text_size.x, box_min.y + padding);
const ImVec4 text_clip_rect(box_min.x, box_min.y, box_max.x, box_max.y);
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, text_col, indicator.text.c_str(),
dl->AddText(g_medium_font.first, g_medium_font.second, text_pos, text_col, indicator.text.c_str(),
indicator.text.c_str() + indicator.text.length(), 0.0f, &text_clip_rect);
const ImVec2 icon_pos = ImVec2(box_min.x + padding, box_min.y + padding);
dl->AddText(g_medium_font, g_medium_font->FontSize, icon_pos, text_col, ICON_FA_STOPWATCH,
dl->AddText(g_medium_font.first, g_medium_font.second, icon_pos, text_col, ICON_FA_STOPWATCH,
nullptr, 0.0f, &text_clip_rect);
if (!indicator.active && opacity <= 0.01f)
@ -2279,18 +2279,18 @@ void Achievements::DrawPauseMenuOverlays()
return;
const ImGuiIO& io = ImGui::GetIO();
ImFont* font = g_medium_font;
const std::pair<ImFont*, float> font = g_medium_font;
const ImVec2 image_size(
LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY));
const float start_y = LayoutScale(10.0f + 4.0f + 4.0f) + g_large_font->FontSize + (g_medium_font->FontSize * 2.0f);
const float start_y = LayoutScale(10.0f + 4.0f + 4.0f) + g_large_font.second + (g_medium_font.second * 2.0f);
const float margin = LayoutScale(10.0f);
const float spacing = LayoutScale(10.0f);
const float padding = LayoutScale(10.0f);
const float max_text_width = ImGuiFullscreen::LayoutScale(300.0f);
const float row_width = max_text_width + padding + padding + image_size.x + spacing;
const float title_height = padding + font->FontSize + padding;
const float title_height = padding + font.second + padding;
if (!s_active_challenge_indicators.empty())
{
@ -2300,11 +2300,11 @@ void Achievements::DrawPauseMenuOverlays()
ImDrawList* dl = ImGui::GetBackgroundDrawList();
dl->AddRectFilled(box_min, box_max, IM_COL32(0x21, 0x21, 0x21, 200), LayoutScale(10.0f));
dl->AddText(font, font->FontSize, ImVec2(box_min.x + padding, box_min.y + padding), IM_COL32(255, 255, 255, 255),
dl->AddText(font.first, font.second, ImVec2(box_min.x + padding, box_min.y + padding), IM_COL32(255, 255, 255, 255),
TRANSLATE("Achievements", "Active Challenge Achievements"));
const float y_advance = image_size.y + spacing;
const float acheivement_name_offset = (image_size.y - font->FontSize) / 2.0f;
const float acheivement_name_offset = (image_size.y - font.second) / 2.0f;
const float max_non_ellipised_text_width = max_text_width - LayoutScale(10.0f);
ImVec2 position(box_min.x + padding, box_min.y + title_height);
@ -2319,21 +2319,21 @@ void Achievements::DrawPauseMenuOverlays()
const char* achievement_title = indicator.achievement->title;
const char* achievement_title_end = achievement_title + std::strlen(indicator.achievement->title);
const char* remaining_text = nullptr;
const ImVec2 text_width(font->CalcTextSizeA(
font->FontSize, max_non_ellipised_text_width, 0.0f, achievement_title, achievement_title_end, &remaining_text));
const ImVec2 text_width(font.first->CalcTextSizeA(
font.second, max_non_ellipised_text_width, 0.0f, achievement_title, achievement_title_end, &remaining_text));
const ImVec2 text_position(position.x + image_size.x + spacing, position.y + acheivement_name_offset);
const ImVec4 text_bbox(text_position.x, text_position.y, text_position.x + max_text_width, text_position.y + image_size.y);
const u32 text_color = IM_COL32(255, 255, 255, 255);
if (remaining_text < achievement_title_end)
{
dl->AddText(font, font->FontSize, text_position, text_color, achievement_title, remaining_text, 0.0f, &text_bbox);
dl->AddText(font, font->FontSize, ImVec2(text_position.x + text_width.x, text_position.y), text_color, "...", nullptr, 0.0f,
dl->AddText(font.first, font.second, text_position, text_color, achievement_title, remaining_text, 0.0f, &text_bbox);
dl->AddText(font.first, font.second, ImVec2(text_position.x + text_width.x, text_position.y), text_color, "...", nullptr, 0.0f,
&text_bbox);
}
else
{
dl->AddText(font, font->FontSize, text_position, text_color, achievement_title, achievement_title_end, 0.0f, &text_bbox);
dl->AddText(font.first, font.second, text_position, text_color, achievement_title, achievement_title_end, 0.0f, &text_bbox);
}
position.y += y_advance;
@ -2422,19 +2422,19 @@ void Achievements::DrawAchievementsWindow()
FullscreenUI::ReturnToPreviousWindow();
}
const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + g_large_font->FontSize));
const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + g_large_font.second));
text.assign(s_game_title);
if (s_hardcore_mode)
text.append(TRANSLATE_SV("Achievements", " (Hardcore Mode)"));
top += g_large_font->FontSize + spacing;
top += g_large_font.second + spacing;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
const ImRect summary_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font->FontSize));
const ImRect summary_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font.second));
if (s_game_summary.num_core_achievements > 0)
{
if (s_game_summary.num_unlocked_achievements == s_game_summary.num_core_achievements)
@ -2454,9 +2454,9 @@ void Achievements::DrawAchievementsWindow()
text.assign(TRANSLATE_SV("Achievements", "This game has no achievements."));
}
top += g_medium_font->FontSize + spacing;
top += g_medium_font.second + spacing;
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(
summary_bb.Min, summary_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
@ -2472,12 +2472,12 @@ void Achievements::DrawAchievementsWindow()
ImGui::GetColorU32(ImGuiFullscreen::UISecondaryColor));
text.format("{}%", static_cast<int>(std::round(fraction * 100.0f)));
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
text_size = ImGui::CalcTextSize(text.c_str(), text.end_ptr());
ImGui::PopFont();
const ImVec2 text_pos(progress_bb.Min.x + ((progress_bb.Max.x - progress_bb.Min.x) / 2.0f) - (text_size.x / 2.0f),
progress_bb.Min.y + ((progress_bb.Max.y - progress_bb.Min.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryTextColor),
dl->AddText(g_medium_font.first, g_medium_font.second, text_pos, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryTextColor),
text.c_str(), text.end_ptr());
top += progress_height + spacing;
}
@ -2555,16 +2555,16 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
const bool is_measured = !is_unlocked && !measured_progress.empty();
const float unlock_size = is_unlocked ? (spacing + ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE) : 0.0f;
const ImVec2 points_template_size(
g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, TRANSLATE("Achievements", "XXX points")));
g_medium_font.first->CalcTextSizeA(g_medium_font.second, FLT_MAX, 0.0f, TRANSLATE("Achievements", "XXX points")));
const size_t summary_length = std::strlen(cheevo->description);
const float summary_wrap_width = (ImGui::GetCurrentWindow()->WorkRect.GetWidth() - (ImGui::GetStyle().FramePadding.x * 2.0f) -
LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT + 30.0f) - points_template_size.x);
const ImVec2 summary_text_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, summary_wrap_width, cheevo->description,
const ImVec2 summary_text_size(g_medium_font.first->CalcTextSizeA(g_medium_font.second, FLT_MAX, summary_wrap_width, cheevo->description,
cheevo->description + summary_length));
// Messy, but need to undo LayoutScale in MenuButtonFrame()...
const float extra_summary_height = LayoutUnscale(std::max(summary_text_size.y - g_medium_font->FontSize, 0.0f));
const float extra_summary_height = LayoutUnscale(std::max(summary_text_size.y - g_medium_font.second, 0.0f));
ImRect bb;
bool visible, hovered;
@ -2602,10 +2602,10 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
SmallString text;
const float midpoint = bb.Min.y + g_large_font->FontSize + spacing;
const float midpoint = bb.Min.y + g_large_font.second + spacing;
text.format((cheevo->points != 1) ? TRANSLATE_FS("Achievements", "{} points") : TRANSLATE_FS("Achievements", "{} point"), cheevo->points);
const ImVec2 points_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.end_ptr()));
const ImVec2 points_size(g_medium_font.first->CalcTextSizeA(g_medium_font.second, FLT_MAX, 0.0f, text.c_str(), text.end_ptr()));
const float points_template_start = bb.Max.x - points_template_size.x;
const float points_start = points_template_start + ((points_template_size.x - points_size.x) * 0.5f);
@ -2631,21 +2631,21 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
break;
}
const ImVec2 right_icon_size(g_large_font->CalcTextSizeA(g_large_font->FontSize, FLT_MAX, 0.0f, right_icon_text));
const ImVec2 right_icon_size(g_large_font.first->CalcTextSizeA(g_large_font.second, FLT_MAX, 0.0f, right_icon_text));
const float text_start_x = bb.Min.x + image_size.x + LayoutScale(15.0f);
const ImRect title_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(points_start, midpoint));
const ImRect summary_bb(ImVec2(text_start_x, midpoint), ImVec2(points_start, midpoint + g_medium_font->FontSize + extra_summary_height));
const ImRect summary_bb(ImVec2(text_start_x, midpoint), ImVec2(points_start, midpoint + g_medium_font.second + extra_summary_height));
const ImRect points_bb(ImVec2(points_start, midpoint), bb.Max);
const ImRect lock_bb(
ImVec2(points_template_start + ((points_template_size.x - right_icon_size.x) * 0.5f), bb.Min.y), ImVec2(bb.Max.x, midpoint));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, cheevo->title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::RenderTextClipped(lock_bb.Min, lock_bb.Max, right_icon_text, nullptr, &right_icon_size, ImVec2(0.0f, 0.0f), &lock_bb);
ImGui::PopFont();
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
if (cheevo->description && summary_length > 0)
{
ImGui::RenderTextWrapped(summary_bb.Min, cheevo->description, cheevo->description + summary_length, summary_wrap_width);
@ -2664,7 +2664,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
ImDrawList* dl = ImGui::GetWindowDrawList();
const float progress_height = LayoutScale(progress_height_unscaled);
const float progress_spacing = LayoutScale(progress_spacing_unscaled);
const float top = midpoint + g_medium_font->FontSize + progress_spacing;
const float top = midpoint + g_medium_font.second + progress_spacing;
const ImRect progress_bb(ImVec2(text_start_x, top), ImVec2(bb.Max.x, top + progress_height));
const float fraction = cheevo->measured_percent * 0.01f;
dl->AddRectFilled(progress_bb.Min, progress_bb.Max, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryDarkColor));
@ -2674,7 +2674,7 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo)
const ImVec2 text_size = ImGui::CalcTextSize(measured_progress.data(), measured_progress.data() + measured_progress.size());
const ImVec2 text_pos(progress_bb.Min.x + ((progress_bb.Max.x - progress_bb.Min.x) / 2.0f) - (text_size.x / 2.0f),
progress_bb.Min.y + ((progress_bb.Max.y - progress_bb.Min.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryTextColor),
dl->AddText(g_medium_font.first, g_medium_font.second, text_pos, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryTextColor),
measured_progress.data(), measured_progress.data() + measured_progress.size());
}
@ -2738,11 +2738,11 @@ void Achievements::DrawLeaderboardsWindow()
}
const float rank_column_width =
g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits<float>::max(), -1.0f, "99999").x;
g_large_font.first->CalcTextSizeA(g_large_font.second, std::numeric_limits<float>::max(), -1.0f, "99999").x;
const float name_column_width =
g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits<float>::max(), -1.0f, "WWWWWWWWWWWWWWWWWWWWWW").x;
g_large_font.first->CalcTextSizeA(g_large_font.second, std::numeric_limits<float>::max(), -1.0f, "WWWWWWWWWWWWWWWWWWWWWW").x;
const float time_column_width =
g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits<float>::max(), -1.0f, "WWWWWWWWWWW").x;
g_large_font.first->CalcTextSizeA(g_large_font.second, std::numeric_limits<float>::max(), -1.0f, "WWWWWWWWWWW").x;
const float column_spacing = spacing * 2.0f;
if (ImGuiFullscreen::BeginFullscreenWindow(ImVec2(), ImVec2(display_size.x, heading_height), "leaderboards_heading",
@ -2793,23 +2793,23 @@ void Achievements::DrawLeaderboardsWindow()
}
}
const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + g_large_font->FontSize));
const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + g_large_font.second));
text.assign(Achievements::GetGameTitle());
top += g_large_font->FontSize + spacing;
top += g_large_font.second + spacing;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (is_leaderboard_open)
{
const ImRect subtitle_bb(ImVec2(left, top), ImVec2(right, top + g_large_font->FontSize));
const ImRect subtitle_bb(ImVec2(left, top), ImVec2(right, top + g_large_font.second));
text.assign(s_open_leaderboard->title);
top += g_large_font->FontSize + spacing_small;
top += g_large_font.second + spacing_small;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(
subtitle_bb.Min, subtitle_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &subtitle_bb);
ImGui::PopFont();
@ -2824,17 +2824,17 @@ void Achievements::DrawLeaderboardsWindow()
text.format(TRANSLATE_FS("Achievements", "This game has {} leaderboards."), count);
}
const ImRect summary_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font->FontSize));
top += g_medium_font->FontSize + spacing_small;
const ImRect summary_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font.second));
top += g_medium_font.second + spacing_small;
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(
summary_bb.Min, summary_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
if (!is_leaderboard_open && !Achievements::IsHardcoreModeActive())
{
const ImRect hardcore_warning_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font->FontSize));
top += g_medium_font->FontSize + spacing_small;
const ImRect hardcore_warning_bb(ImVec2(left, top), ImVec2(right, top + g_medium_font.second));
top += g_medium_font.second + spacing_small;
ImGui::RenderTextClipped(hardcore_warning_bb.Min, hardcore_warning_bb.Max,
TRANSLATE("Achievements", "Submitting scores is disabled because hardcore mode is off. Leaderboards are read-only."),
@ -2871,10 +2871,10 @@ void Achievements::DrawLeaderboardsWindow()
ImGuiFullscreen::MenuButtonFrame(
"legend", false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, &visible, &hovered, &bb.Min, &bb.Max, 0, alpha);
const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + g_large_font.second + LayoutScale(4.0f);
float text_start_x = bb.Min.x + LayoutScale(15.0f) + padding;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
const ImRect rank_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint));
ImGui::RenderTextClipped(
@ -2907,7 +2907,7 @@ void Achievements::DrawLeaderboardsWindow()
const float line_thickness = LayoutScale(1.0f);
const float line_padding = LayoutScale(5.0f);
const ImVec2 line_start(bb.Min.x, bb.Min.y + g_large_font->FontSize + line_padding);
const ImVec2 line_start(bb.Min.x, bb.Min.y + g_large_font.second + line_padding);
const ImVec2 line_end(bb.Max.x, line_start.y);
ImGui::GetWindowDrawList()->AddLine(line_start, line_end, ImGui::GetColorU32(ImGuiCol_TextDisabled), line_thickness);
}
@ -2958,7 +2958,7 @@ void Achievements::DrawLeaderboardsWindow()
}
else
{
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
const ImVec2 pos_min(0.0f, heading_height);
const ImVec2 pos_max(display_size.x, display_size.y);
@ -2985,10 +2985,10 @@ void Achievements::DrawLeaderboardsWindow()
ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, &visible, &hovered, &bb.Min, &bb.Max);
if (visible)
{
const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + g_large_font.second + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(
title_bb.Min, title_bb.Max, TRANSLATE("Achievements", "Loading..."), nullptr, nullptr, ImVec2(0, 0), &title_bb);
ImGui::PopFont();
@ -3022,13 +3022,13 @@ void Achievements::DrawLeaderboardEntry(const rc_client_leaderboard_entry_t& ent
if (!visible)
return;
const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + g_large_font.second + LayoutScale(4.0f);
float text_start_x = bb.Min.x + LayoutScale(15.0f);
SmallString text;
text.format("{}", entry.rank);
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
if (is_self)
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 242, 0, 255));
@ -3102,18 +3102,18 @@ void Achievements::DrawLeaderboardListEntry(const rc_client_leaderboard_t* lboar
if (!visible)
return;
const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + g_large_font.second + LayoutScale(4.0f);
const float text_start_x = bb.Min.x + LayoutScale(15.0f);
const ImRect title_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(text_start_x, midpoint), bb.Max);
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, lboard->title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (lboard->description && lboard->description[0] != '\0')
{
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, lboard->description, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
}

View File

@ -371,27 +371,29 @@ void GSDumpReplayer::RenderUI()
float position_y = margin;
ImDrawList* dl = ImGui::GetBackgroundDrawList();
ImFont* font = ImGuiManager::GetFixedFont();
ImFont* const font = ImGuiManager::GetFixedFont();
const float font_size = ImGuiManager::GetFontSizeStandard();
std::string text;
ImVec2 text_size;
text.reserve(128);
#define DRAW_LINE(font, text, color) \
#define DRAW_LINE(font, size, text, color) \
do \
{ \
text_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, (text), nullptr, nullptr); \
text_size = font->CalcTextSizeA(size, std::numeric_limits<float>::max(), -1.0f, (text), nullptr, nullptr); \
const ImVec2 text_pos = CalculatePerformanceOverlayTextPosition(GSConfig.OsdMessagesPos, margin, text_size, ImGuiManager::GetWindowWidth(), position_y); \
dl->AddText(font, font->FontSize, ImVec2(text_pos.x + shadow_offset, text_pos.y + shadow_offset), IM_COL32(0, 0, 0, 100), (text)); \
dl->AddText(font, font->FontSize, text_pos, color, (text)); \
dl->AddText(font, size, ImVec2(text_pos.x + shadow_offset, text_pos.y + shadow_offset), IM_COL32(0, 0, 0, 100), (text)); \
dl->AddText(font, size, text_pos, color, (text)); \
position_y += text_size.y + spacing; \
} while (0)
fmt::format_to(std::back_inserter(text), "Dump Frame: {}", s_dump_frame_number);
DRAW_LINE(font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
text.clear();
fmt::format_to(std::back_inserter(text), "Packet Number: {}/{}", s_current_packet, static_cast<u32>(s_dump_file->GetPackets().size()));
DRAW_LINE(font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
#undef DRAW_LINE
}

View File

@ -356,43 +356,43 @@ namespace FullscreenUI
static bool DrawToggleSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
bool default_value, bool enabled = true, bool allow_tristate = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawIntListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
int default_value, const char* const* options, size_t option_count, bool translate_options, int option_offset = 0,
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font,
ImFont* summary_font = g_medium_font);
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font,
std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawIntRangeSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
int default_value, int min_value, int max_value, const char* format = "%d", bool enabled = true,
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
int default_value, int min_value, int max_value, int step_value, const char* format = "%d", bool enabled = true,
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
#if 0
// Unused as of now
static void DrawFloatRangeSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
float default_value, float min_value, float max_value, const char* format = "%f", float multiplier = 1.0f, bool enabled = true,
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
#endif
static void DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, float default_value, float min_value, float max_value, float step_value, float multiplier,
const char* format = "%f", bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawIntRectSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* left_key, int default_left, const char* top_key, int default_top, const char* right_key, int default_right,
const char* bottom_key, int default_bottom, int min_value, int max_value, int step_value, const char* format = "%d",
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font,
ImFont* summary_font = g_medium_font);
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font,
std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawStringListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
const char* default_value, const char* const* options, const char* const* option_values, size_t option_count,
bool translate_options, bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font,
ImFont* summary_font = g_medium_font, const char* translation_ctx = TR_CONTEXT);
bool translate_options, bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font,
std::pair<ImFont*, float> summary_font = g_medium_font, const char* translation_ctx = TR_CONTEXT);
static void DrawStringListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
const char* default_value, SettingInfo::GetOptionsCallback options_callback, bool enabled = true,
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawFloatListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
float default_value, const char* const* options, const float* option_values, size_t option_count, bool translate_options,
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font,
ImFont* summary_font = g_medium_font);
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font,
std::pair<ImFont*, float> summary_font = g_medium_font);
template <typename DataType, typename SizeType>
static void DrawEnumSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, DataType default_value,
@ -400,13 +400,13 @@ namespace FullscreenUI
const char* (*to_string_function)(DataType value),
const char* (*to_display_string_function)(DataType value), SizeType option_count,
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawFolderSetting(SettingsInterface* bsi, const char* title, const char* section, const char* key,
const std::string& runtime_var, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font,
ImFont* summary_font = g_medium_font);
const std::string& runtime_var, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font,
std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawPathSetting(SettingsInterface* bsi, const char* title, const char* section, const char* key, const char* default_value,
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font,
ImFont* summary_font = g_medium_font);
bool enabled = true, float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font,
std::pair<ImFont*, float> summary_font = g_medium_font);
static void DrawClampingModeSetting(SettingsInterface* bsi, const char* title, const char* summary, int vunum);
static void PopulateGraphicsAdapterList();
static void PopulateGameListDirectoryCache(SettingsInterface* si);
@ -764,9 +764,10 @@ bool FullscreenUI::Initialize()
ImGuiFullscreen::SetTheme(Host::GetBaseStringSettingValue("UI", "FullscreenUITheme", "Dark"));
ImGuiFullscreen::UpdateLayoutScale();
ImGuiFullscreen::UpdateFontScale();
ApplyLayoutSettings();
if (!ImGuiManager::AddFullscreenFontsIfMissing() || !ImGuiFullscreen::Initialize("fullscreenui/placeholder.png") || !LoadResources())
if (!ImGuiFullscreen::Initialize("fullscreenui/placeholder.png") || !LoadResources())
{
DestroyResources();
ImGuiFullscreen::Shutdown(true);
@ -1413,11 +1414,11 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "landing_heading", UIPrimaryColor))
{
ImFont* const heading_font = g_large_font;
const std::pair<ImFont*, float> heading_font = g_large_font;
ImDrawList* const dl = ImGui::GetWindowDrawList();
SmallString heading_str;
ImGui::PushFont(heading_font);
ImGui::PushFont(heading_font.first, heading_font.second);
ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor);
// draw branding
@ -1426,7 +1427,7 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
const ImVec2 logo_size = LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
dl->AddImage(reinterpret_cast<ImTextureID>(GetCachedTexture("icons/AppIconLarge.png")->GetNativeHandle()),
logo_pos, logo_pos + logo_size);
dl->AddText(heading_font, heading_font->FontSize,
dl->AddText(heading_font.first, heading_font.second,
ImVec2(logo_pos.x + logo_size.x + LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING), logo_pos.y),
ImGui::GetColorU32(ImGuiCol_Text), "PCSX2");
}
@ -1436,7 +1437,7 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
{
heading_str.format(FSUI_FSTR("{:%H:%M}"), fmt::localtime(std::time(nullptr)));
const ImVec2 time_size = heading_font->CalcTextSizeA(heading_font->FontSize, FLT_MAX, 0.0f, "00:00");
const ImVec2 time_size = heading_font.first->CalcTextSizeA(heading_font.second, FLT_MAX, 0.0f, "00:00");
time_pos = ImVec2(heading_size.x - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING) - time_size.x,
LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING));
ImGui::RenderTextClipped(time_pos, time_pos + time_size, heading_str.c_str(), heading_str.end_ptr(), &time_size);
@ -1449,7 +1450,7 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size)
const char* username = Achievements::GetLoggedInUserName();
if (username)
{
const ImVec2 name_size = heading_font->CalcTextSizeA(heading_font->FontSize, FLT_MAX, 0.0f, username);
const ImVec2 name_size = heading_font.first->CalcTextSizeA(heading_font.second, FLT_MAX, 0.0f, username);
const ImVec2 name_pos =
ImVec2(time_pos.x - name_size.x - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING), time_pos.y);
ImGui::RenderTextClipped(name_pos, name_pos + name_size, username, nullptr, &name_size);
@ -1785,11 +1786,11 @@ void FullscreenUI::DrawInputBindingButton(
}
}
const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + g_large_font.second + LayoutScale(4.0f);
if (oneline)
{
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
const ImVec2 value_size(ImGui::CalcTextSize(value.empty() ? FSUI_CSTR("-") : value.c_str(), nullptr));
const float text_end = bb.Max.x - value_size.x;
@ -1806,12 +1807,12 @@ void FullscreenUI::DrawInputBindingButton(
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, show_type ? title.c_str() : display_name, nullptr, nullptr,
ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, value.empty() ? FSUI_CSTR("No Binding") : value.c_str(),
nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
@ -1937,7 +1938,7 @@ void FullscreenUI::DrawInputBindingWindow()
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::OpenPopup(title);
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -1958,7 +1959,7 @@ void FullscreenUI::DrawInputBindingWindow()
}
bool FullscreenUI::DrawToggleSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
bool default_value, bool enabled, bool allow_tristate, float height, ImFont* font, ImFont* summary_font)
bool default_value, bool enabled, bool allow_tristate, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
if (!allow_tristate || !IsEditingGameSettings(bsi))
{
@ -1988,7 +1989,7 @@ bool FullscreenUI::DrawToggleSetting(SettingsInterface* bsi, const char* title,
void FullscreenUI::DrawIntListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
int default_value, const char* const* options, size_t option_count, bool translate_options, int option_offset, bool enabled,
float height, ImFont* font, ImFont* summary_font)
float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
if (options && option_count == 0)
{
@ -2044,7 +2045,7 @@ void FullscreenUI::DrawIntListSetting(SettingsInterface* bsi, const char* title,
}
void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section, const char* key,
int default_value, int min_value, int max_value, const char* format, bool enabled, float height, ImFont* font, ImFont* summary_font)
int default_value, int min_value, int max_value, const char* format, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<int> value =
@ -2058,7 +2059,7 @@ void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title
ImGui::SetNextWindowSize(LayoutScale(500.0f, 192.0f));
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2099,7 +2100,7 @@ void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title
void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, int default_value, int min_value, int max_value, int step_value, const char* format, bool enabled, float height,
ImFont* font, ImFont* summary_font)
std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<int> value =
@ -2118,7 +2119,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit
ImGui::SetNextWindowSize(LayoutScale(500.0f, 192.0f));
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2157,7 +2158,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit
// Align value text in middle.
ImGui::SetCursorPosY(
button_pos.y + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - g_large_font->FontSize) * 0.5f);
button_pos.y + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - g_large_font.second) * 0.5f);
ImGui::TextUnformatted(str_value);
s32 step = 0;
@ -2220,7 +2221,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit
// Unused as of now
void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, float default_value, float min_value, float max_value, const char* format, float multiplier, bool enabled,
float height, ImFont* font, ImFont* summary_font)
float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<float> value =
@ -2234,7 +2235,7 @@ void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* tit
ImGui::SetNextWindowSize(LayoutScale(500.0f, 190.0f));
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2278,7 +2279,7 @@ void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* tit
void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, float default_value, float min_value, float max_value, float step_value, float multiplier, const char* format,
bool enabled, float height, ImFont* font, ImFont* summary_font)
bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<float> value =
@ -2297,7 +2298,7 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t
ImGui::SetNextWindowSize(LayoutScale(500.0f, 192.0f));
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2343,7 +2344,7 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t
// Align value text in middle.
ImGui::SetCursorPosY(
button_pos.y + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - g_large_font->FontSize) * 0.5f);
button_pos.y + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - g_large_font.second) * 0.5f);
ImGui::TextUnformatted(str_value);
float step = 0;
@ -2405,7 +2406,7 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t
void FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* left_key, int default_left, const char* top_key, int default_top, const char* right_key, int default_right,
const char* bottom_key, int default_bottom, int min_value, int max_value, int step_value, const char* format, bool enabled,
float height, ImFont* font, ImFont* summary_font)
float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<int> left_value =
@ -2433,7 +2434,7 @@ void FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title,
ImGui::SetNextWindowSize(LayoutScale(550.0f, 370.0f));
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2488,7 +2489,7 @@ void FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title,
// Align value text in middle.
ImGui::SetCursorPosY(ImGui::GetCursorPosY() +
((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - g_large_font->FontSize) * 0.5f);
((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - g_large_font.second) * 0.5f);
ImGui::TextUnformatted(Host::TranslateToCString(TR_CONTEXT, labels[i]));
ImGui::SameLine(midpoint);
ImGui::SetNextItemWidth(end);
@ -2573,7 +2574,7 @@ void FullscreenUI::DrawIntRectSetting(SettingsInterface* bsi, const char* title,
void FullscreenUI::DrawStringListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, const char* default_value, const char* const* options, const char* const* option_values, size_t option_count,
bool translate_options, bool enabled, float height, ImFont* font, ImFont* summary_font, const char* translation_ctx)
bool translate_options, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font, const char* translation_ctx)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<SmallString> value(
@ -2642,8 +2643,8 @@ void FullscreenUI::DrawStringListSetting(SettingsInterface* bsi, const char* tit
}
void FullscreenUI::DrawStringListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, const char* default_value, SettingInfo::GetOptionsCallback option_callback, bool enabled, float height, ImFont* font,
ImFont* summary_font)
const char* key, const char* default_value, SettingInfo::GetOptionsCallback option_callback, bool enabled, float height, std::pair<ImFont*, float> font,
std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<SmallString> value(
@ -2687,7 +2688,7 @@ void FullscreenUI::DrawStringListSetting(SettingsInterface* bsi, const char* tit
void FullscreenUI::DrawFloatListSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, float default_value, const char* const* options, const float* option_values, size_t option_count,
bool translate_options, bool enabled, float height, ImFont* font, ImFont* summary_font)
bool translate_options, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<float> value(
@ -2759,7 +2760,7 @@ template <typename DataType, typename SizeType>
void FullscreenUI::DrawEnumSetting(SettingsInterface* bsi, const char* title, const char* summary, const char* section,
const char* key, DataType default_value, std::optional<DataType> (*from_string_function)(const char* str),
const char* (*to_string_function)(DataType value), const char* (*to_display_string_function)(DataType value), SizeType option_count,
bool enabled, float height, ImFont* font, ImFont* summary_font)
bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<SmallString> value(bsi->GetOptionalSmallStringValue(
@ -2807,8 +2808,8 @@ void FullscreenUI::DrawEnumSetting(SettingsInterface* bsi, const char* title, co
}
void FullscreenUI::DrawFolderSetting(SettingsInterface* bsi, const char* title, const char* section, const char* key,
const std::string& runtime_var, float height /* = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT */, ImFont* font /* = g_large_font */,
ImFont* summary_font /* = g_medium_font */)
const std::string& runtime_var, float height /* = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT */, std::pair<ImFont*, float> font /* = g_large_font */,
std::pair<ImFont*, float> summary_font /* = g_medium_font */)
{
if (MenuButton(title, runtime_var.c_str()))
{
@ -2833,7 +2834,7 @@ void FullscreenUI::DrawFolderSetting(SettingsInterface* bsi, const char* title,
void FullscreenUI::DrawPathSetting(SettingsInterface* bsi, const char* title, const char* section, const char* key,
const char* default_value, bool enabled /* = true */, float height /* = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT */,
ImFont* font /* = g_large_font */, ImFont* summary_font /* = g_medium_font */)
std::pair<ImFont*, float> font /* = g_large_font */, std::pair<ImFont*, float> summary_font /* = g_medium_font */)
{
const bool game_settings = IsEditingGameSettings(bsi);
const std::optional<SmallString> value(
@ -5121,7 +5122,7 @@ void FullscreenUI::DrawControllerSettingsPage()
ImGui::SetNextWindowSize(LayoutScale(500.0f, 180.0f));
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -5586,10 +5587,10 @@ void FullscreenUI::DrawGameFixesSettingsPage()
}
static void DrawShadowedText(
ImDrawList* dl, ImFont* font, const ImVec2& pos, u32 col, const char* text, const char* text_end = nullptr, float wrap_width = 0.0f)
ImDrawList* dl, std::pair<ImFont*, float> font, const ImVec2& pos, u32 col, const char* text, const char* text_end = nullptr, float wrap_width = 0.0f)
{
dl->AddText(font, font->FontSize, pos + LayoutScale(1.0f, 1.0f), IM_COL32(0, 0, 0, 100), text, text_end, wrap_width);
dl->AddText(font, font->FontSize, pos, col, text, text_end, wrap_width);
dl->AddText(font.first, font.second, pos + LayoutScale(1.0f, 1.0f), IM_COL32(0, 0, 0, 100), text, text_end, wrap_width);
dl->AddText(font.first, font.second, pos, col, text, text_end, wrap_width);
}
void FullscreenUI::DrawPauseMenu(MainWindowType type)
@ -5606,20 +5607,20 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
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()));
g_large_font.first->CalcTextSizeA(g_large_font.second, std::numeric_limits<float>::max(), -1.0f, s_current_game_title.c_str()));
const ImVec2 path_size(path_string.empty() ?
ImVec2(0.0f, 0.0f) :
g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits<float>::max(), -1.0f,
g_medium_font.first->CalcTextSizeA(g_medium_font.second, std::numeric_limits<float>::max(), -1.0f,
path_string.data(), path_string.data() + path_string.length()));
const ImVec2 subtitle_size(g_medium_font->CalcTextSizeA(
g_medium_font->FontSize, std::numeric_limits<float>::max(), -1.0f, s_current_game_subtitle.c_str()));
const ImVec2 subtitle_size(g_medium_font.first->CalcTextSizeA(
g_medium_font.second, std::numeric_limits<float>::max(), -1.0f, s_current_game_subtitle.c_str()));
ImVec2 title_pos(display_size.x - LayoutScale(10.0f + image_width + 20.0f) - title_size.x,
display_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT) - LayoutScale(10.0f + image_height));
ImVec2 path_pos(display_size.x - LayoutScale(10.0f + image_width + 20.0f) - path_size.x,
title_pos.y + g_large_font->FontSize + LayoutScale(4.0f));
title_pos.y + g_large_font.second + LayoutScale(4.0f));
ImVec2 subtitle_pos(display_size.x - LayoutScale(10.0f + image_width + 20.0f) - subtitle_size.x,
(path_string.empty() ? title_pos.y + g_large_font->FontSize : path_pos.y + g_medium_font->FontSize) + LayoutScale(4.0f));
(path_string.empty() ? title_pos.y + g_large_font.second : path_pos.y + g_medium_font.second) + LayoutScale(4.0f));
float rp_height = 0.0f;
{
@ -5629,14 +5630,14 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
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.length());
const ImVec2 rp_size = g_medium_font.first->CalcTextSizeA(
g_medium_font.second, std::numeric_limits<float>::max(), wrap_width, rp.data(), rp.data() + rp.length());
// Add a small extra gap if any Rich Presence is displayed
rp_height = rp_size.y - g_medium_font->FontSize + LayoutScale(2.0f);
rp_height = rp_size.y - g_medium_font.second + LayoutScale(2.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);
subtitle_pos.y + g_medium_font.second + LayoutScale(4.0f) - rp_height);
title_pos.y -= rp_height;
path_pos.y -= rp_height;
@ -5679,7 +5680,7 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
#endif
std::strftime(buf, sizeof(buf), "%X", &ltime);
const ImVec2 time_size(g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits<float>::max(), -1.0f, buf));
const ImVec2 time_size(g_large_font.first->CalcTextSizeA(g_large_font.second, std::numeric_limits<float>::max(), -1.0f, buf));
const ImVec2 time_pos(display_size.x - LayoutScale(10.0f) - time_size.x, LayoutScale(10.0f));
DrawShadowedText(dl, g_large_font, time_pos, text_color, buf);
@ -5692,15 +5693,15 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
SmallString buf;
buf.format(FSUI_FSTR("This Session: {}"), session_time_str);
const ImVec2 session_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits<float>::max(), -1.0f, buf));
const ImVec2 session_size(g_medium_font.first->CalcTextSizeA(g_medium_font.second, std::numeric_limits<float>::max(), -1.0f, buf));
const ImVec2 session_pos(
display_size.x - LayoutScale(10.0f) - session_size.x, time_pos.y + g_large_font->FontSize + LayoutScale(4.0f));
display_size.x - LayoutScale(10.0f) - session_size.x, time_pos.y + g_large_font.second + LayoutScale(4.0f));
DrawShadowedText(dl, g_medium_font, session_pos, text_color, buf);
buf.format(FSUI_FSTR("All Time: {}"), played_time_str);
const ImVec2 total_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits<float>::max(), -1.0f, buf));
const ImVec2 total_size(g_medium_font.first->CalcTextSizeA(g_medium_font.second, std::numeric_limits<float>::max(), -1.0f, buf));
const ImVec2 total_pos(
display_size.x - LayoutScale(10.0f) - total_size.x, session_pos.y + g_medium_font->FontSize + LayoutScale(4.0f));
display_size.x - LayoutScale(10.0f) - total_size.x, session_pos.y + g_medium_font.second + LayoutScale(4.0f));
DrawShadowedText(dl, g_medium_font, total_pos, text_color, buf);
}
}
@ -6066,8 +6067,8 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
const float image_width = item_width - (style.FramePadding.x * 2.0f);
const float image_height = image_width / 1.33f;
const ImVec2 image_size(image_width, image_height);
const float item_height = (style.FramePadding.y * 2.0f) + image_height + title_spacing + g_large_font->FontSize + summary_spacing +
g_medium_font->FontSize;
const float item_height = (style.FramePadding.y * 2.0f) + image_height + title_spacing + g_large_font.second + summary_spacing +
g_medium_font.second;
const ImVec2 item_size(item_width, item_height);
const u32 grid_count_x = std::floor(ImGui::GetWindowWidth() / item_width_with_spacing);
const float start_x =
@ -6086,7 +6087,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
// can't use a choice dialog here, because we're already in a modal...
ImGuiFullscreen::PushResetLayout();
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -6097,7 +6098,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
const float width = LayoutScale(600.0f);
const float title_height =
g_large_font->FontSize + ImGui::GetStyle().FramePadding.y * 2.0f + ImGui::GetStyle().WindowPadding.y * 2.0f;
g_large_font.second + ImGui::GetStyle().FramePadding.y * 2.0f + ImGui::GetStyle().WindowPadding.y * 2.0f;
const float height =
title_height + LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY + (LAYOUT_MENU_BUTTON_Y_PADDING * 2.0f)) * 3.0f;
ImGui::SetNextWindowSize(ImVec2(width, height));
@ -6230,16 +6231,16 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading)
image_rect.Min, image_rect.Max, ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), IM_COL32(255, 255, 255, 255));
const ImVec2 title_pos(bb.Min.x, bb.Min.y + image_height + title_spacing);
const ImRect title_bb(title_pos, ImVec2(bb.Max.x, title_pos.y + g_large_font->FontSize));
ImGui::PushFont(g_large_font);
const ImRect title_bb(title_pos, ImVec2(bb.Max.x, title_pos.y + g_large_font.second));
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, entry.title.c_str(), nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (!entry.summary.empty())
{
const ImVec2 summary_pos(bb.Min.x, title_pos.y + g_large_font->FontSize + summary_spacing);
const ImRect summary_bb(summary_pos, ImVec2(bb.Max.x, summary_pos.y + g_medium_font->FontSize));
ImGui::PushFont(g_medium_font);
const ImVec2 summary_pos(bb.Min.x, title_pos.y + g_large_font.second + summary_spacing);
const ImRect summary_bb(summary_pos, ImVec2(bb.Max.x, summary_pos.y + g_medium_font.second));
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(
summary_bb.Min, summary_bb.Max, entry.summary.c_str(), nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
@ -6338,7 +6339,7 @@ void FullscreenUI::DrawResumeStateSelector()
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::OpenPopup(FSUI_CSTR("Load Resume State"));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
@ -6683,12 +6684,12 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
DrawGameCover(entry, ImGui::GetWindowDrawList(), bb.Min, bb.Min + image_size);
const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + g_large_font.second + LayoutScale(4.0f);
const float text_start_x = bb.Min.x + image_size.x + LayoutScale(15.0f);
const ImRect title_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(text_start_x, midpoint), bb.Max);
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
// TODO: Fix font fallback issues and enable native-language titles
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, entry->GetTitle(true).c_str(), entry->GetTitle(true).c_str() + entry->GetTitle(true).size(), nullptr,
ImVec2(0.0f, 0.0f), &title_bb);
@ -6696,7 +6697,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
if (!summary.empty())
{
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(
summary_bb.Min, summary_bb.Max, summary.c_str(), nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
@ -6767,7 +6768,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
if (selected_entry)
{
// title
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
const std::string_view title(std::string_view(selected_entry->GetTitle(true)).substr(0, 37));
text_width = ImGui::CalcTextSize(title.data(), title.data() + title.length(), false, work_width).x;
if (title.length() != selected_entry->GetTitle(true).length())
@ -6777,7 +6778,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
"%.*s%s", static_cast<int>(title.size()), title.data(), (title.length() == selected_entry->GetTitle(true).length()) ? "" : "...");
ImGui::PopFont();
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
// code
text_width = ImGui::CalcTextSize(selected_entry->serial.c_str(), nullptr, false, work_width).x;
@ -6827,7 +6828,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
{
// title
const char* title = FSUI_CSTR("No Game Selected");
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
text_width = ImGui::CalcTextSize(title, nullptr, false, work_width).x;
ImGui::SetCursorPosX((work_width - text_width) / 2.0f);
ImGui::TextWrapped("%s", title);
@ -6870,7 +6871,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
const float image_width = item_width - (style.FramePadding.x * 2.0f);
const float image_height = image_width * 1.33f;
const ImVec2 image_size(image_width, image_height);
const float item_height = (style.FramePadding.y * 2.0f) + image_height + title_spacing + g_medium_font->FontSize;
const float item_height = (style.FramePadding.y * 2.0f) + image_height + title_spacing + g_medium_font.second;
const ImVec2 item_size(item_width, item_height);
const u32 grid_count_x = std::floor(ImGui::GetWindowWidth() / item_width_with_spacing);
const float start_x =
@ -6926,7 +6927,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
const std::string_view title(std::string_view(entry->GetTitle(true)).substr(0, 31));
draw_title.clear();
fmt::format_to(std::back_inserter(draw_title), "{}{}", title, (title.length() == entry->GetTitle(true).length()) ? "" : "...");
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, draw_title.c_str(), draw_title.c_str() + draw_title.length(), nullptr,
ImVec2(0.5f, 0.0f), &title_bb);
ImGui::PopFont();
@ -7346,7 +7347,7 @@ void FullscreenUI::DrawAboutWindow()
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::OpenPopup(FSUI_CSTR("About PCSX2"));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(30.0f, 30.0f));
@ -7435,7 +7436,7 @@ void FullscreenUI::DrawAchievementsLoginWindow()
{
const float content_width = ImGui::GetContentRegionAvail().x;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
const float icon_height = LayoutScale(24.0f);
const float icon_width = icon_height * (500.0f / 275.0f);

View File

@ -60,10 +60,9 @@ namespace ImGuiFullscreen
static void SetFileSelectorDirectory(std::string dir);
static ImGuiID GetBackgroundProgressID(const char* str_id);
ImFont* g_standard_font = nullptr;
ImFont* g_medium_font = nullptr;
ImFont* g_large_font = nullptr;
ImFont* g_icon_font = nullptr;
std::pair<ImFont*, float> g_standard_font{};
std::pair<ImFont*, float> g_medium_font{};
std::pair<ImFont*, float> g_large_font{};
float g_layout_scale = 1.0f;
float g_rcp_layout_scale = 1.0f;
@ -205,11 +204,11 @@ namespace ImGuiFullscreen
static InputLayout s_gamepad_layout = InputLayout::Unknown;
} // namespace ImGuiFullscreen
void ImGuiFullscreen::SetFonts(ImFont* standard_font, ImFont* medium_font, ImFont* large_font)
void ImGuiFullscreen::SetFont(ImFont* standard_font)
{
g_standard_font = standard_font;
g_medium_font = medium_font;
g_large_font = large_font;
g_standard_font.first = standard_font;
g_medium_font.first = standard_font;
g_large_font.first = standard_font;
}
bool ImGuiFullscreen::Initialize(const char* placeholder_image_path)
@ -244,9 +243,9 @@ void ImGuiFullscreen::Shutdown(bool clear_state)
s_texture_upload_queue.clear();
s_placeholder_texture.reset();
g_standard_font = nullptr;
g_medium_font = nullptr;
g_large_font = nullptr;
g_standard_font.first = nullptr;
g_medium_font.first = nullptr;
g_large_font.first = nullptr;
s_texture_cache.Clear();
@ -646,6 +645,13 @@ bool ImGuiFullscreen::UpdateLayoutScale()
return g_layout_scale != old_scale;
}
void ImGuiFullscreen::UpdateFontScale()
{
g_standard_font.second = ImGuiManager::GetFontSizeStandard();
g_medium_font.second = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE);
g_large_font.second = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE);
}
ImRect ImGuiFullscreen::CenterImage(const ImVec2& fit_size, const ImVec2& image_size, bool fill)
{
const float fit_ar = fit_size.x / fit_size.y;
@ -857,7 +863,7 @@ bool ImGuiFullscreen::BeginFullscreenColumns(const char* title, float pos_y, boo
bool clipped;
if (title)
{
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
clipped = ImGui::Begin(title, nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
ImGui::PopFont();
}
@ -999,7 +1005,7 @@ void ImGuiFullscreen::DrawFullscreenFooter()
ImDrawList* dl = ImGui::GetForegroundDrawList();
dl->AddRectFilled(ImVec2(0.0f, io.DisplaySize.y - height), io.DisplaySize, ImGui::GetColorU32(UIPrimaryColor), 0.0f);
ImFont* const font = g_medium_font;
const std::pair<ImFont*, float> font = g_medium_font;
const float max_width = io.DisplaySize.x - padding * 2.0f;
float prev_opacity = 0.0f;
@ -1017,11 +1023,11 @@ void ImGuiFullscreen::DrawFullscreenFooter()
if (prev_opacity > 0.0f)
{
const ImVec2 text_size =
font->CalcTextSizeA(font->FontSize, max_width, 0.0f, s_last_fullscreen_footer_text.c_str(),
font.first->CalcTextSizeA(font.second, max_width, 0.0f, s_last_fullscreen_footer_text.c_str(),
s_last_fullscreen_footer_text.end_ptr());
dl->AddText(
font, font->FontSize,
ImVec2(io.DisplaySize.x - padding * 2.0f - text_size.x, io.DisplaySize.y - font->FontSize - padding),
font.first, font.second,
ImVec2(io.DisplaySize.x - padding * 2.0f - text_size.x, io.DisplaySize.y - font.second - padding),
ImGui::GetColorU32(ImVec4(UIPrimaryTextColor.x, UIPrimaryTextColor.y, UIPrimaryTextColor.z, prev_opacity)),
s_last_fullscreen_footer_text.c_str(), s_last_fullscreen_footer_text.end_ptr());
}
@ -1033,11 +1039,11 @@ void ImGuiFullscreen::DrawFullscreenFooter()
if (prev_opacity < 1.0f)
{
const ImVec2 text_size = font->CalcTextSizeA(font->FontSize, max_width, 0.0f, s_fullscreen_footer_text.c_str(),
const ImVec2 text_size = font.first->CalcTextSizeA(font.second, max_width, 0.0f, s_fullscreen_footer_text.c_str(),
s_fullscreen_footer_text.end_ptr());
dl->AddText(
font, font->FontSize,
ImVec2(io.DisplaySize.x - padding * 2.0f - text_size.x, io.DisplaySize.y - font->FontSize - padding),
font.first, font.second,
ImVec2(io.DisplaySize.x - padding * 2.0f - text_size.x, io.DisplaySize.y - font.second - padding),
ImGui::GetColorU32(ImVec4(UIPrimaryTextColor.x, UIPrimaryTextColor.y, UIPrimaryTextColor.z, 1.0f - prev_opacity)),
s_fullscreen_footer_text.c_str(), s_fullscreen_footer_text.end_ptr());
}
@ -1094,18 +1100,18 @@ void ImGuiFullscreen::DrawWindowTitle(const char* title)
ImGuiWindow* window = ImGui::GetCurrentWindow();
const ImVec2 pos(window->DC.CursorPos + LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING));
const ImVec2 size(window->WorkRect.GetWidth() - (LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING) * 2.0f),
g_large_font->FontSize + LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f);
g_large_font.second + LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f);
const ImRect rect(pos, pos + size);
ImGui::ItemSize(size);
if (!ImGui::ItemAdd(rect, window->GetID("window_title")))
return;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(rect.Min, rect.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &rect);
ImGui::PopFont();
const ImVec2 line_start(pos.x, pos.y + g_large_font->FontSize + LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING));
const ImVec2 line_start(pos.x, pos.y + g_large_font.second + LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING));
const ImVec2 line_end(pos.x + size.x, line_start.y);
const float line_thickness = LayoutScale(1.0f);
ImDrawList* dl = ImGui::GetWindowDrawList();
@ -1256,14 +1262,14 @@ void ImGuiFullscreen::MenuHeading(const char* title, bool draw_line /*= true*/)
return;
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(bb.Min, bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &bb);
ImGui::PopFont();
ImGui::PopStyleColor();
if (draw_line)
{
const ImVec2 line_start(bb.Min.x, bb.Min.y + g_large_font->FontSize + line_padding);
const ImVec2 line_start(bb.Min.x, bb.Min.y + g_large_font.second + line_padding);
const ImVec2 line_end(bb.Max.x, line_start.y);
ImGui::GetWindowDrawList()->AddLine(line_start, line_end, ImGui::GetColorU32(ImGuiCol_TextDisabled), line_thickness);
}
@ -1283,12 +1289,12 @@ bool ImGuiFullscreen::MenuHeadingButton(
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::RenderTextClipped(bb.Min, bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &bb);
if (value)
{
const ImVec2 value_size(g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits<float>::max(), 0.0f, value));
const ImVec2 value_size(g_large_font.first->CalcTextSizeA(g_large_font.second, std::numeric_limits<float>::max(), 0.0f, value));
const ImRect value_bb(ImVec2(bb.Max.x - value_size.x, bb.Min.y), ImVec2(bb.Max.x, bb.Max.y));
ImGui::RenderTextClipped(value_bb.Min, value_bb.Max, value, nullptr, nullptr, ImVec2(0.0f, 0.0f), &value_bb);
}
@ -1299,7 +1305,7 @@ bool ImGuiFullscreen::MenuHeadingButton(
if (draw_line)
{
const ImVec2 line_start(bb.Min.x, bb.Min.y + g_large_font->FontSize + line_padding);
const ImVec2 line_start(bb.Min.x, bb.Min.y + g_large_font.second + line_padding);
const ImVec2 line_end(bb.Max.x, line_start.y);
ImGui::GetWindowDrawList()->AddLine(line_start, line_end, ImGui::GetColorU32(ImGuiCol_TextDisabled), line_thickness);
}
@ -1307,13 +1313,13 @@ bool ImGuiFullscreen::MenuHeadingButton(
return pressed;
}
bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabled, float height, ImFont* font)
bool ImGuiFullscreen::ActiveButton(const char* title, bool is_active, bool enabled, float height, std::pair<ImFont*, float> font)
{
return ActiveButtonWithRightText(title, nullptr, is_active, enabled, height, font);
}
bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* right_title, bool is_active,
bool enabled, float height, ImFont* font)
bool enabled, float height, std::pair<ImFont*, float> font)
{
if (is_active)
{
@ -1336,13 +1342,13 @@ bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* r
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
if (right_title && *right_title)
{
const ImVec2 right_text_size = font->CalcTextSizeA(font->FontSize, title_bb.GetWidth(), 0.0f, right_title);
const ImVec2 right_text_size = font.first->CalcTextSizeA(font.second, title_bb.GetWidth(), 0.0f, right_title);
const ImVec2 right_text_start = ImVec2(title_bb.Max.x - right_text_size.x, title_bb.Min.y);
ImGui::RenderTextClipped(right_text_start, title_bb.Max, right_title, nullptr, &right_text_size, ImVec2(0.0f, 0.0f),
&title_bb);
@ -1357,7 +1363,7 @@ bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* r
return pressed;
}
bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool enabled, float height, ImFont* font, ImFont* summary_font)
bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
ImRect bb;
bool visible, hovered;
@ -1365,20 +1371,20 @@ bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool en
if (!visible)
return false;
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + font.second + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (summary)
{
ImGui::PushFont(summary_font);
ImGui::PushFont(summary_font.first, summary_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
}
@ -1390,7 +1396,7 @@ bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool en
return pressed;
}
bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled, float height, ImFont* font, const ImVec2& text_align)
bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled, float height, std::pair<ImFont*, float> font, const ImVec2& text_align)
{
ImRect bb;
bool visible, hovered;
@ -1398,14 +1404,14 @@ bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled,
if (!visible)
return false;
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + font.second + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, text_align, &title_bb);
ImGui::PopFont();
@ -1417,7 +1423,7 @@ bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled,
}
bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, ImTextureID user_texture_id, const ImVec2& image_size,
bool enabled, float height, const ImVec2& uv0, const ImVec2& uv1, ImFont* title_font, ImFont* summary_font)
bool enabled, float height, const ImVec2& uv0, const ImVec2& uv1, std::pair<ImFont*, float> title_font, std::pair<ImFont*, float> summary_font)
{
ImRect bb;
bool visible, hovered;
@ -1428,7 +1434,7 @@ bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, Im
ImGui::GetWindowDrawList()->AddImage(user_texture_id, bb.Min, bb.Min + image_size, uv0, uv1,
enabled ? IM_COL32(255, 255, 255, 255) : ImGui::GetColorU32(ImGuiCol_TextDisabled));
const float midpoint = bb.Min.y + title_font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + title_font.second + LayoutScale(4.0f);
const float text_start_x = bb.Min.x + image_size.x + LayoutScale(15.0f);
const ImRect title_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(text_start_x, midpoint), bb.Max);
@ -1436,13 +1442,13 @@ bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, Im
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(title_font);
ImGui::PushFont(title_font.first, title_font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (summary)
{
ImGui::PushFont(summary_font);
ImGui::PushFont(summary_font.first, summary_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
}
@ -1455,9 +1461,9 @@ bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, Im
}
bool ImGuiFullscreen::FloatingButton(const char* text, float x, float y, float width, float height, float anchor_x, float anchor_y,
bool enabled, ImFont* font, ImVec2* out_position, bool repeat_button)
bool enabled, std::pair<ImFont*, float> font, ImVec2* out_position, bool repeat_button)
{
const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), 0.0f, text));
const ImVec2 text_size(font.first->CalcTextSizeA(font.second, std::numeric_limits<float>::max(), 0.0f, text));
const ImVec2& padding(ImGui::GetStyle().FramePadding);
if (width < 0.0f)
width = (padding.x * 2.0f) + text_size.x;
@ -1534,7 +1540,7 @@ bool ImGuiFullscreen::FloatingButton(const char* text, float x, float y, float w
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(bb.Min, bb.Max, text, nullptr, nullptr, ImVec2(0.0f, 0.0f), &bb);
ImGui::PopFont();
@ -1545,7 +1551,7 @@ bool ImGuiFullscreen::FloatingButton(const char* text, float x, float y, float w
}
bool ImGuiFullscreen::ToggleButton(
const char* title, const char* summary, bool* v, bool enabled, float height, ImFont* font, ImFont* summary_font)
const char* title, const char* summary, bool* v, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
ImRect bb;
bool visible, hovered;
@ -1553,20 +1559,20 @@ bool ImGuiFullscreen::ToggleButton(
if (!visible)
return false;
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + font.second + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (summary)
{
ImGui::PushFont(summary_font);
ImGui::PushFont(summary_font.first, summary_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
}
@ -1616,7 +1622,7 @@ bool ImGuiFullscreen::ToggleButton(
}
bool ImGuiFullscreen::ThreeWayToggleButton(
const char* title, const char* summary, std::optional<bool>* v, bool enabled, float height, ImFont* font, ImFont* summary_font)
const char* title, const char* summary, std::optional<bool>* v, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
ImRect bb;
bool visible, hovered;
@ -1624,20 +1630,20 @@ bool ImGuiFullscreen::ThreeWayToggleButton(
if (!visible)
return false;
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + font.second + LayoutScale(4.0f);
const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), bb.Max);
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::PopFont();
if (summary)
{
ImGui::PushFont(summary_font);
ImGui::PushFont(summary_font.first, summary_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
}
@ -1693,7 +1699,7 @@ bool ImGuiFullscreen::ThreeWayToggleButton(
}
bool ImGuiFullscreen::MenuButtonWithValue(
const char* title, const char* summary, const char* value, bool enabled, float height, ImFont* font, ImFont* summary_font)
const char* title, const char* summary, const char* value, bool enabled, float height, std::pair<ImFont*, float> font, std::pair<ImFont*, float> summary_font)
{
ImRect bb;
bool visible, hovered;
@ -1703,7 +1709,7 @@ bool ImGuiFullscreen::MenuButtonWithValue(
const ImVec2 value_size(ImGui::CalcTextSize(value));
const float midpoint = bb.Min.y + font->FontSize + LayoutScale(4.0f);
const float midpoint = bb.Min.y + font.second + LayoutScale(4.0f);
const float text_end = bb.Max.x - value_size.x;
const ImRect title_bb(bb.Min, ImVec2(text_end, midpoint));
const ImRect summary_bb(ImVec2(bb.Min.x, midpoint), ImVec2(text_end, bb.Max.y));
@ -1711,14 +1717,14 @@ bool ImGuiFullscreen::MenuButtonWithValue(
if (!enabled)
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &title_bb);
ImGui::RenderTextClipped(bb.Min, bb.Max, value, nullptr, nullptr, ImVec2(1.0f, 0.5f), &bb);
ImGui::PopFont();
if (summary)
{
ImGui::PushFont(summary_font);
ImGui::PushFont(summary_font.first, summary_font.second);
ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, summary, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb);
ImGui::PopFont();
}
@ -1730,8 +1736,8 @@ bool ImGuiFullscreen::MenuButtonWithValue(
}
bool ImGuiFullscreen::EnumChoiceButtonImpl(const char* title, const char* summary, s32* value_pointer,
const char* (*to_display_name_function)(s32 value, void* opaque), void* opaque, u32 count, bool enabled, float height, ImFont* font,
ImFont* summary_font)
const char* (*to_display_name_function)(s32 value, void* opaque), void* opaque, u32 count, bool enabled, float height, std::pair<ImFont*, float> font,
std::pair<ImFont*, float> summary_font)
{
const bool pressed =
MenuButtonWithValue(title, summary, to_display_name_function(*value_pointer, opaque), enabled, height, font, summary_font);
@ -1787,7 +1793,7 @@ void ImGuiFullscreen::EndNavBar()
ImGui::PopStyleVar(4);
}
void ImGuiFullscreen::NavTitle(const char* title, float height /*= LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY*/, ImFont* font /*= g_large_font*/)
void ImGuiFullscreen::NavTitle(const char* title, float height /*= LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY*/, std::pair<ImFont*, float> font /*= g_large_font*/)
{
ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems)
@ -1795,7 +1801,7 @@ void ImGuiFullscreen::NavTitle(const char* title, float height /*= LAYOUT_MENU_B
s_menu_button_index++;
const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), 0.0f, title));
const ImVec2 text_size(font.first->CalcTextSizeA(font.second, std::numeric_limits<float>::max(), 0.0f, title));
const ImVec2 pos(window->DC.CursorPos);
const ImGuiStyle& style = ImGui::GetStyle();
const ImVec2 size = ImVec2(text_size.x, LayoutScale(height) + style.FramePadding.y * 2.0f);
@ -1810,7 +1816,7 @@ void ImGuiFullscreen::NavTitle(const char* title, float height /*= LAYOUT_MENU_B
bb.Min.y += style.FramePadding.y;
bb.Max.y -= style.FramePadding.y;
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(bb.Min, bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &bb);
ImGui::PopFont();
}
@ -1827,7 +1833,7 @@ void ImGuiFullscreen::RightAlignNavButtons(u32 num_items /*= 0*/, float item_wid
}
bool ImGuiFullscreen::NavButton(const char* title, bool is_active, bool enabled /* = true */, float width /* = -1.0f */,
float height /* = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY */, ImFont* font /* = g_large_font */)
float height /* = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY */, std::pair<ImFont*, float> font /* = g_large_font */)
{
ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems)
@ -1835,7 +1841,7 @@ bool ImGuiFullscreen::NavButton(const char* title, bool is_active, bool enabled
s_menu_button_index++;
const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), 0.0f, title));
const ImVec2 text_size(font.first->CalcTextSizeA(font.second, std::numeric_limits<float>::max(), 0.0f, title));
const ImVec2 pos(window->DC.CursorPos);
const ImGuiStyle& style = ImGui::GetStyle();
const ImVec2 size = ImVec2(((width < 0.0f) ? text_size.x : LayoutScale(width)) + style.FramePadding.x * 2.0f,
@ -1884,7 +1890,7 @@ bool ImGuiFullscreen::NavButton(const char* title, bool is_active, bool enabled
ImGui::PushStyleColor(
ImGuiCol_Text, ImGui::GetColorU32(enabled ? (is_active ? ImGuiCol_Text : ImGuiCol_TextDisabled) : ImGuiCol_ButtonHovered));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(bb.Min, bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &bb);
ImGui::PopFont();
@ -1895,7 +1901,7 @@ bool ImGuiFullscreen::NavButton(const char* title, bool is_active, bool enabled
bool ImGuiFullscreen::NavTab(const char* title, bool is_active, bool enabled /* = true */, float width, float height,
const ImVec4& background, ImFont* font /* = g_large_font */)
const ImVec4& background, std::pair<ImFont*, float> font /* = g_large_font */)
{
ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems)
@ -1903,7 +1909,7 @@ bool ImGuiFullscreen::NavTab(const char* title, bool is_active, bool enabled /*
s_menu_button_index++;
const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), 0.0f, title));
const ImVec2 text_size(font.first->CalcTextSizeA(font.second, std::numeric_limits<float>::max(), 0.0f, title));
const ImVec2 pos(window->DC.CursorPos);
const ImVec2 size = ImVec2(((width < 0.0f) ? text_size.x : LayoutScale(width)), LayoutScale(height));
@ -1966,7 +1972,7 @@ bool ImGuiFullscreen::NavTab(const char* title, bool is_active, bool enabled /*
ImGuiCol_Text,
ImGui::GetColorU32(enabled ? (is_active ? ImGuiCol_Text : ImGuiCol_TextDisabled) : ImGuiCol_ButtonHovered));
ImGui::PushFont(font);
ImGui::PushFont(font.first, font.second);
ImGui::RenderTextClipped(bb.Min, bb.Max, title, nullptr, nullptr, ImVec2(0.0f, 0.0f), &bb);
ImGui::PopFont();
@ -2046,21 +2052,21 @@ bool ImGuiFullscreen::HorizontalMenuItem(GSTexture* icon, const ImVec2& icon_uv0
ImDrawList* dl = ImGui::GetWindowDrawList();
dl->AddImage(reinterpret_cast<ImTextureID>(icon->GetNativeHandle()), icon_pos, icon_pos + ImVec2(icon_size, icon_size), icon_uv0, icon_uv1);
ImFont* title_font = g_large_font;
const ImVec2 title_size = title_font->CalcTextSizeA(title_font->FontSize, avail_width, 0.0f, title);
const std::pair<ImFont*, float> title_font = g_large_font;
const ImVec2 title_size = title_font.first->CalcTextSizeA(title_font.second, avail_width, 0.0f, title);
const ImVec2 title_pos =
ImVec2(bb.Min.x + (avail_width - title_size.x) * 0.5f, icon_pos.y + icon_size + LayoutScale(10.0f));
const ImVec4 title_bb = ImVec4(title_pos.x, title_pos.y, title_pos.x + title_size.x, title_pos.y + title_size.y);
dl->AddText(title_font, title_font->FontSize, title_pos, ImGui::GetColorU32(ImGuiCol_Text), title, nullptr, 0.0f,
dl->AddText(title_font.first, title_font.second, title_pos, ImGui::GetColorU32(ImGuiCol_Text), title, nullptr, 0.0f,
&title_bb);
ImFont* desc_font = g_medium_font;
const ImVec2 desc_size = desc_font->CalcTextSizeA(desc_font->FontSize, avail_width, avail_width, description);
const std::pair<ImFont*, float> desc_font = g_medium_font;
const ImVec2 desc_size = desc_font.first->CalcTextSizeA(desc_font.second, avail_width, avail_width, description);
const ImVec2 desc_pos = ImVec2(bb.Min.x + (avail_width - desc_size.x) * 0.5f, title_bb.w + LayoutScale(10.0f));
const ImVec4 desc_bb = ImVec4(desc_pos.x, desc_pos.y, desc_pos.x + desc_size.x, desc_pos.y + desc_size.y);
dl->AddText(desc_font, desc_font->FontSize, desc_pos, ImGui::GetColorU32(ImGuiCol_Text), description, nullptr,
dl->AddText(desc_font.first, desc_font.second, desc_pos, ImGui::GetColorU32(ImGuiCol_Text), description, nullptr,
avail_width, &desc_bb);
ImGui::SameLine();
@ -2219,7 +2225,7 @@ void ImGuiFullscreen::DrawFileSelector()
FileSelectorItem* selected = nullptr;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2345,7 +2351,7 @@ void ImGuiFullscreen::DrawChoiceDialog()
if (!s_choice_dialog_open)
return;
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2354,7 +2360,7 @@ void ImGuiFullscreen::DrawChoiceDialog()
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIPrimaryColor);
const float width = LayoutScale(600.0f);
const float title_height = g_large_font->FontSize + ImGui::GetStyle().FramePadding.y * 2.0f + ImGui::GetStyle().WindowPadding.y * 2.0f;
const float title_height = g_large_font.second + ImGui::GetStyle().FramePadding.y * 2.0f + ImGui::GetStyle().WindowPadding.y * 2.0f;
const float height = std::min(LayoutScale(480.0f), title_height + (LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) +
LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) *
static_cast<float>(s_choice_dialog_options.size()));
@ -2469,7 +2475,7 @@ void ImGuiFullscreen::DrawInputDialog()
ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::OpenPopup(s_input_dialog_title.c_str());
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
@ -2620,7 +2626,7 @@ void ImGuiFullscreen::DrawMessageDialog()
ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGui::OpenPopup(win_id);
ImGui::PushFont(g_large_font);
ImGui::PushFont(g_large_font.first, g_large_font.second);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING));
@ -2789,7 +2795,7 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac
ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, LayoutScale(1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(10.0f, 10.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, LayoutScale(10.0f, 10.0f));
ImGui::PushFont(g_medium_font);
ImGui::PushFont(g_medium_font.first, g_medium_font.second);
ImDrawList* dl = ImGui::GetForegroundDrawList();
@ -2802,8 +2808,8 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac
IM_COL32(0x11, 0x11, 0x11, 200), LayoutScale(10.0f));
ImVec2 pos(window_pos_x + LayoutScale(10.0f), window_pos_y + LayoutScale(10.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, pos, IM_COL32(255, 255, 255, 255), data.message.c_str(), nullptr, 0.0f);
pos.y += g_medium_font->FontSize + LayoutScale(10.0f);
dl->AddText(g_medium_font.first, g_medium_font.second, pos, IM_COL32(255, 255, 255, 255), data.message.c_str(), nullptr, 0.0f);
pos.y += g_medium_font.second + LayoutScale(10.0f);
const ImVec2 box_end(pos.x + window_width - LayoutScale(10.0f * 2.0f), pos.y + LayoutScale(25.0f));
dl->AddRectFilled(pos, box_end, ImGui::GetColorU32(UIPrimaryDarkColor));
@ -2817,7 +2823,7 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac
const ImVec2 text_size(ImGui::CalcTextSize(text.c_str()));
const ImVec2 text_pos(
pos.x + ((box_end.x - pos.x) / 2.0f) - (text_size.x / 2.0f), pos.y + ((box_end.y - pos.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(g_medium_font, g_medium_font->FontSize, text_pos, ImGui::GetColorU32(UIPrimaryTextColor), text.c_str());
dl->AddText(g_medium_font.first, g_medium_font.second, text_pos, ImGui::GetColorU32(UIPrimaryTextColor), text.c_str());
}
else
{
@ -2905,8 +2911,8 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing)
const float shadow_size = ImGuiFullscreen::LayoutScale(4.0f);
const float rounding = ImGuiFullscreen::LayoutScale(4.0f);
ImFont* const title_font = ImGuiFullscreen::g_large_font;
ImFont* const text_font = ImGuiFullscreen::g_medium_font;
const std::pair<ImFont*, float> title_font = ImGuiFullscreen::g_large_font;
const std::pair<ImFont*, float> text_font = ImGuiFullscreen::g_medium_font;
const u32 toast_background_color = IM_COL32(0x21, 0x21, 0x21, 255);
const u32 toast_border_color = IM_COL32(0x48, 0x48, 0x48, 255);
@ -2923,10 +2929,10 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing)
continue;
}
const ImVec2 title_size(title_font->CalcTextSizeA(title_font->FontSize, max_text_width, max_text_width,
const ImVec2 title_size(title_font.first->CalcTextSizeA(title_font.second, max_text_width, max_text_width,
notif.title.c_str(), notif.title.c_str() + notif.title.size()));
const ImVec2 text_size(text_font->CalcTextSizeA(text_font->FontSize, max_text_width, max_text_width,
const ImVec2 text_size(text_font.first->CalcTextSizeA(text_font.second, max_text_width, max_text_width,
notif.text.c_str(), notif.text.c_str() + notif.text.size()));
const float box_width = std::max((horizontal_padding * 2.0f) + badge_size + horizontal_spacing +
@ -3003,13 +3009,13 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing)
const ImVec2 title_min(badge_max.x + horizontal_spacing, box_min.y + vertical_padding);
const ImVec2 title_max(title_min.x + title_size.x, title_min.y + title_size.y);
const u32 title_col = (toast_title_color & ~IM_COL32_A_MASK) | (opacity << IM_COL32_A_SHIFT);
dl->AddText(title_font, title_font->FontSize, title_min, title_col, notif.title.c_str(),
dl->AddText(title_font.first, title_font.second, title_min, title_col, notif.title.c_str(),
notif.title.c_str() + notif.title.size(), max_text_width);
const ImVec2 text_min(badge_max.x + horizontal_spacing, title_max.y + vertical_spacing);
const ImVec2 text_max(text_min.x + text_size.x, text_min.y + text_size.y);
const u32 text_col = (toast_text_color & ~IM_COL32_A_MASK) | (opacity << IM_COL32_A_SHIFT);
dl->AddText(text_font, text_font->FontSize, text_min, text_col, notif.text.c_str(),
dl->AddText(text_font.first, text_font.second, text_min, text_col, notif.text.c_str(),
notif.text.c_str() + notif.text.size(), max_text_width);
position.y += s_notification_vertical_direction * (box_height + shadow_size + spacing);
@ -3050,18 +3056,18 @@ void ImGuiFullscreen::DrawToast()
const float max_width = LayoutScale(600.0f);
ImFont* title_font = g_large_font;
ImFont* message_font = g_medium_font;
const std::pair<ImFont*, float> title_font = g_large_font;
const std::pair<ImFont*, float> message_font = g_medium_font;
const float padding = LayoutScale(20.0f);
const float total_padding = padding * 2.0f;
const float margin = LayoutScale(20.0f + (s_fullscreen_footer_text.empty() ? 0.0f : LAYOUT_FOOTER_HEIGHT));
const float spacing = s_toast_title.empty() ? 0.0f : LayoutScale(10.0f);
const ImVec2 display_size(ImGui::GetIO().DisplaySize);
const ImVec2 title_size(s_toast_title.empty() ? ImVec2(0.0f, 0.0f) :
title_font->CalcTextSizeA(title_font->FontSize, FLT_MAX, max_width,
title_font.first->CalcTextSizeA(title_font.second, FLT_MAX, max_width,
s_toast_title.c_str(), s_toast_title.c_str() + s_toast_title.length()));
const ImVec2 message_size(s_toast_message.empty() ? ImVec2(0.0f, 0.0f) :
message_font->CalcTextSizeA(message_font->FontSize, FLT_MAX, max_width,
message_font.first->CalcTextSizeA(message_font.second, FLT_MAX, max_width,
s_toast_message.c_str(), s_toast_message.c_str() + s_toast_message.length()));
const ImVec2 comb_size(std::max(title_size.x, message_size.x), title_size.y + spacing + message_size.y);
@ -3073,14 +3079,14 @@ void ImGuiFullscreen::DrawToast()
if (!s_toast_title.empty())
{
const float offset = (comb_size.x - title_size.x) * 0.5f;
dl->AddText(title_font, title_font->FontSize, box_pos + ImVec2(offset + padding, padding),
dl->AddText(title_font.first, title_font.second, box_pos + ImVec2(offset + padding, padding),
ImGui::GetColorU32(ModAlpha(UIPrimaryTextColor, alpha)), s_toast_title.c_str(), s_toast_title.c_str() + s_toast_title.length(),
max_width);
}
if (!s_toast_message.empty())
{
const float offset = (comb_size.x - message_size.x) * 0.5f;
dl->AddText(message_font, message_font->FontSize, box_pos + ImVec2(offset + padding, padding + spacing + title_size.y),
dl->AddText(message_font.first, message_font.second, box_pos + ImVec2(offset + padding, padding + spacing + title_size.y),
ImGui::GetColorU32(ModAlpha(UIPrimaryTextColor, alpha)), s_toast_message.c_str(),
s_toast_message.c_str() + s_toast_message.length(), max_width);
}

View File

@ -42,9 +42,9 @@ namespace ImGuiFullscreen
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;
extern std::pair<ImFont*, float> g_standard_font;
extern std::pair<ImFont*, float> g_medium_font;
extern std::pair<ImFont*, float> g_large_font;
extern float g_layout_scale;
extern float g_rcp_layout_scale;
@ -93,8 +93,9 @@ namespace ImGuiFullscreen
bool Initialize(const char* placeholder_image_path);
void SetTheme(std::string_view theme);
void SetFonts(ImFont* standard_font, ImFont* medium_font, ImFont* large_font);
void SetFont(ImFont* standard_font);
bool UpdateLayoutScale();
void UpdateFontScale();
/// Shuts down, optionally clearing all state (including notifications).
void Shutdown(bool clear_state);
@ -178,33 +179,33 @@ namespace ImGuiFullscreen
void MenuHeading(const char* title, bool draw_line = true);
bool MenuHeadingButton(const char* title, const char* value = nullptr, bool enabled = true, bool draw_line = true);
bool ActiveButton(const char* title, bool is_active, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY,
ImFont* font = g_large_font);
std::pair<ImFont*, float> font = g_large_font);
bool ActiveButtonWithRightText(const char* title, const char* right_title, bool is_active, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font);
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, std::pair<ImFont*, float> font = g_large_font);
bool MenuButton(const char* title, const char* summary, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
bool MenuButtonWithoutSummary(const char* title, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY,
ImFont* font = g_large_font, const ImVec2& text_align = ImVec2(0.0f, 0.0f));
std::pair<ImFont*, float> font = g_large_font, const ImVec2& text_align = ImVec2(0.0f, 0.0f));
bool MenuButtonWithValue(const char* title, const char* summary, const char* value, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
float height = LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
bool MenuImageButton(const char* title, const char* summary, ImTextureID user_texture_id, const ImVec2& image_size, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT, const ImVec2& uv0 = ImVec2(0.0f, 0.0f), const ImVec2& uv1 = ImVec2(1.0f, 1.0f),
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
bool FloatingButton(const char* text, float x, float y, float width = -1.0f, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY,
float anchor_x = 0.0f, float anchor_y = 0.0f, bool enabled = true, ImFont* font = g_large_font, ImVec2* out_position = nullptr,
float anchor_x = 0.0f, float anchor_y = 0.0f, bool enabled = true, std::pair<ImFont*, float> font = g_large_font, ImVec2* out_position = nullptr,
bool repeat_button = false);
bool ToggleButton(const char* title, const char* summary, bool* v, bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT,
ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
bool ThreeWayToggleButton(const char* title, const char* summary, std::optional<bool>* v, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font);
float height = LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font);
bool EnumChoiceButtonImpl(const char* title, const char* summary, s32* value_pointer,
const char* (*to_display_name_function)(s32 value, void* opaque), void* opaque, u32 count, bool enabled, float height, ImFont* font,
ImFont* summary_font);
const char* (*to_display_name_function)(s32 value, void* opaque), void* opaque, u32 count, bool enabled, float height, std::pair<ImFont*, float> font,
std::pair<ImFont*, float> summary_font);
template <typename DataType, typename CountType>
static __fi bool EnumChoiceButton(const char* title, const char* summary, DataType* value_pointer,
const char* (*to_display_name_function)(DataType value), CountType count, bool enabled = true,
float height = LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = g_large_font, ImFont* summary_font = g_medium_font)
float height = LAYOUT_MENU_BUTTON_HEIGHT, std::pair<ImFont*, float> font = g_large_font, std::pair<ImFont*, float> summary_font = g_medium_font)
{
s32 value = static_cast<s32>(*value_pointer);
auto to_display_name_wrapper = [](s32 value, void* opaque) -> const char* {
@ -225,13 +226,13 @@ namespace ImGuiFullscreen
void BeginNavBar(float x_padding = LAYOUT_MENU_BUTTON_X_PADDING, float y_padding = LAYOUT_MENU_BUTTON_Y_PADDING);
void EndNavBar();
void NavTitle(const char* title, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font);
void NavTitle(const char* title, float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, std::pair<ImFont*, float> font = g_large_font);
void RightAlignNavButtons(u32 num_items = 0, float item_width = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY,
float item_height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
bool NavButton(const char* title, bool is_active, bool enabled = true, float width = -1.0f,
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font);
float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, std::pair<ImFont*, float> font = g_large_font);
bool NavTab(const char* title, bool is_active, bool enabled, float width, float height, const ImVec4& background,
ImFont* font = g_large_font);
std::pair<ImFont*, float> font = g_large_font);
bool BeginHorizontalMenu(const char* name, const ImVec2& position, const ImVec2& size, u32 num_items);
void EndHorizontalMenu();

View File

@ -52,10 +52,10 @@ namespace ImGuiManager
static void SetKeyMap();
static bool LoadFontData();
static void UnloadFontData();
static bool AddImGuiFonts(bool fullscreen_fonts);
static ImFont* AddTextFont(float size);
static ImFont* AddFixedFont(float size);
static bool AddIconFonts(float size);
static bool AddImGuiFonts();
static ImFont* AddTextFont();
static ImFont* AddFixedFont();
static bool AddIconFonts();
static void AcquirePendingOSDMessages(Common::Timer::Value current_time);
static void DrawOSDMessages(Common::Timer::Value current_time);
static void CreateSoftwareCursorTextures();
@ -72,8 +72,6 @@ static std::vector<ImWchar> s_font_range;
static ImFont* s_standard_font;
static ImFont* s_fixed_font;
static ImFont* s_medium_font;
static ImFont* s_large_font;
static std::vector<u8> s_standard_font_data;
static std::vector<u8> s_fixed_font_data;
@ -119,7 +117,7 @@ void ImGuiManager::SetFontPathAndRange(std::string path, std::vector<u16> range)
if (!LoadFontData())
pxFailRel("Failed to load font data");
if (!AddImGuiFonts(HasFullscreenFonts()))
if (!AddImGuiFonts())
pxFailRel("Failed to create ImGui font text");
NewFrame();
@ -156,9 +154,12 @@ bool ImGuiManager::Initialize()
const bool add_fullscreen_fonts = s_fullscreen_ui_was_initialized;
pxAssertRel(!FullscreenUI::IsInitialized(), "Fullscreen UI is not initialized on ImGui init");
if (add_fullscreen_fonts)
{
ImGuiFullscreen::UpdateLayoutScale();
ImGuiFullscreen::UpdateFontScale();
}
if (!AddImGuiFonts(add_fullscreen_fonts))
if (!AddImGuiFonts())
{
Host::ReportErrorAsync("ImGuiManager", "Failed to create ImGui font text");
ImGui::DestroyContext();
@ -187,7 +188,7 @@ void ImGuiManager::Shutdown(bool clear_state)
DestroySoftwareCursorTextures();
FullscreenUI::Shutdown(clear_state);
ImGuiFullscreen::SetFonts(nullptr, nullptr, nullptr);
ImGuiFullscreen::SetFont(nullptr);
SaveStateSelectorUI::DestroyTextures();
if (clear_state)
s_fullscreen_ui_was_initialized = false;
@ -199,8 +200,6 @@ void ImGuiManager::Shutdown(bool clear_state)
s_standard_font = nullptr;
s_fixed_font = nullptr;
s_medium_font = nullptr;
s_large_font = nullptr;
if (clear_state)
UnloadFontData();
@ -240,14 +239,13 @@ void ImGuiManager::UpdateScale()
const float window_scale = g_gs_device ? g_gs_device->GetWindowScale() : 1.0f;
const float scale = std::max(window_scale * (EmuConfig.GS.OsdScale / 100.0f), 0.5f);
if ((!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale()) && scale == s_global_scale)
if ((!ImGuiFullscreen::UpdateLayoutScale()) && scale == s_global_scale)
return;
s_global_scale = scale;
SetStyle();
if (!AddImGuiFonts(HasFullscreenFonts()))
pxFailRel("Failed to create ImGui font text");
ImGuiFullscreen::UpdateFontScale();
if (FullscreenUI::IsInitialized())
FullscreenUI::ReloadSvgResources();
@ -446,7 +444,10 @@ void ImGuiManager::UnloadFontData()
std::vector<u8>().swap(s_icon_pf_font_data);
}
ImFont* ImGuiManager::AddTextFont(float size)
// A resonable default font size is recommended
#define FONT_BASE_SIZE 15.0f
ImFont* ImGuiManager::AddTextFont()
{
static const ImWchar default_ranges[] = {
// Basic Latin + Latin Supplement + Central European diacritics
@ -471,19 +472,19 @@ ImFont* ImGuiManager::AddTextFont(float size)
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
s_standard_font_data.data(), static_cast<int>(s_standard_font_data.size()), size, &cfg,
s_standard_font_data.data(), static_cast<int>(s_standard_font_data.size()), FONT_BASE_SIZE, &cfg,
s_font_range.empty() ? default_ranges : s_font_range.data());
}
ImFont* ImGuiManager::AddFixedFont(float size)
ImFont* ImGuiManager::AddFixedFont()
{
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
return ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
s_fixed_font_data.data(), static_cast<int>(s_fixed_font_data.size()), size, &cfg, nullptr);
s_fixed_font_data.data(), static_cast<int>(s_fixed_font_data.size()), FONT_BASE_SIZE, &cfg, nullptr);
}
bool ImGuiManager::AddIconFonts(float size)
bool ImGuiManager::AddIconFonts()
{
// clang-format off
static constexpr ImWchar range_fa[] = { 0xe06f,0xe06f,0xe097,0xe097,0xe2ca,0xe2ca,0xe494,0xe494,0xe4bb,0xe4bb,0xe4cf,0xe4cf,0xe51f,0xe51f,0xf001,0xf002,0xf005,0xf005,0xf007,0xf007,0xf009,0xf00a,0xf00c,0xf00d,0xf011,0xf011,0xf013,0xf013,0xf017,0xf017,0xf019,0xf019,0xf01e,0xf01e,0xf022,0xf023,0xf025,0xf028,0xf02b,0xf02b,0xf02e,0xf02e,0xf030,0xf030,0xf037,0xf037,0xf03a,0xf03a,0xf03d,0xf03e,0xf043,0xf043,0xf047,0xf047,0xf04b,0xf04c,0xf04e,0xf04e,0xf050,0xf050,0xf052,0xf052,0xf05a,0xf05a,0xf05e,0xf05e,0xf063,0xf063,0xf066,0xf066,0xf06a,0xf06a,0xf06e,0xf06e,0xf071,0xf071,0xf075,0xf075,0xf077,0xf078,0xf07b,0xf07c,0xf080,0xf080,0xf084,0xf084,0xf08e,0xf08e,0xf091,0xf091,0xf0a0,0xf0a0,0xf0ac,0xf0ad,0xf0b0,0xf0b0,0xf0c0,0xf0c0,0xf0c5,0xf0c5,0xf0c7,0xf0c8,0xf0cb,0xf0cb,0xf0dc,0xf0dc,0xf0e2,0xf0e2,0xf0eb,0xf0ec,0xf0f3,0xf0f3,0xf0fe,0xf0fe,0xf110,0xf110,0xf11b,0xf11c,0xf120,0xf121,0xf125,0xf125,0xf129,0xf129,0xf140,0xf140,0xf14a,0xf14a,0xf14c,0xf14c,0xf15b,0xf15b,0xf15d,0xf15d,0xf185,0xf185,0xf187,0xf188,0xf191,0xf192,0xf1b3,0xf1b3,0xf1c0,0xf1c0,0xf1da,0xf1da,0xf1de,0xf1de,0xf1e6,0xf1e6,0xf1ea,0xf1eb,0xf1f8,0xf1f8,0xf1fb,0xf1fc,0xf21e,0xf21e,0xf245,0xf245,0xf26c,0xf26c,0xf279,0xf279,0xf2a8,0xf2a8,0xf2bd,0xf2bd,0xf2d3,0xf2d3,0xf2db,0xf2db,0xf2f2,0xf2f2,0xf302,0xf303,0xf31e,0xf31e,0xf360,0xf360,0xf3a5,0xf3a5,0xf3c1,0xf3c1,0xf462,0xf462,0xf466,0xf466,0xf49e,0xf49e,0xf4e2,0xf4e2,0xf51f,0xf51f,0xf530,0xf530,0xf54c,0xf54c,0xf552,0xf553,0xf5a2,0xf5a2,0xf5a5,0xf5a5,0xf5bc,0xf5bc,0xf5c7,0xf5c7,0xf624,0xf625,0xf62a,0xf62a,0xf65d,0xf65e,0xf6a9,0xf6a9,0xf70e,0xf70e,0xf756,0xf756,0xf780,0xf780,0xf794,0xf794,0xf7d8,0xf7d8,0xf815,0xf815,0xf84c,0xf84c,0xf87c,0xf87c,0xf8cc,0xf8cc,0x0,0x0 };
@ -494,12 +495,12 @@ bool ImGuiManager::AddIconFonts(float size)
ImFontConfig cfg;
cfg.MergeMode = true;
cfg.PixelSnapH = true;
cfg.GlyphMinAdvanceX = size;
cfg.GlyphMaxAdvanceX = size;
cfg.GlyphMinAdvanceX = FONT_BASE_SIZE;
cfg.GlyphMaxAdvanceX = FONT_BASE_SIZE;
cfg.FontDataOwnedByAtlas = false;
if (!ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
s_icon_fa_font_data.data(), static_cast<int>(s_icon_fa_font_data.size()), size * 0.75f, &cfg, range_fa))
s_icon_fa_font_data.data(), static_cast<int>(s_icon_fa_font_data.size()), FONT_BASE_SIZE * 0.75f, &cfg, range_fa))
{
return false;
}
@ -509,12 +510,12 @@ bool ImGuiManager::AddIconFonts(float size)
ImFontConfig cfg;
cfg.MergeMode = true;
cfg.PixelSnapH = true;
cfg.GlyphMinAdvanceX = size;
cfg.GlyphMaxAdvanceX = size;
cfg.GlyphMinAdvanceX = FONT_BASE_SIZE;
cfg.GlyphMaxAdvanceX = FONT_BASE_SIZE;
cfg.FontDataOwnedByAtlas = false;
if (!ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
s_icon_pf_font_data.data(), static_cast<int>(s_icon_pf_font_data.size()), size * 1.2f, &cfg, range_pf))
s_icon_pf_font_data.data(), static_cast<int>(s_icon_pf_font_data.size()), FONT_BASE_SIZE * 1.2f, &cfg, range_pf))
{
return false;
}
@ -523,66 +524,21 @@ bool ImGuiManager::AddIconFonts(float size)
return true;
}
bool ImGuiManager::AddImGuiFonts(bool fullscreen_fonts)
bool ImGuiManager::AddImGuiFonts()
{
const float standard_font_size = std::ceil(15.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))
s_standard_font = AddTextFont();
if (!s_standard_font || !AddIconFonts())
return false;
s_fixed_font = AddFixedFont(standard_font_size);
s_fixed_font = AddFixedFont();
if (!s_fixed_font)
return false;
if (fullscreen_fonts)
{
const float medium_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE);
s_medium_font = AddTextFont(medium_font_size);
if (!s_medium_font || !AddIconFonts(medium_font_size))
return false;
const float large_font_size = ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE);
s_large_font = AddTextFont(large_font_size);
if (!s_large_font || !AddIconFonts(large_font_size))
return false;
}
else
{
s_medium_font = nullptr;
s_large_font = nullptr;
}
ImGuiFullscreen::SetFonts(s_standard_font, s_medium_font, s_large_font);
return io.Fonts->Build();
}
bool ImGuiManager::AddFullscreenFontsIfMissing()
{
if (HasFullscreenFonts())
return true;
// can't do this in the middle of a frame
ImGui::EndFrame();
if (!AddImGuiFonts(true))
{
Console.Error("Failed to lazily allocate fullscreen fonts.");
AddImGuiFonts(false);
}
NewFrame();
return HasFullscreenFonts();
}
bool ImGuiManager::HasFullscreenFonts()
{
return (s_medium_font && s_large_font);
ImGuiFullscreen::SetFont(s_standard_font);
return true;
}
struct OSDMessage
@ -715,7 +671,8 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time)
{
static constexpr float MOVE_DURATION = 0.5f;
ImFont* const font = ImGui::GetFont();
ImFont* const font = s_standard_font;
const float font_size = GetFontSizeStandard();
const float scale = s_global_scale;
const float spacing = std::ceil(5.0f * scale);
const float margin = std::ceil(10.0f * scale);
@ -814,7 +771,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time)
break;
const ImVec2 text_size(
font->CalcTextSizeA(font->FontSize, max_width, max_width, msg.text.c_str(), msg.text.c_str() + msg.text.length()));
font->CalcTextSizeA(font_size, max_width, max_width, msg.text.c_str(), msg.text.c_str() + msg.text.length()));
const ImVec2 size(text_size.x + padding * 2.0f, text_size.y + padding * 2.0f);
// For bottom positions, adjust actual_y to try to account for message height
@ -833,7 +790,7 @@ void ImGuiManager::DrawOSDMessages(Common::Timer::Value current_time)
ImDrawList* dl = ImGui::GetBackgroundDrawList();
dl->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x21, 0x21, 0x21, opacity), rounding);
dl->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(0x48, 0x48, 0x48, opacity), rounding);
dl->AddText(font, font->FontSize, ImVec2(text_rect.x, text_rect.y), IM_COL32(0xff, 0xff, 0xff, opacity), msg.text.c_str(),
dl->AddText(font, font_size, ImVec2(text_rect.x, text_rect.y), IM_COL32(0xff, 0xff, 0xff, opacity), msg.text.c_str(),
msg.text.c_str() + msg.text.length(), max_width, &text_rect);
// Stack direction depends on the position upward for bottom positions, downward for others
@ -882,16 +839,19 @@ ImFont* ImGuiManager::GetFixedFont()
return s_fixed_font;
}
ImFont* ImGuiManager::GetMediumFont()
float ImGuiManager::GetFontSizeStandard()
{
AddFullscreenFontsIfMissing();
return s_medium_font;
return std::ceil(15.0f * s_global_scale);
}
ImFont* ImGuiManager::GetLargeFont()
float ImGuiManager::GetFontSizeMedium()
{
AddFullscreenFontsIfMissing();
return s_large_font;
return ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE);
}
float ImGuiManager::GetFontSizeLarge()
{
return ImGuiFullscreen::LayoutScale(ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE);
}
bool ImGuiManager::WantsTextInput()

View File

@ -50,25 +50,20 @@ namespace ImGuiManager
/// Returns the scale of all on-screen elements.
float GetGlobalScale();
/// Returns true if fullscreen fonts are present.
bool HasFullscreenFonts();
/// Allocates/adds fullscreen fonts if they're not loaded.
bool AddFullscreenFontsIfMissing();
/// Returns the standard font for external drawing.
ImFont* GetStandardFont();
/// Returns the fixed-width font for external drawing.
ImFont* GetFixedFont();
/// Returns the medium font for external drawing, scaled by ImGuiFullscreen.
/// This font is allocated on demand.
ImFont* GetMediumFont();
// Returns the standard font size for external drawing.
float GetFontSizeStandard();
/// Returns the large font for external drawing, scaled by ImGuiFullscreen.
/// This font is allocated on demand.
ImFont* GetLargeFont();
// Returns the medium font size for external drawing, matching the size used by ImGuiFullscreen.
float GetFontSizeMedium();
// Returns the large font size for external drawing, matching the size used by ImGuiFullscreen.
float GetFontSizeLarge();
/// Returns true if imgui wants to intercept text input.
bool WantsTextInput();

View File

@ -167,6 +167,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
ImFont* const fixed_font = ImGuiManager::GetFixedFont();
ImFont* const standard_font = ImGuiManager::GetStandardFont();
const float font_size = ImGuiManager::GetFontSizeStandard();
ImDrawList* dl = ImGui::GetBackgroundDrawList();
SmallString text;
@ -179,14 +180,14 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
case OsdOverlayPos::Center:
case OsdOverlayPos::CenterRight:
position_y = (GetWindowHeight() - (fixed_font->FontSize * 8.0f)) * 0.5f;
position_y = (GetWindowHeight() - (font_size * 8.0f)) * 0.5f;
break;
case OsdOverlayPos::BottomLeft:
case OsdOverlayPos::BottomCenter:
case OsdOverlayPos::BottomRight:
position_y = GetWindowHeight() - margin - (fixed_font->FontSize * 15.0f + spacing * 14.0f);
position_y = GetWindowHeight() - margin - (font_size * 15.0f + spacing * 14.0f);
break;
case OsdOverlayPos::TopLeft:
@ -197,13 +198,13 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
break;
}
#define DRAW_LINE(font, text, color) \
#define DRAW_LINE(font, size, text, color) \
do \
{ \
text_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, (text), nullptr, nullptr); \
text_size = font->CalcTextSizeA(size, std::numeric_limits<float>::max(), -1.0f, (text), nullptr, nullptr); \
const ImVec2 text_pos = CalculatePerformanceOverlayTextPosition(GSConfig.OsdPerformancePos, margin, text_size, GetWindowWidth(), position_y); \
dl->AddText(font, font->FontSize, ImVec2(text_pos.x + shadow_offset, text_pos.y + shadow_offset), IM_COL32(0, 0, 0, 100), (text)); \
dl->AddText(font, font->FontSize, text_pos, color, (text)); \
dl->AddText(font, size, ImVec2(text_pos.x + shadow_offset, text_pos.y + shadow_offset), IM_COL32(0, 0, 0, 100), (text)); \
dl->AddText(font, size, text_pos, color, (text)); \
position_y += text_size.y + spacing; \
} while (0)
@ -271,19 +272,19 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
else
color = IM_COL32(255, 255, 255, 255);
DRAW_LINE(fixed_font, text.c_str(), color);
DRAW_LINE(fixed_font, font_size, text.c_str(), color);
}
if (GSConfig.OsdShowGSStats)
{
text.clear();
GSgetStats(text);
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
text.clear();
GSgetMemoryStats(text);
if (!text.empty())
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
text.clear();
text.append_format("{} QF | Min: {:.2f}ms | Avg: {:.2f}ms | Max: {:.2f}ms",
@ -291,7 +292,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
PerformanceMetrics::GetMinimumFrameTime(),
PerformanceMetrics::GetAverageFrameTime(),
PerformanceMetrics::GetMaximumFrameTime());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
if (GSConfig.OsdShowResolution)
@ -301,7 +302,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
text.clear();
text.append_format("{}x{} {} {}", width, height, ReportVideoMode(), ReportInterlaceMode());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
if (GSConfig.OsdShowHardwareInfo)
@ -312,12 +313,12 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
cpuinfo_get_package(0)->name,
cpuinfo_get_cores_count(),
cpuinfo_get_processors_count());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
// GPU
text.clear();
text.append_format("GPU: {}{}", g_gs_device->GetName(), GSConfig.UseDebugDevice ? " (Debug)" : "");
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
if (GSConfig.OsdShowCPU)
@ -328,17 +329,17 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
else
text = "EE: ";
FormatProcessorStat(text, PerformanceMetrics::GetCPUThreadUsage(), PerformanceMetrics::GetCPUThreadAverageTime());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
text = "GS: ";
FormatProcessorStat(text, PerformanceMetrics::GetGSThreadUsage(), PerformanceMetrics::GetGSThreadAverageTime());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
if (THREAD_VU1)
{
text = "VU: ";
FormatProcessorStat(text, PerformanceMetrics::GetVUThreadUsage(), PerformanceMetrics::GetVUThreadAverageTime());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
const u32 gs_sw_threads = PerformanceMetrics::GetGSSWThreadCount();
@ -347,14 +348,14 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
text.clear();
text.append_format("SW-{}: ", i);
FormatProcessorStat(text, PerformanceMetrics::GetGSSWThreadUsage(i), PerformanceMetrics::GetGSSWThreadAverageTime(i));
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
if (GSCapture::IsCapturing())
{
text = "CAP: ";
FormatProcessorStat(text, PerformanceMetrics::GetCaptureThreadUsage(), PerformanceMetrics::GetCaptureThreadAverageTime());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
}
@ -362,7 +363,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
{
text = "GPU: ";
FormatProcessorStat(text, PerformanceMetrics::GetGPUUsage(), PerformanceMetrics::GetGPUAverageTime());
DRAW_LINE(fixed_font, text.c_str(), IM_COL32(255, 255, 255, 255));
DRAW_LINE(fixed_font, font_size, text.c_str(), IM_COL32(255, 255, 255, 255));
}
if (GSConfig.OsdShowIndicators)
@ -373,11 +374,11 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
if (!is_normal_speed)
{
if (target_speed == EmuConfig.EmulationSpeed.SlomoScalar) // Slow-Motion
DRAW_LINE(standard_font, ICON_PF_SLOW_MOTION, IM_COL32(255, 255, 255, 255));
DRAW_LINE(standard_font, font_size, ICON_PF_SLOW_MOTION, IM_COL32(255, 255, 255, 255));
else if (target_speed == EmuConfig.EmulationSpeed.TurboScalar) // Turbo
DRAW_LINE(standard_font, ICON_FA_FORWARD_FAST, IM_COL32(255, 255, 255, 255));
DRAW_LINE(standard_font, font_size, ICON_FA_FORWARD_FAST, IM_COL32(255, 255, 255, 255));
else // Unlimited
DRAW_LINE(standard_font, ICON_FA_FORWARD, IM_COL32(255, 255, 255, 255));
DRAW_LINE(standard_font, font_size, ICON_FA_FORWARD, IM_COL32(255, 255, 255, 255));
}
}
@ -396,7 +397,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
ImGui::PushFont(fixed_font);
ImGui::PushFont(fixed_font, font_size);
if (ImGui::Begin("##frame_times", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs))
{
auto [min, max] = GetMinMax(PerformanceMetrics::GetFrameTimeHistory());
@ -423,7 +424,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
text.clear();
text.append_format("Max: {:.1f} ms", max);
text_size = fixed_font->CalcTextSizeA(fixed_font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.length());
text_size = fixed_font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.length());
float text_x;
switch (GSConfig.OsdPerformancePos)
@ -452,7 +453,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
text.clear();
text.append_format("Min: {:.1f} ms", min);
text_size = fixed_font->CalcTextSizeA(fixed_font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.length());
text_size = fixed_font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text.c_str(), text.c_str() + text.length());
float min_text_x;
switch (GSConfig.OsdPerformancePos)
@ -474,9 +475,9 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
min_text_x = wpos.x + history_size.x - text_size.x - spacing; // Right alignment within window
break;
}
win_dl->AddText(ImVec2(min_text_x + shadow_offset, wpos.y + history_size.y - fixed_font->FontSize + shadow_offset),
win_dl->AddText(ImVec2(min_text_x + shadow_offset, wpos.y + history_size.y - font_size + shadow_offset),
IM_COL32(0, 0, 0, 100), text.c_str(), text.c_str() + text.length());
win_dl->AddText(ImVec2(min_text_x, wpos.y + history_size.y - fixed_font->FontSize),
win_dl->AddText(ImVec2(min_text_x, wpos.y + history_size.y - font_size),
IM_COL32(255, 255, 255, 255), text.c_str(), text.c_str() + text.length());
}
ImGui::End();
@ -491,10 +492,10 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f
{
// We should put the Pause icon in the top right regardless of performance overlay position
text = ICON_FA_PAUSE;
text_size = standard_font->CalcTextSizeA(standard_font->FontSize, std::numeric_limits<float>::max(), -1.0f, text.c_str(), nullptr, nullptr);
text_size = standard_font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(), -1.0f, text.c_str(), nullptr, nullptr);
const ImVec2 pause_pos(GetWindowWidth() - margin - text_size.x, margin);
dl->AddText(standard_font, standard_font->FontSize, ImVec2(pause_pos.x + shadow_offset, pause_pos.y + shadow_offset), IM_COL32(0, 0, 0, 100), text.c_str());
dl->AddText(standard_font, standard_font->FontSize, pause_pos, IM_COL32(255, 255, 255, 255), text.c_str());
dl->AddText(standard_font, font_size, ImVec2(pause_pos.x + shadow_offset, pause_pos.y + shadow_offset), IM_COL32(0, 0, 0, 100), text.c_str());
dl->AddText(standard_font, font_size, pause_pos, IM_COL32(255, 255, 255, 255), text.c_str());
}
}
@ -625,16 +626,17 @@ __ri void ImGuiManager::DrawSettingsOverlay(float scale, float margin, float spa
text.pop_back();
const float shadow_offset = std::ceil(scale);
ImFont* font = ImGuiManager::GetFixedFont();
const float position_y = GetWindowHeight() - margin - font->FontSize;
ImFont* const font = ImGuiManager::GetFixedFont();
const float font_size = ImGuiManager::GetFontSizeStandard();
const float position_y = GetWindowHeight() - margin - font_size;
ImDrawList* dl = ImGui::GetBackgroundDrawList();
ImVec2 text_size =
font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, text.c_str(), text.c_str() + text.length(), nullptr);
dl->AddText(font, font->FontSize,
font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(), -1.0f, text.c_str(), text.c_str() + text.length(), nullptr);
dl->AddText(font, font_size,
ImVec2(GetWindowWidth() - margin - text_size.x + shadow_offset, position_y + shadow_offset), IM_COL32(0, 0, 0, 100),
text.c_str(), text.c_str() + text.length());
dl->AddText(font, font->FontSize, ImVec2(GetWindowWidth() - margin - text_size.x, position_y), IM_COL32(255, 255, 255, 255),
dl->AddText(font, font_size, ImVec2(GetWindowWidth() - margin - text_size.x, position_y), IM_COL32(255, 255, 255, 255),
text.c_str(), text.c_str() + text.length());
}
@ -646,7 +648,8 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
return;
const float shadow_offset = std::ceil(scale);
ImFont* font = ImGuiManager::GetStandardFont();
ImFont* const font = ImGuiManager::GetStandardFont();
const float font_size = ImGuiManager::GetFontSizeStandard();
static constexpr u32 text_color = IM_COL32(0xff, 0xff, 0xff, 255);
static constexpr u32 shadow_color = IM_COL32(0x00, 0x00, 0x00, 100);
@ -669,7 +672,7 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
}
float current_x = ImFloor(margin);
float current_y = ImFloor(display_size.y - margin - ((static_cast<float>(num_ports) * (font->FontSize + spacing)) - spacing));
float current_y = ImFloor(display_size.y - margin - ((static_cast<float>(num_ports) * (font_size + spacing)) - spacing));
const ImVec4 clip_rect(current_x, current_y, display_size.x - margin, display_size.y);
SmallString text;
@ -724,12 +727,12 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
}
}
dl->AddText(font, font->FontSize, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color, text.c_str(),
dl->AddText(font, font_size, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color, text.c_str(),
text.c_str() + text.length(), 0.0f, &clip_rect);
dl->AddText(
font, font->FontSize, ImVec2(current_x, current_y), text_color, text.c_str(), text.c_str() + text.length(), 0.0f, &clip_rect);
font, font_size, ImVec2(current_x, current_y), text_color, text.c_str(), text.c_str() + text.length(), 0.0f, &clip_rect);
current_y += font->FontSize + spacing;
current_y += font_size + spacing;
}
for (u32 port = 0; port < USB::NUM_PORTS; port++)
@ -778,12 +781,12 @@ __ri void ImGuiManager::DrawInputsOverlay(float scale, float margin, float spaci
}
}
dl->AddText(font, font->FontSize, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color, text.c_str(),
dl->AddText(font, font_size, ImVec2(current_x + shadow_offset, current_y + shadow_offset), shadow_color, text.c_str(),
text.c_str() + text.length(), 0.0f, &clip_rect);
dl->AddText(
font, font->FontSize, ImVec2(current_x, current_y), text_color, text.c_str(), text.c_str() + text.length(), 0.0f, &clip_rect);
font, font_size, ImVec2(current_x, current_y), text_color, text.c_str(), text.c_str() + text.length(), 0.0f, &clip_rect);
current_y += font->FontSize + spacing;
current_y += font_size + spacing;
}
}
@ -798,37 +801,38 @@ __ri void ImGuiManager::DrawInputRecordingOverlay(float& position_y, float scale
ImFont* const fixed_font = ImGuiManager::GetFixedFont();
ImFont* const standard_font = ImGuiManager::GetStandardFont();
const float font_size = ImGuiManager::GetFontSizeStandard();
ImDrawList* dl = ImGui::GetBackgroundDrawList();
std::string text;
ImVec2 text_size;
text.reserve(128);
#define DRAW_LINE(font, text, color) \
#define DRAW_LINE(font, size, text, color) \
do \
{ \
text_size = font->CalcTextSizeA(font->FontSize, std::numeric_limits<float>::max(), -1.0f, (text), nullptr, nullptr); \
dl->AddText(font, font->FontSize, \
text_size = font->CalcTextSizeA(size, std::numeric_limits<float>::max(), -1.0f, (text), nullptr, nullptr); \
dl->AddText(font, size, \
ImVec2(GetWindowWidth() - margin - text_size.x + shadow_offset, position_y + shadow_offset), \
IM_COL32(0, 0, 0, 100), (text)); \
dl->AddText(font, font->FontSize, ImVec2(GetWindowWidth() - margin - text_size.x, position_y), color, (text)); \
dl->AddText(font, size, ImVec2(GetWindowWidth() - margin - text_size.x, position_y), color, (text)); \
position_y += text_size.y + spacing; \
} while (0)
// Status Indicators
if (g_InputRecordingData.is_recording)
{
DRAW_LINE(standard_font, TinyString::from_format(TRANSLATE_FS("ImGuiOverlays", "{} Recording Input"), ICON_PF_CIRCLE).c_str(), IM_COL32(255, 0, 0, 255));
DRAW_LINE(standard_font, font_size, TinyString::from_format(TRANSLATE_FS("ImGuiOverlays", "{} Recording Input"), ICON_PF_CIRCLE).c_str(), IM_COL32(255, 0, 0, 255));
}
else
{
DRAW_LINE(standard_font, TinyString::from_format(TRANSLATE_FS("ImGuiOverlays", "{} Replaying"), ICON_FA_PLAY).c_str(), IM_COL32(97, 240, 84, 255));
DRAW_LINE(standard_font, font_size, TinyString::from_format(TRANSLATE_FS("ImGuiOverlays", "{} Replaying"), ICON_FA_PLAY).c_str(), IM_COL32(97, 240, 84, 255));
}
// Input Recording Metadata
DRAW_LINE(fixed_font, g_InputRecordingData.recording_active_message.c_str(), IM_COL32(117, 255, 241, 255));
DRAW_LINE(fixed_font, g_InputRecordingData.frame_data_message.c_str(), IM_COL32(117, 255, 241, 255));
DRAW_LINE(fixed_font, g_InputRecordingData.undo_count_message.c_str(), IM_COL32(117, 255, 241, 255));
DRAW_LINE(fixed_font, font_size, g_InputRecordingData.recording_active_message.c_str(), IM_COL32(117, 255, 241, 255));
DRAW_LINE(fixed_font, font_size, g_InputRecordingData.frame_data_message.c_str(), IM_COL32(117, 255, 241, 255));
DRAW_LINE(fixed_font, font_size, g_InputRecordingData.undo_count_message.c_str(), IM_COL32(117, 255, 241, 255));
#undef DRAW_LINE
}
@ -842,27 +846,28 @@ __ri void ImGuiManager::DrawVideoCaptureOverlay(float& position_y, float scale,
const float shadow_offset = std::ceil(scale);
ImFont* const standard_font = ImGuiManager::GetStandardFont();
float font_size = ImGuiManager::GetFontSizeStandard();
ImDrawList* dl = ImGui::GetBackgroundDrawList();
static constexpr const char* ICON = ICON_PF_CIRCLE;
const TinyString text_msg = TinyString::from_format(" {}", GSCapture::GetElapsedTime());
const ImVec2 icon_size = standard_font->CalcTextSizeA(standard_font->FontSize, std::numeric_limits<float>::max(),
const ImVec2 icon_size = standard_font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(),
-1.0f, ICON, nullptr, nullptr);
const ImVec2 text_size = standard_font->CalcTextSizeA(standard_font->FontSize, std::numeric_limits<float>::max(),
const ImVec2 text_size = standard_font->CalcTextSizeA(font_size, std::numeric_limits<float>::max(),
-1.0f, text_msg.c_str(), text_msg.end_ptr(), nullptr);
// Shadow
dl->AddText(standard_font, standard_font->FontSize,
dl->AddText(standard_font, font_size,
ImVec2(GetWindowWidth() - margin - text_size.x - icon_size.x + shadow_offset, position_y + shadow_offset),
IM_COL32(0, 0, 0, 100), ICON);
dl->AddText(standard_font, standard_font->FontSize,
dl->AddText(standard_font, font_size,
ImVec2(GetWindowWidth() - margin - text_size.x + shadow_offset, position_y + shadow_offset),
IM_COL32(0, 0, 0, 100), text_msg.c_str(), text_msg.end_ptr());
// Text
dl->AddText(standard_font, standard_font->FontSize,
dl->AddText(standard_font, font_size,
ImVec2(GetWindowWidth() - margin - text_size.x - icon_size.x, position_y), IM_COL32(255, 0, 0, 255), ICON);
dl->AddText(standard_font, standard_font->FontSize,
dl->AddText(standard_font, font_size,
ImVec2(GetWindowWidth() - margin - text_size.x, position_y), IM_COL32(255, 255, 255, 255), text_msg.c_str(),
text_msg.end_ptr());
@ -1183,7 +1188,7 @@ void SaveStateSelectorUI::Draw()
ImGui::TextUnformatted(entry.title.c_str(), entry.title.c_str() + entry.title.length());
ImGui::TextUnformatted(entry.summary.c_str(), entry.summary.c_str() + entry.summary.length());
ImGui::PushFont(ImGuiManager::GetFixedFont());
ImGui::PushFont(ImGuiManager::GetFixedFont(), ImGuiManager::GetFontSizeStandard());
ImGui::TextUnformatted(entry.filename.c_str(), entry.filename.c_str() + entry.filename.length());
ImGui::PopFont();