diff --git a/src/core/achievements.cpp b/src/core/achievements.cpp index 9df8d7c82..7da0e4b6c 100644 --- a/src/core/achievements.cpp +++ b/src/core/achievements.cpp @@ -2153,8 +2153,8 @@ static float IndicatorOpacity(const T& i) void Achievements::DrawGameOverlays() { - using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LayoutScale; + using ImGuiFullscreen::UIStyle; if (!HasActiveGame() || !g_settings.achievements_overlays) return; @@ -2210,7 +2210,8 @@ void Achievements::DrawGameOverlays() const char* text_start = s_state.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 = + UIStyle.MediumFont->CalcTextSizeA(UIStyle.MediumFont->FontSize, FLT_MAX, 0.0f, text_start, text_end); const ImVec2 box_min = ImVec2(position.x - image_size.x - text_size.x - spacing - padding * 2.0f, position.y - image_size.y - padding * 2.0f); @@ -2230,7 +2231,8 @@ 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(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, text_pos, col, text_start, text_end, 0.0f, + &text_clip_rect); if (!indicator.active && opacity <= 0.01f) { @@ -2252,8 +2254,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 = ImGuiFullscreen::UIStyle.MediumFont->CalcTextSizeA( + ImGuiFullscreen::UIStyle.MediumFont->FontSize, FLT_MAX, 0.0f, width_string.c_str(), width_string.end_ptr()); const ImVec2 box_min = ImVec2(position.x - size.x - padding * 2.0f, position.y - size.y - padding * 2.0f); const ImVec2 box_max = position; @@ -2263,17 +2265,17 @@ 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 = ImGuiFullscreen::UIStyle.MediumFont->CalcTextSizeA( + ImGuiFullscreen::UIStyle.MediumFont->FontSize, 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(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, 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, nullptr, 0.0f, - &text_clip_rect); + dl->AddText(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, icon_pos, text_col, ICON_FA_STOPWATCH, nullptr, + 0.0f, &text_clip_rect); if (!indicator.active && opacity <= 0.01f) { @@ -2297,9 +2299,8 @@ void Achievements::DrawGameOverlays() void Achievements::DrawPauseMenuOverlays() { - using ImGuiFullscreen::g_large_font; - using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LayoutScale; + using ImGuiFullscreen::UIStyle; if (!HasActiveGame()) return; @@ -2310,11 +2311,12 @@ void Achievements::DrawPauseMenuOverlays() return; const ImGuiIO& io = ImGui::GetIO(); - ImFont* font = g_medium_font; + ImFont* font = UIStyle.MediumFont; 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) + UIStyle.LargeFont->FontSize + (UIStyle.MediumFont->FontSize * 2.0f); const float margin = LayoutScale(10.0f); const float spacing = LayoutScale(10.0f); const float padding = LayoutScale(10.0f); @@ -2398,9 +2400,8 @@ bool Achievements::PrepareAchievementsWindow() void Achievements::DrawAchievementsWindow() { - using ImGuiFullscreen::g_large_font; - using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LayoutScale; + using ImGuiFullscreen::UIStyle; if (!s_state.achievement_list) return; @@ -2411,10 +2412,10 @@ void Achievements::DrawAchievementsWindow() static constexpr float heading_alpha = 0.95f; static constexpr float heading_height_unscaled = 110.0f; - const ImVec4 background = ImGuiFullscreen::ModAlpha(ImGuiFullscreen::UIBackgroundColor, alpha); - const ImVec4 heading_background = ImGuiFullscreen::ModAlpha(ImGuiFullscreen::UIBackgroundColor, heading_alpha); + const ImVec4 background = ImGuiFullscreen::ModAlpha(UIStyle.BackgroundColor, alpha); + const ImVec4 heading_background = ImGuiFullscreen::ModAlpha(UIStyle.BackgroundColor, heading_alpha); const ImVec2 display_size = ImGui::GetIO().DisplaySize; - const float heading_height = ImGuiFullscreen::LayoutScale(heading_height_unscaled); + const float heading_height = LayoutScale(heading_height_unscaled); bool close_window = false; if (ImGuiFullscreen::BeginFullscreenWindow( @@ -2427,9 +2428,9 @@ void Achievements::DrawAchievementsWindow() &bb.Min, &bb.Max, 0, heading_alpha); if (visible) { - const float padding = ImGuiFullscreen::LayoutScale(10.0f); - const float spacing = ImGuiFullscreen::LayoutScale(10.0f); - const float image_height = ImGuiFullscreen::LayoutScale(85.0f); + const float padding = LayoutScale(10.0f); + const float spacing = LayoutScale(10.0f); + const float image_height = LayoutScale(85.0f); const ImVec2 icon_min(bb.Min + ImVec2(padding, padding)); const ImVec2 icon_max(icon_min + ImVec2(image_height, image_height)); @@ -2452,23 +2453,23 @@ void Achievements::DrawAchievementsWindow() ImVec2 text_size; close_window = (ImGuiFullscreen::FloatingButton(ICON_FA_WINDOW_CLOSE, 10.0f, 10.0f, -1.0f, -1.0f, 1.0f, 0.0f, - true, g_large_font) || + true, UIStyle.LargeFont) || ImGuiFullscreen::WantsToCloseMenu()); - const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + g_large_font->FontSize)); + const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + UIStyle.LargeFont->FontSize)); text.assign(s_state.game_title); if (s_state.hardcore_mode) text.append(TRANSLATE_SV("Achievements", " (Hardcore Mode)")); - top += g_large_font->FontSize + spacing; + top += UIStyle.LargeFont->FontSize + spacing; - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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 + UIStyle.MediumFont->FontSize)); if (s_state.game_summary.num_core_achievements > 0) { if (s_state.game_summary.num_unlocked_achievements == s_state.game_summary.num_core_achievements) @@ -2489,31 +2490,31 @@ void Achievements::DrawAchievementsWindow() text.assign(TRANSLATE_SV("Achievements", "This game has no achievements.")); } - top += g_medium_font->FontSize + spacing; + top += UIStyle.MediumFont->FontSize + spacing; - ImGui::PushFont(g_medium_font); + ImGui::PushFont(UIStyle.MediumFont); ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &summary_bb); ImGui::PopFont(); if (s_state.game_summary.num_core_achievements > 0) { - const float progress_height = ImGuiFullscreen::LayoutScale(20.0f); + const float progress_height = LayoutScale(20.0f); const ImRect progress_bb(ImVec2(left, top), ImVec2(right, top + progress_height)); const float fraction = static_cast(s_state.game_summary.num_unlocked_achievements) / static_cast(s_state.game_summary.num_core_achievements); - dl->AddRectFilled(progress_bb.Min, progress_bb.Max, ImGui::GetColorU32(ImGuiFullscreen::UIPrimaryDarkColor)); + dl->AddRectFilled(progress_bb.Min, progress_bb.Max, ImGui::GetColorU32(UIStyle.PrimaryDarkColor)); dl->AddRectFilled(progress_bb.Min, ImVec2(progress_bb.Min.x + fraction * progress_bb.GetWidth(), progress_bb.Max.y), - ImGui::GetColorU32(ImGuiFullscreen::UISecondaryColor)); + ImGui::GetColorU32(UIStyle.SecondaryColor)); text.format("{}%", static_cast(std::round(fraction * 100.0f))); text_size = ImGui::CalcTextSize(text.c_str(), text.end_ptr()); 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), text.c_str(), text.end_ptr()); + dl->AddText(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, text_pos, + ImGui::GetColorU32(UIStyle.PrimaryTextColor), text.c_str(), text.end_ptr()); top += progress_height + spacing; } } @@ -2587,10 +2588,9 @@ void Achievements::DrawAchievementsWindow() void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo) { - using ImGuiFullscreen::g_large_font; - using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LayoutScale; using ImGuiFullscreen::LayoutUnscale; + using ImGuiFullscreen::UIStyle; static constexpr float alpha = 0.8f; static constexpr float progress_height_unscaled = 20.0f; @@ -2602,18 +2602,19 @@ void Achievements::DrawAchievement(const rc_client_achievement_t* cheevo) const std::string_view measured_progress(cheevo->measured_progress); 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"))); + const ImVec2 points_template_size(UIStyle.MediumFont->CalcTextSizeA(UIStyle.MediumFont->FontSize, 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, cheevo->description + summary_length)); + const ImVec2 summary_text_size(UIStyle.MediumFont->CalcTextSizeA(UIStyle.MediumFont->FontSize, 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 - UIStyle.MediumFont->FontSize, 0.0f)); ImRect bb; bool visible, hovered; @@ -2653,10 +2654,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 + UIStyle.LargeFont->FontSize + spacing; text = TRANSLATE_PLURAL_SSTR("Achievements", "%n points", "Achievement points", cheevo->points); const ImVec2 points_size( - g_medium_font->CalcTextSizeA(g_medium_font->FontSize, FLT_MAX, 0.0f, text.c_str(), text.end_ptr())); + UIStyle.MediumFont->CalcTextSizeA(UIStyle.MediumFont->FontSize, 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); @@ -2682,23 +2683,24 @@ 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( + UIStyle.LargeFont->CalcTextSizeA(UIStyle.LargeFont->FontSize, 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)); + ImVec2(points_start, midpoint + UIStyle.MediumFont->FontSize + 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(UIStyle.LargeFont); 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(UIStyle.MediumFont); if (cheevo->description && summary_length > 0) { ImGui::RenderTextWrapped(summary_bb.Min, cheevo->description, cheevo->description + summary_length, @@ -2722,19 +2724,19 @@ 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 + UIStyle.MediumFont->FontSize + 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)); + dl->AddRectFilled(progress_bb.Min, progress_bb.Max, ImGui::GetColorU32(ImGuiFullscreen::UIStyle.PrimaryDarkColor)); dl->AddRectFilled(progress_bb.Min, ImVec2(progress_bb.Min.x + fraction * progress_bb.GetWidth(), progress_bb.Max.y), - ImGui::GetColorU32(ImGuiFullscreen::UISecondaryColor)); + ImGui::GetColorU32(ImGuiFullscreen::UIStyle.SecondaryColor)); 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), measured_progress.data(), + dl->AddText(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, text_pos, + ImGui::GetColorU32(ImGuiFullscreen::UIStyle.PrimaryTextColor), measured_progress.data(), measured_progress.data() + measured_progress.size()); } @@ -2769,9 +2771,8 @@ bool Achievements::PrepareLeaderboardsWindow() void Achievements::DrawLeaderboardsWindow() { - using ImGuiFullscreen::g_large_font; - using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LayoutScale; + using ImGuiFullscreen::UIStyle; static constexpr float alpha = 0.8f; static constexpr float heading_alpha = 0.95f; @@ -2785,8 +2786,8 @@ void Achievements::DrawLeaderboardsWindow() ImRect bb; - const ImVec4 background = ImGuiFullscreen::ModAlpha(ImGuiFullscreen::UIBackgroundColor, alpha); - const ImVec4 heading_background = ImGuiFullscreen::ModAlpha(ImGuiFullscreen::UIBackgroundColor, heading_alpha); + const ImVec4 background = ImGuiFullscreen::ModAlpha(ImGuiFullscreen::UIStyle.BackgroundColor, alpha); + const ImVec4 heading_background = ImGuiFullscreen::ModAlpha(ImGuiFullscreen::UIStyle.BackgroundColor, heading_alpha); const ImVec2 display_size = ImGui::GetIO().DisplaySize; const float padding = LayoutScale(10.0f); const float spacing = LayoutScale(10.0f); @@ -2802,13 +2803,15 @@ void Achievements::DrawLeaderboardsWindow() } const float rank_column_width = - g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits::max(), -1.0f, "99999").x; + UIStyle.LargeFont->CalcTextSizeA(UIStyle.LargeFont->FontSize, std::numeric_limits::max(), -1.0f, "99999").x; const float name_column_width = - g_large_font - ->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits::max(), -1.0f, "WWWWWWWWWWWWWWWWWWWWWW") + UIStyle.LargeFont + ->CalcTextSizeA(UIStyle.LargeFont->FontSize, std::numeric_limits::max(), -1.0f, "WWWWWWWWWWWWWWWWWWWWWW") .x; const float time_column_width = - g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits::max(), -1.0f, "WWWWWWWWWWW").x; + UIStyle.LargeFont + ->CalcTextSizeA(UIStyle.LargeFont->FontSize, std::numeric_limits::max(), -1.0f, "WWWWWWWWWWW") + .x; const float column_spacing = spacing * 2.0f; if (ImGuiFullscreen::BeginFullscreenWindow( @@ -2845,7 +2848,7 @@ void Achievements::DrawLeaderboardsWindow() if (!is_leaderboard_open) { if (ImGuiFullscreen::FloatingButton(ICON_FA_WINDOW_CLOSE, 10.0f, 10.0f, -1.0f, -1.0f, 1.0f, 0.0f, true, - g_large_font) || + UIStyle.LargeFont) || ImGuiFullscreen::WantsToCloseMenu()) { FullscreenUI::ReturnToPreviousWindow(); @@ -2854,31 +2857,31 @@ void Achievements::DrawLeaderboardsWindow() else { if (ImGuiFullscreen::FloatingButton(ICON_FA_CARET_SQUARE_LEFT, 10.0f, 10.0f, -1.0f, -1.0f, 1.0f, 0.0f, true, - g_large_font) || + UIStyle.LargeFont) || ImGuiFullscreen::WantsToCloseMenu()) { close_leaderboard_on_exit = true; } } - const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + g_large_font->FontSize)); + const ImRect title_bb(ImVec2(left, top), ImVec2(right, top + UIStyle.LargeFont->FontSize)); text.assign(Achievements::GetGameTitle()); - top += g_large_font->FontSize + spacing; + top += UIStyle.LargeFont->FontSize + spacing; - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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 + UIStyle.LargeFont->FontSize)); text.assign(s_state.open_leaderboard->title); - top += g_large_font->FontSize + spacing_small; + top += UIStyle.LargeFont->FontSize + spacing_small; - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::RenderTextClipped(subtitle_bb.Min, subtitle_bb.Max, text.c_str(), text.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &subtitle_bb); ImGui::PopFont(); @@ -2893,17 +2896,17 @@ void Achievements::DrawLeaderboardsWindow() text = TRANSLATE_PLURAL_SSTR("Achievements", "This game has %n leaderboards.", "Leaderboard count", 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 + UIStyle.MediumFont->FontSize)); + top += UIStyle.MediumFont->FontSize + spacing_small; - ImGui::PushFont(g_medium_font); + ImGui::PushFont(UIStyle.MediumFont); 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 + UIStyle.MediumFont->FontSize)); + top += UIStyle.MediumFont->FontSize + spacing_small; ImGui::RenderTextClipped( hardcore_warning_bb.Min, hardcore_warning_bb.Max, @@ -2916,7 +2919,7 @@ void Achievements::DrawLeaderboardsWindow() if (is_leaderboard_open) { - const float tab_width = (ImGui::GetWindowWidth() / ImGuiFullscreen::g_layout_scale) * 0.5f; + const float tab_width = (ImGui::GetWindowWidth() / ImGuiFullscreen::UIStyle.LayoutScale) * 0.5f; ImGui::SetCursorPos(ImVec2(0.0f, top + spacing_small)); if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft, false) || @@ -2953,10 +2956,10 @@ void Achievements::DrawLeaderboardsWindow() &visible, &hovered, &bb.Min, &bb.Max, 0, alpha); UNREFERENCED_VARIABLE(pressed); - const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f); + const float midpoint = bb.Min.y + UIStyle.LargeFont->FontSize + LayoutScale(4.0f); float text_start_x = bb.Min.x + LayoutScale(15.0f) + padding; - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); const ImRect rank_bb(ImVec2(text_start_x, bb.Min.y), ImVec2(bb.Max.x, midpoint)); ImGui::RenderTextClipped(rank_bb.Min, rank_bb.Max, TRANSLATE("Achievements", "Rank"), nullptr, nullptr, @@ -2991,7 +2994,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 + UIStyle.LargeFont->FontSize + 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); @@ -3063,7 +3066,7 @@ void Achievements::DrawLeaderboardsWindow() } else { - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); const ImVec2 pos_min(0.0f, heading_height); const ImVec2 pos_max(display_size.x, display_size.y); @@ -3092,10 +3095,10 @@ void Achievements::DrawLeaderboardsWindow() &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 + UIStyle.LargeFont->FontSize + LayoutScale(4.0f); const ImRect title_bb(bb.Min, ImVec2(bb.Max.x, midpoint)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, TRANSLATE("Achievements", "Loading..."), nullptr, nullptr, ImVec2(0, 0), &title_bb); ImGui::PopFont(); @@ -3130,8 +3133,8 @@ void Achievements::DrawLeaderboardEntry(const rc_client_leaderboard_entry_t& ent float rank_column_width, float name_column_width, float time_column_width, float column_spacing) { - using ImGuiFullscreen::g_large_font; using ImGuiFullscreen::LayoutScale; + using ImGuiFullscreen::UIStyle; static constexpr float alpha = 0.8f; @@ -3143,13 +3146,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 + UIStyle.LargeFont->FontSize + 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(UIStyle.LargeFont); if (is_self) ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 242, 0, 255)); @@ -3212,9 +3215,8 @@ void Achievements::DrawLeaderboardEntry(const rc_client_leaderboard_entry_t& ent } void Achievements::DrawLeaderboardListEntry(const rc_client_leaderboard_t* lboard) { - using ImGuiFullscreen::g_large_font; - using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LayoutScale; + using ImGuiFullscreen::UIStyle; static constexpr float alpha = 0.8f; @@ -3228,18 +3230,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 + UIStyle.LargeFont->FontSize + 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(UIStyle.LargeFont); 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(UIStyle.MediumFont); ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, lboard->description, nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb); ImGui::PopFont(); diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index e9059aff2..a9869f06f 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -72,10 +72,6 @@ public: #define FSUI_NSTR(str) str using ImGuiFullscreen::FocusResetType; -using ImGuiFullscreen::g_large_font; -using ImGuiFullscreen::g_layout_padding_left; -using ImGuiFullscreen::g_layout_padding_top; -using ImGuiFullscreen::g_medium_font; using ImGuiFullscreen::LAYOUT_FOOTER_HEIGHT; using ImGuiFullscreen::LAYOUT_LARGE_FONT_SIZE; using ImGuiFullscreen::LAYOUT_MEDIUM_FONT_SIZE; @@ -85,21 +81,7 @@ using ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING; using ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING; using ImGuiFullscreen::LAYOUT_SCREEN_HEIGHT; using ImGuiFullscreen::LAYOUT_SCREEN_WIDTH; -using ImGuiFullscreen::UIBackgroundColor; -using ImGuiFullscreen::UIBackgroundHighlightColor; -using ImGuiFullscreen::UIBackgroundLineColor; -using ImGuiFullscreen::UIBackgroundTextColor; -using ImGuiFullscreen::UIDisabledColor; -using ImGuiFullscreen::UIPrimaryColor; -using ImGuiFullscreen::UIPrimaryDarkColor; -using ImGuiFullscreen::UIPrimaryLightColor; -using ImGuiFullscreen::UIPrimaryLineColor; -using ImGuiFullscreen::UIPrimaryTextColor; -using ImGuiFullscreen::UISecondaryColor; -using ImGuiFullscreen::UISecondaryStrongColor; -using ImGuiFullscreen::UISecondaryTextColor; -using ImGuiFullscreen::UISecondaryWeakColor; -using ImGuiFullscreen::UITextHighlightColor; +using ImGuiFullscreen::UIStyle; using ImGuiFullscreen::ActiveButton; using ImGuiFullscreen::AddNotification; @@ -331,33 +313,34 @@ static void DoSaveInputProfile(const std::string& name); 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); + float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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, const char* tr_context = TR_CONTEXT); + float height = ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT, + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont, + const char* tr_context = TR_CONTEXT); 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, + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); #if 0 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, @@ -378,15 +361,15 @@ static void DrawEnumSetting(SettingsInterface* bsi, const char* title, const cha 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); static void PopulateGraphicsAdapterList(); static void PopulateGameListDirectoryCache(SettingsInterface* si); @@ -1293,14 +1276,14 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) *menu_pos = ImVec2(0.0f, heading_size.y); *menu_size = ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)); - if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "landing_heading", UIPrimaryColor)) + if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "landing_heading", UIStyle.PrimaryColor)) { - ImFont* const heading_font = g_large_font; + ImFont* const heading_font = UIStyle.LargeFont; ImDrawList* const dl = ImGui::GetWindowDrawList(); SmallString heading_str; ImGui::PushFont(heading_font); - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); // draw branding { @@ -1361,7 +1344,7 @@ void FullscreenUI::DrawLandingWindow() ImVec2 menu_pos, menu_size; DrawLandingTemplate(&menu_pos, &menu_size); - ImGui::PushStyleColor(ImGuiCol_Text, UIBackgroundTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); if (BeginHorizontalMenu("landing_window", menu_pos, menu_size, 4)) { @@ -1433,7 +1416,7 @@ void FullscreenUI::DrawStartGameWindow() ImVec2 menu_pos, menu_size; DrawLandingTemplate(&menu_pos, &menu_size); - ImGui::PushStyleColor(ImGuiCol_Text, UIBackgroundTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); if (BeginHorizontalMenu("start_game_window", menu_pos, menu_size, 4)) { @@ -1497,7 +1480,7 @@ void FullscreenUI::DrawExitWindow() ImVec2 menu_pos, menu_size; DrawLandingTemplate(&menu_pos, &menu_size); - ImGui::PushStyleColor(ImGuiCol_Text, UIBackgroundTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); if (BeginHorizontalMenu("exit_window", menu_pos, menu_size, 3)) { @@ -1687,11 +1670,11 @@ void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingIn } } - const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f); + const float midpoint = bb.Min.y + UIStyle.LargeFont->FontSize + LayoutScale(4.0f); if (oneline) { - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); const ImVec2 value_size(ImGui::CalcTextSize(value.empty() ? FSUI_CSTR("-") : value.c_str(), nullptr)); const float text_end = bb.Max.x - value_size.x; @@ -1708,12 +1691,12 @@ void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingIn 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(UIStyle.LargeFont); 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(UIStyle.MediumFont); 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(); @@ -1849,7 +1832,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(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -1983,7 +1966,7 @@ void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -2010,7 +1993,7 @@ void FullscreenUI::DrawIntRangeSetting(SettingsInterface* bsi, const char* title } ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -2041,7 +2024,7 @@ void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* tit ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -2071,7 +2054,7 @@ void FullscreenUI::DrawFloatRangeSetting(SettingsInterface* bsi, const char* tit } ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -2107,7 +2090,7 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -2154,27 +2137,27 @@ 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); + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - UIStyle.LargeFont->FontSize) * 0.5f); ImGui::TextUnformatted(str_value); float step = 0; - if (FloatingButton(ICON_FA_CHEVRON_UP, padding.x, button_pos.y, -1.0f, -1.0f, 1.0f, 0.0f, true, g_large_font, + if (FloatingButton(ICON_FA_CHEVRON_UP, padding.x, button_pos.y, -1.0f, -1.0f, 1.0f, 0.0f, true, UIStyle.LargeFont, &button_pos, true)) { step = step_value; } if (FloatingButton(ICON_FA_CHEVRON_DOWN, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos, true)) + UIStyle.LargeFont, &button_pos, true)) { step = -step_value; } if (FloatingButton(ICON_FA_KEYBOARD, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos)) + UIStyle.LargeFont, &button_pos)) { manual_input = true; } if (FloatingButton(ICON_FA_TRASH, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos)) + UIStyle.LargeFont, &button_pos)) { dlg_value = default_value * multiplier; dlg_value_changed = true; @@ -2201,7 +2184,7 @@ void FullscreenUI::DrawFloatSpinBoxSetting(SettingsInterface* bsi, const char* t SetSettingsChanged(bsi); } - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -2359,7 +2342,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -2400,27 +2383,27 @@ 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); + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - UIStyle.LargeFont->FontSize) * 0.5f); ImGui::TextUnformatted(str_value); s32 step = 0; - if (FloatingButton(ICON_FA_CHEVRON_UP, padding.x, button_pos.y, -1.0f, -1.0f, 1.0f, 0.0f, true, g_large_font, + if (FloatingButton(ICON_FA_CHEVRON_UP, padding.x, button_pos.y, -1.0f, -1.0f, 1.0f, 0.0f, true, UIStyle.LargeFont, &button_pos, true)) { step = step_value; } if (FloatingButton(ICON_FA_CHEVRON_DOWN, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos, true)) + UIStyle.LargeFont, &button_pos, true)) { step = -step_value; } if (FloatingButton(ICON_FA_KEYBOARD, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos)) + UIStyle.LargeFont, &button_pos)) { manual_input = true; } if (FloatingButton(ICON_FA_TRASH, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos)) + UIStyle.LargeFont, &button_pos)) { dlg_value = default_value; dlg_value_changed = true; @@ -2447,7 +2430,7 @@ void FullscreenUI::DrawIntSpinBoxSetting(SettingsInterface* bsi, const char* tit SetSettingsChanged(bsi); } - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -2860,7 +2843,7 @@ void FullscreenUI::DrawSettingsWindow() const float bg_alpha = System::IsValid() ? (s_settings_page == SettingsPage::PostProcessing ? 0.50f : 0.90f) : 1.0f; if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "settings_category", - ImVec4(UIPrimaryColor.x, UIPrimaryColor.y, UIPrimaryColor.z, bg_alpha))) + ImVec4(UIStyle.PrimaryColor.x, UIStyle.PrimaryColor.y, UIStyle.PrimaryColor.z, bg_alpha))) { static constexpr float ITEM_WIDTH = 25.0f; @@ -2959,7 +2942,7 @@ void FullscreenUI::DrawSettingsWindow() ImVec2(0.0f, heading_size.y), ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)), TinyString::from_format("settings_page_{}", static_cast(s_settings_page)).c_str(), - ImVec4(UIBackgroundColor.x, UIBackgroundColor.y, UIBackgroundColor.z, bg_alpha), 0.0f, + ImVec4(UIStyle.BackgroundColor.x, UIStyle.BackgroundColor.y, UIStyle.BackgroundColor.z, bg_alpha), 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f))) { ResetFocusHere(); @@ -3597,7 +3580,7 @@ void FullscreenUI::DrawEmulationSettingsPage() "system requirements."); } - ActiveButton(rewind_summary, false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font); + ActiveButton(rewind_summary, false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont); EndMenuButtons(); } @@ -3986,7 +3969,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(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -4039,8 +4022,8 @@ void FullscreenUI::DrawControllerSettingsPage() break; case SettingInfo::Type::IntegerList: DrawIntListSetting(bsi, title, description, section.c_str(), si.name, si.IntegerDefaultValue(), si.options, - 0, true, si.IntegerMinValue(), true, LAYOUT_MENU_BUTTON_HEIGHT, g_large_font, - g_medium_font, ci->name); + 0, true, si.IntegerMinValue(), true, LAYOUT_MENU_BUTTON_HEIGHT, UIStyle.LargeFont, + UIStyle.MediumFont, ci->name); break; case SettingInfo::Type::Float: DrawFloatSpinBoxSetting(bsi, title, description, section.c_str(), si.name, si.FloatDefaultValue(), @@ -4583,7 +4566,7 @@ void FullscreenUI::DrawGraphicsSettingsPage() MenuHeading(FSUI_CSTR("Texture Replacements")); ActiveButton(FSUI_CSTR("The texture cache is currently experimental, and may cause rendering errors in some games."), - false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font); + false, false, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont); DrawToggleSetting(bsi, FSUI_ICONSTR(ICON_FA_ID_BADGE, "Enable Texture Cache"), FSUI_CSTR("Enables caching of guest textures, required for texture replacement."), "GPU", @@ -4791,7 +4774,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage() 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(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -4864,7 +4847,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage() #endif ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -4890,7 +4873,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage() 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(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -4962,7 +4945,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage() #endif ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -5226,7 +5209,7 @@ void FullscreenUI::DrawAchievementsLoginWindow() ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); const char* popup_title = FSUI_CSTR("RetroAchievements Login"); bool popup_closed = false; @@ -5482,7 +5465,7 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) ImGui::SetNextWindowSize(LayoutScale(500.0f, 194.0f)); ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -5501,24 +5484,24 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) ImVec2 button_pos(ImGui::GetCursorPos()); // 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); + ImGui::SetCursorPosY(button_pos.y + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + padding.y * 2.0f) - + UIStyle.LargeFont->FontSize) * + 0.5f); ImGui::TextUnformatted(visible_value.c_str(), visible_value.end_ptr()); s32 step = 0; - if (FloatingButton(ICON_FA_CHEVRON_UP, padding.x, button_pos.y, -1.0f, -1.0f, 1.0f, 0.0f, true, g_large_font, - &button_pos, true)) + if (FloatingButton(ICON_FA_CHEVRON_UP, padding.x, button_pos.y, -1.0f, -1.0f, 1.0f, 0.0f, true, + UIStyle.LargeFont, &button_pos, true)) { step = step_value; } if (FloatingButton(ICON_FA_CHEVRON_DOWN, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, - true, g_large_font, &button_pos, true)) + true, UIStyle.LargeFont, &button_pos, true)) { step = -step_value; } if (FloatingButton(ICON_FA_TRASH, button_pos.x - padding.x, button_pos.y, -1.0f, -1.0f, -1.0f, 0.0f, true, - g_large_font, &button_pos)) + UIStyle.LargeFont, &button_pos)) { range_value = ci.option_range_start - 1; range_value_changed = true; @@ -5555,7 +5538,7 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) SetSettingsChanged(bsi); } - if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, + if (MenuButtonWithoutSummary(FSUI_CSTR("OK"), true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, ImVec2(0.5f, 0.0f))) { ImGui::CloseCurrentPopup(); @@ -5679,9 +5662,9 @@ void FullscreenUI::DrawPauseMenu() ImDrawList* dl = ImGui::GetBackgroundDrawList(); const ImVec2 display_size(ImGui::GetIO().DisplaySize); - const ImU32 text_color = ImGui::GetColorU32(UIBackgroundTextColor) | IM_COL32_A_MASK; + const ImU32 text_color = ImGui::GetColorU32(UIStyle.BackgroundTextColor) | IM_COL32_A_MASK; dl->AddRectFilled(ImVec2(0.0f, 0.0f), display_size, - (ImGui::GetColorU32(UIBackgroundColor) & ~IM_COL32_A_MASK) | (200 << IM_COL32_A_SHIFT)); + (ImGui::GetColorU32(UIStyle.BackgroundColor) & ~IM_COL32_A_MASK) | (200 << IM_COL32_A_SHIFT)); // title info { @@ -5695,15 +5678,15 @@ void FullscreenUI::DrawPauseMenu() const float image_width = 60.0f; const float image_height = 60.0f; - const ImVec2 title_size( - g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits::max(), -1.0f, title.c_str())); - const ImVec2 subtitle_size( - g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits::max(), -1.0f, buffer.c_str())); + const ImVec2 title_size(UIStyle.LargeFont->CalcTextSizeA(UIStyle.LargeFont->FontSize, + std::numeric_limits::max(), -1.0f, title.c_str())); + const ImVec2 subtitle_size(UIStyle.MediumFont->CalcTextSizeA( + UIStyle.MediumFont->FontSize, std::numeric_limits::max(), -1.0f, buffer.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 subtitle_pos(display_size.x - LayoutScale(10.0f + image_width + 20.0f) - subtitle_size.x, - title_pos.y + g_large_font->FontSize + LayoutScale(4.0f)); + title_pos.y + UIStyle.LargeFont->FontSize + LayoutScale(4.0f)); float rp_height = 0.0f; { @@ -5713,24 +5696,25 @@ void FullscreenUI::DrawPauseMenu() 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::max(), - wrap_width, rp.data(), rp.data() + rp.length()); + const ImVec2 rp_size = + UIStyle.MediumFont->CalcTextSizeA(UIStyle.MediumFont->FontSize, std::numeric_limits::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 - UIStyle.MediumFont->FontSize + 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 + UIStyle.MediumFont->FontSize + LayoutScale(4.0f) - rp_height); title_pos.y -= rp_height; subtitle_pos.y -= rp_height; - DrawShadowedText(dl, g_medium_font, rp_pos, text_color, rp.data(), rp.data() + rp.length(), wrap_width); + DrawShadowedText(dl, UIStyle.MediumFont, rp_pos, text_color, rp.data(), rp.data() + rp.length(), wrap_width); } } - DrawShadowedText(dl, g_large_font, title_pos, text_color, title.c_str()); - DrawShadowedText(dl, g_medium_font, subtitle_pos, text_color, buffer.c_str()); + DrawShadowedText(dl, UIStyle.LargeFont, title_pos, text_color, title.c_str()); + DrawShadowedText(dl, UIStyle.MediumFont, subtitle_pos, text_color, buffer.c_str()); GPUTexture* const cover = GetCoverForCurrentGame(); const ImVec2 image_min(display_size.x - LayoutScale(10.0f + image_width), @@ -5746,10 +5730,10 @@ void FullscreenUI::DrawPauseMenu() { buffer.format("{:%X}", fmt::localtime(std::time(nullptr))); - const ImVec2 time_size(g_large_font->CalcTextSizeA(g_large_font->FontSize, std::numeric_limits::max(), -1.0f, - buffer.c_str(), buffer.end_ptr())); + const ImVec2 time_size(UIStyle.LargeFont->CalcTextSizeA( + UIStyle.LargeFont->FontSize, std::numeric_limits::max(), -1.0f, buffer.c_str(), buffer.end_ptr())); 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, buffer.c_str(), buffer.end_ptr()); + DrawShadowedText(dl, UIStyle.LargeFont, time_pos, text_color, buffer.c_str(), buffer.end_ptr()); const std::string& serial = System::GetGameSerial(); if (!serial.empty()) @@ -5758,18 +5742,18 @@ void FullscreenUI::DrawPauseMenu() const std::time_t session_time = static_cast(System::GetSessionPlayedTime()); buffer.format(FSUI_FSTR("Session: {}"), GameList::FormatTimespan(session_time, true)); - const ImVec2 session_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits::max(), - -1.0f, buffer.c_str(), buffer.end_ptr())); + const ImVec2 session_size(UIStyle.MediumFont->CalcTextSizeA( + UIStyle.MediumFont->FontSize, std::numeric_limits::max(), -1.0f, buffer.c_str(), buffer.end_ptr())); const ImVec2 session_pos(display_size.x - LayoutScale(10.0f) - session_size.x, - time_pos.y + g_large_font->FontSize + LayoutScale(4.0f)); - DrawShadowedText(dl, g_medium_font, session_pos, text_color, buffer.c_str(), buffer.end_ptr()); + time_pos.y + UIStyle.LargeFont->FontSize + LayoutScale(4.0f)); + DrawShadowedText(dl, UIStyle.MediumFont, session_pos, text_color, buffer.c_str(), buffer.end_ptr()); buffer.format(FSUI_FSTR("All Time: {}"), GameList::FormatTimespan(cached_played_time + session_time, true)); - const ImVec2 total_size(g_medium_font->CalcTextSizeA(g_medium_font->FontSize, std::numeric_limits::max(), - -1.0f, buffer.c_str(), buffer.end_ptr())); + const ImVec2 total_size(UIStyle.MediumFont->CalcTextSizeA( + UIStyle.MediumFont->FontSize, std::numeric_limits::max(), -1.0f, buffer.c_str(), buffer.end_ptr())); const ImVec2 total_pos(display_size.x - LayoutScale(10.0f) - total_size.x, - session_pos.y + g_medium_font->FontSize + LayoutScale(4.0f)); - DrawShadowedText(dl, g_medium_font, total_pos, text_color, buffer.c_str(), buffer.end_ptr()); + session_pos.y + UIStyle.MediumFont->FontSize + LayoutScale(4.0f)); + DrawShadowedText(dl, UIStyle.MediumFont, total_pos, text_color, buffer.c_str(), buffer.end_ptr()); } } @@ -6109,7 +6093,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) ImVec2(io.DisplaySize.x, LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); - ImGui::PushStyleColor(ImGuiCol_ChildBg, ModAlpha(UIPrimaryColor, 0.9f)); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ModAlpha(UIStyle.PrimaryColor, 0.9f)); bool closed = false; bool was_close_not_back = false; @@ -6126,7 +6110,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) } ImGui::PopStyleColor(); - ImGui::PushStyleColor(ImGuiCol_ChildBg, ModAlpha(UIBackgroundColor, 0.9f)); + ImGui::PushStyleColor(ImGuiCol_ChildBg, ModAlpha(UIStyle.BackgroundColor, 0.9f)); ImGui::SetCursorPos(ImVec2(0.0f, heading_size.y)); if (IsFocusResetFromWindowChange()) @@ -6149,8 +6133,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 + + UIStyle.LargeFont->FontSize + summary_spacing + UIStyle.MediumFont->FontSize; const ImVec2 item_size(item_width, item_height); const u32 grid_count_x = static_cast(std::floor(ImGui::GetWindowWidth() / item_width_with_spacing)); const float start_x = @@ -6166,18 +6150,18 @@ 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(UIStyle.LargeFont); 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); - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIPrimaryColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); 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 = UIStyle.LargeFont->FontSize + ImGui::GetStyle().FramePadding.y * 2.0f + + ImGui::GetStyle().WindowPadding.y * 2.0f; const float height = title_height + ((LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f)) * @@ -6190,7 +6174,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) if (ImGui::BeginPopupModal(entry.title.c_str(), &is_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { - ImGui::PushStyleColor(ImGuiCol_Text, UIBackgroundTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); BeginMenuButtons(); @@ -6305,17 +6289,17 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) 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 + UIStyle.LargeFont->FontSize)); + ImGui::PushFont(UIStyle.LargeFont); 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 + UIStyle.LargeFont->FontSize + summary_spacing); + const ImRect summary_bb(summary_pos, ImVec2(bb.Max.x, summary_pos.y + UIStyle.MediumFont->FontSize)); + ImGui::PushFont(UIStyle.MediumFont); ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, entry.summary.c_str(), nullptr, nullptr, ImVec2(0.0f, 0.0f), &summary_bb); ImGui::PopFont(); @@ -6413,7 +6397,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(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(20.0f, 20.0f)); @@ -6660,7 +6644,8 @@ void FullscreenUI::DrawGameListWindow() const float bg_alpha = System::IsValid() ? 0.90f : 1.0f; - if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "gamelist_view", MulAlpha(UIPrimaryColor, bg_alpha))) + if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "gamelist_view", + MulAlpha(UIStyle.PrimaryColor, bg_alpha))) { static constexpr float ITEM_WIDTH = 25.0f; static constexpr const char* icons[] = {ICON_FA_BORDER_ALL, ICON_FA_LIST}; @@ -6784,19 +6769,19 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size) ImGui::GetWindowDrawList()->AddImage(cover_texture, image_rect.Min, image_rect.Max, ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), IM_COL32(255, 255, 255, 255)); - const float midpoint = bb.Min.y + g_large_font->FontSize + LayoutScale(4.0f); + const float midpoint = bb.Min.y + UIStyle.LargeFont->FontSize + 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(UIStyle.LargeFont); ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, entry->title.c_str(), entry->title.c_str() + entry->title.size(), nullptr, ImVec2(0.0f, 0.0f), &title_bb); ImGui::PopFont(); if (!summary.empty()) { - ImGui::PushFont(g_medium_font); + ImGui::PushFont(UIStyle.MediumFont); ImGui::RenderTextClipped(summary_bb.Min, summary_bb.Max, summary.c_str(), summary.end_ptr(), nullptr, ImVec2(0.0f, 0.0f), &summary_bb); ImGui::PopFont(); @@ -6824,7 +6809,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size) } EndFullscreenColumnWindow(); - if (BeginFullscreenColumnWindow(-530.0f, 0.0f, "game_list_info", UIPrimaryDarkColor)) + if (BeginFullscreenColumnWindow(-530.0f, 0.0f, "game_list_info", UIStyle.PrimaryDarkColor)) { const GPUTexture* cover_texture = selected_entry ? GetGameListCover(selected_entry) : GetTextureForGameListEntryType(GameList::EntryType::Count); @@ -6854,13 +6839,13 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size) if (selected_entry) { // title - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); text_width = ImGui::CalcTextSize(selected_entry->title.c_str(), nullptr, false, work_width).x; ImGui::SetCursorPosX((work_width - text_width) / 2.0f); ImGui::TextWrapped("%s", selected_entry->title.c_str()); ImGui::PopFont(); - ImGui::PushFont(g_medium_font); + ImGui::PushFont(UIStyle.MediumFont); // developer if (selected_entry->dbentry && !selected_entry->dbentry->developer.empty()) @@ -6936,7 +6921,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size) { // title const char* title = FSUI_CSTR("No Game Selected"); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); text_width = ImGui::CalcTextSize(title, nullptr, false, work_width).x; ImGui::SetCursorPosX((work_width - text_width) / 2.0f); ImGui::TextWrapped("%s", title); @@ -6961,7 +6946,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size) if (!BeginFullscreenWindow( ImVec2(0.0f, heading_size.y), ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)), "game_grid", - UIBackgroundColor)) + UIStyle.BackgroundColor)) { EndFullscreenWindow(); return; @@ -6982,7 +6967,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; 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 + UIStyle.MediumFont->FontSize; const ImVec2 item_size(item_width, item_height); const u32 grid_count_x = static_cast(std::floor(ImGui::GetWindowWidth() / item_width_with_spacing)); const float start_x = @@ -7034,7 +7019,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size) const std::string_view title( std::string_view(entry->title).substr(0, (entry->title.length() > 31) ? 31 : std::string_view::npos)); draw_title.format("{}{}", title, (title.length() == entry->title.length()) ? "" : "..."); - ImGui::PushFont(g_medium_font); + ImGui::PushFont(UIStyle.MediumFont); ImGui::RenderTextClipped(title_bb.Min, title_bb.Max, draw_title.c_str(), draw_title.end_ptr(), nullptr, ImVec2(0.5f, 0.0f), &title_bb); ImGui::PopFont(); @@ -7209,7 +7194,8 @@ void FullscreenUI::DrawGameListSettingsWindow() const float bg_alpha = System::IsValid() ? 0.90f : 1.0f; - if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "gamelist_view", MulAlpha(UIPrimaryColor, bg_alpha))) + if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "gamelist_view", + MulAlpha(UIStyle.PrimaryColor, bg_alpha))) { BeginNavBar(); @@ -7228,7 +7214,7 @@ void FullscreenUI::DrawGameListSettingsWindow() if (!BeginFullscreenWindow( ImVec2(0.0f, heading_size.y), ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)), - "settings_parent", UIBackgroundColor, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f))) + "settings_parent", UIStyle.BackgroundColor, 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f))) { EndFullscreenWindow(); return; @@ -7471,7 +7457,7 @@ void FullscreenUI::DrawAboutWindow() ImGui::SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(FSUI_CSTR("About DuckStation")); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(30.0f, 30.0f)); diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 3ff62dbb5..2a4cd190a 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -60,83 +60,8 @@ static void PopulateFileSelectorItems(); 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; - -float g_layout_scale = 1.0f; -float g_rcp_layout_scale = 1.0f; -float g_layout_padding_left = 0.0f; -float g_layout_padding_top = 0.0f; - -ImVec4 UIBackgroundColor; -ImVec4 UIBackgroundTextColor; -ImVec4 UIBackgroundLineColor; -ImVec4 UIBackgroundHighlightColor; -ImVec4 UIPopupBackgroundColor; -ImVec4 UIDisabledColor; -ImVec4 UIPrimaryColor; -ImVec4 UIPrimaryLightColor; -ImVec4 UIPrimaryDarkColor; -ImVec4 UIPrimaryTextColor; -ImVec4 UITextHighlightColor; -ImVec4 UIPrimaryLineColor; -ImVec4 UISecondaryColor; -ImVec4 UISecondaryWeakColor; -ImVec4 UISecondaryStrongColor; -ImVec4 UISecondaryTextColor; - -static u32 s_menu_button_index = 0; -static u32 s_close_button_state = 0; -static ImGuiDir s_has_pending_nav_move = ImGuiDir_None; -static FocusResetType s_focus_reset_queued = FocusResetType::None; -static bool s_light_theme = false; -static bool s_smooth_scrolling = false; - -static LRUCache> s_texture_cache(128, true); -static std::shared_ptr s_placeholder_texture; -static std::atomic_bool s_texture_load_thread_quit{false}; -static std::mutex s_texture_load_mutex; -static std::condition_variable s_texture_load_cv; -static std::deque s_texture_load_queue; -static std::deque> s_texture_upload_queue; -static std::thread s_texture_load_thread; - -static SmallString s_fullscreen_footer_text; -static SmallString s_last_fullscreen_footer_text; -static float s_fullscreen_text_change_time; - -static bool s_choice_dialog_open = false; -static bool s_choice_dialog_checkable = false; -static std::string s_choice_dialog_title; -static ChoiceDialogOptions s_choice_dialog_options; -static ChoiceDialogCallback s_choice_dialog_callback; -static ImGuiID s_enum_choice_button_id = 0; -static s32 s_enum_choice_button_value = 0; -static bool s_enum_choice_button_set = false; - -static bool s_input_dialog_open = false; -static std::string s_input_dialog_title; -static std::string s_input_dialog_message; -static std::string s_input_dialog_caption; -static std::string s_input_dialog_text; -static std::string s_input_dialog_ok_text; -static InputStringDialogCallback s_input_dialog_callback; - -static bool s_message_dialog_open = false; -static std::string s_message_dialog_title; -static std::string s_message_dialog_message; -static std::array s_message_dialog_buttons; -static MessageDialogCallbackVariant s_message_dialog_callback; - -static ImAnimatedVec2 s_menu_button_frame_min_animated; -static ImAnimatedVec2 s_menu_button_frame_max_animated; -static bool s_had_hovered_menu_item = false; -static bool s_has_hovered_menu_item = false; -static bool s_rendered_menu_item_border = false; - namespace { + struct FileSelectorItem { FileSelectorItem() = default; @@ -155,20 +80,7 @@ struct FileSelectorItem std::string full_path; bool is_file; }; -} // namespace -static bool s_file_selector_open = false; -static bool s_file_selector_directory = false; -static std::string s_file_selector_title; -static ImGuiFullscreen::FileSelectorCallback s_file_selector_callback; -static std::string s_file_selector_current_directory; -static std::vector s_file_selector_filters; -static std::vector s_file_selector_items; - -static constexpr float NOTIFICATION_FADE_IN_TIME = 0.2f; -static constexpr float NOTIFICATION_FADE_OUT_TIME = 0.8f; - -namespace { struct Notification { std::string key; @@ -181,16 +93,7 @@ struct Notification float target_y; float last_y; }; -} // namespace -static std::vector s_notifications; - -static std::string s_toast_title; -static std::string s_toast_message; -static Timer::Value s_toast_start_time; -static float s_toast_duration; - -namespace { struct BackgroundProgressDialogData { std::string message; @@ -199,93 +102,167 @@ struct BackgroundProgressDialogData s32 max; s32 value; }; + +struct ALIGN_TO_CACHE_LINE UIState +{ + u32 menu_button_index = 0; + u32 close_button_state = 0; + ImGuiDir has_pending_nav_move = ImGuiDir_None; + FocusResetType focus_reset_queued = FocusResetType::None; + bool light_theme = false; + bool smooth_scrolling = false; + + LRUCache> texture_cache{128, true}; + std::shared_ptr placeholder_texture; + std::atomic_bool texture_load_thread_quit{false}; + std::mutex texture_load_mutex; + std::condition_variable texture_load_cv; + std::deque texture_load_queue; + std::deque> texture_upload_queue; + std::thread texture_load_thread; + + SmallString fullscreen_footer_text; + SmallString last_fullscreen_footer_text; + float fullscreen_text_change_time; + + bool choice_dialog_open = false; + bool choice_dialog_checkable = false; + std::string choice_dialog_title; + ChoiceDialogOptions choice_dialog_options; + ChoiceDialogCallback choice_dialog_callback; + ImGuiID enum_choice_button_id = 0; + s32 enum_choice_button_value = 0; + bool enum_choice_button_set = false; + + bool input_dialog_open = false; + std::string input_dialog_title; + std::string input_dialog_message; + std::string input_dialog_caption; + std::string input_dialog_text; + std::string input_dialog_ok_text; + InputStringDialogCallback input_dialog_callback; + + bool message_dialog_open = false; + std::string message_dialog_title; + std::string message_dialog_message; + std::array message_dialog_buttons; + MessageDialogCallbackVariant message_dialog_callback; + + ImAnimatedVec2 menu_button_frame_min_animated; + ImAnimatedVec2 menu_button_frame_max_animated; + bool had_hovered_menu_item = false; + bool has_hovered_menu_item = false; + bool rendered_menu_item_border = false; + + bool file_selector_open = false; + bool file_selector_directory = false; + std::string file_selector_title; + ImGuiFullscreen::FileSelectorCallback file_selector_callback; + std::string file_selector_current_directory; + std::vector file_selector_filters; + std::vector file_selector_items; + + std::vector notifications; + + std::string toast_title; + std::string toast_message; + Timer::Value toast_start_time; + float toast_duration; + + std::vector background_progress_dialogs; + std::mutex background_progress_lock; +}; + } // namespace -static std::vector s_background_progress_dialogs; -static std::mutex s_background_progress_lock; +static constexpr float NOTIFICATION_FADE_IN_TIME = 0.2f; +static constexpr float NOTIFICATION_FADE_OUT_TIME = 0.8f; + +UIStyles UIStyle = {}; +static UIState s_state; + } // namespace ImGuiFullscreen void ImGuiFullscreen::SetFonts(ImFont* medium_font, ImFont* large_font) { - g_medium_font = medium_font; - g_large_font = large_font; + UIStyle.MediumFont = medium_font; + UIStyle.LargeFont = large_font; } bool ImGuiFullscreen::Initialize(const char* placeholder_image_path) { - s_focus_reset_queued = FocusResetType::ViewChanged; - s_close_button_state = 0; + s_state.focus_reset_queued = FocusResetType::ViewChanged; + s_state.close_button_state = 0; - s_placeholder_texture = LoadTexture(placeholder_image_path); - if (!s_placeholder_texture) + s_state.placeholder_texture = LoadTexture(placeholder_image_path); + if (!s_state.placeholder_texture) { ERROR_LOG("Missing placeholder texture '{}', cannot continue", placeholder_image_path); return false; } - s_texture_load_thread_quit.store(false, std::memory_order_release); - s_texture_load_thread = std::thread(TextureLoaderThread); + s_state.texture_load_thread_quit.store(false, std::memory_order_release); + s_state.texture_load_thread = std::thread(TextureLoaderThread); ResetMenuButtonFrame(); return true; } void ImGuiFullscreen::Shutdown() { - if (s_texture_load_thread.joinable()) + if (s_state.texture_load_thread.joinable()) { { - std::unique_lock lock(s_texture_load_mutex); - s_texture_load_thread_quit.store(true, std::memory_order_release); - s_texture_load_cv.notify_one(); + std::unique_lock lock(s_state.texture_load_mutex); + s_state.texture_load_thread_quit.store(true, std::memory_order_release); + s_state.texture_load_cv.notify_one(); } - s_texture_load_thread.join(); + s_state.texture_load_thread.join(); } - s_texture_upload_queue.clear(); - s_placeholder_texture.reset(); - g_standard_font = nullptr; - g_medium_font = nullptr; - g_large_font = nullptr; + s_state.texture_upload_queue.clear(); + s_state.placeholder_texture.reset(); + UIStyle.MediumFont = nullptr; + UIStyle.LargeFont = nullptr; - s_texture_cache.Clear(); + s_state.texture_cache.Clear(); - s_notifications.clear(); - s_background_progress_dialogs.clear(); - s_fullscreen_footer_text.clear(); - s_last_fullscreen_footer_text.clear(); - s_fullscreen_text_change_time = 0.0f; + s_state.notifications.clear(); + s_state.background_progress_dialogs.clear(); + s_state.fullscreen_footer_text.clear(); + s_state.last_fullscreen_footer_text.clear(); + s_state.fullscreen_text_change_time = 0.0f; CloseInputDialog(); CloseMessageDialog(); - s_choice_dialog_open = false; - s_choice_dialog_checkable = false; - s_choice_dialog_title = {}; - s_choice_dialog_options.clear(); - s_choice_dialog_callback = {}; - s_enum_choice_button_id = 0; - s_enum_choice_button_value = 0; - s_enum_choice_button_set = false; - s_file_selector_open = false; - s_file_selector_directory = false; - s_file_selector_title = {}; - s_file_selector_callback = {}; - s_file_selector_current_directory = {}; - s_file_selector_filters.clear(); - s_file_selector_items.clear(); - s_message_dialog_open = false; - s_message_dialog_title = {}; - s_message_dialog_message = {}; - s_message_dialog_buttons = {}; - s_message_dialog_callback = {}; + s_state.choice_dialog_open = false; + s_state.choice_dialog_checkable = false; + s_state.choice_dialog_title = {}; + s_state.choice_dialog_options.clear(); + s_state.choice_dialog_callback = {}; + s_state.enum_choice_button_id = 0; + s_state.enum_choice_button_value = 0; + s_state.enum_choice_button_set = false; + s_state.file_selector_open = false; + s_state.file_selector_directory = false; + s_state.file_selector_title = {}; + s_state.file_selector_callback = {}; + s_state.file_selector_current_directory = {}; + s_state.file_selector_filters.clear(); + s_state.file_selector_items.clear(); + s_state.message_dialog_open = false; + s_state.message_dialog_title = {}; + s_state.message_dialog_message = {}; + s_state.message_dialog_buttons = {}; + s_state.message_dialog_callback = {}; } void ImGuiFullscreen::SetSmoothScrolling(bool enabled) { - s_smooth_scrolling = enabled; + s_state.smooth_scrolling = enabled; } const std::shared_ptr& ImGuiFullscreen::GetPlaceholderTexture() { - return s_placeholder_texture; + return s_state.placeholder_texture; } std::optional ImGuiFullscreen::LoadTextureImage(std::string_view path, u32 svg_width, u32 svg_height) @@ -379,16 +356,16 @@ std::shared_ptr ImGuiFullscreen::LoadTexture(std::string_view path, return ret; } - return s_placeholder_texture; + return s_state.placeholder_texture; } GPUTexture* ImGuiFullscreen::GetCachedTexture(std::string_view name) { - std::shared_ptr* tex_ptr = s_texture_cache.Lookup(name); + std::shared_ptr* tex_ptr = s_state.texture_cache.Lookup(name); if (!tex_ptr) { std::shared_ptr tex = LoadTexture(name); - tex_ptr = s_texture_cache.Insert(std::string(name), std::move(tex)); + tex_ptr = s_state.texture_cache.Insert(std::string(name), std::move(tex)); } return tex_ptr->get(); @@ -400,11 +377,11 @@ GPUTexture* ImGuiFullscreen::GetCachedTexture(std::string_view name, u32 svg_wid svg_height = static_cast(std::ceil(LayoutScale(static_cast(svg_height)))); const SmallString wh_name = SmallString::from_format("{}#{}x{}", name, svg_width, svg_height); - std::shared_ptr* tex_ptr = s_texture_cache.Lookup(wh_name.view()); + std::shared_ptr* tex_ptr = s_state.texture_cache.Lookup(wh_name.view()); if (!tex_ptr) { std::shared_ptr tex = LoadTexture(name, svg_width, svg_height); - tex_ptr = s_texture_cache.Insert(std::string(wh_name.view()), std::move(tex)); + tex_ptr = s_state.texture_cache.Insert(std::string(wh_name.view()), std::move(tex)); } return tex_ptr->get(); @@ -412,16 +389,16 @@ GPUTexture* ImGuiFullscreen::GetCachedTexture(std::string_view name, u32 svg_wid GPUTexture* ImGuiFullscreen::GetCachedTextureAsync(std::string_view name) { - std::shared_ptr* tex_ptr = s_texture_cache.Lookup(name); + std::shared_ptr* tex_ptr = s_state.texture_cache.Lookup(name); if (!tex_ptr) { // insert the placeholder - tex_ptr = s_texture_cache.Insert(std::string(name), s_placeholder_texture); + tex_ptr = s_state.texture_cache.Insert(std::string(name), s_state.placeholder_texture); // queue the actual load - std::unique_lock lock(s_texture_load_mutex); - s_texture_load_queue.emplace_back(name); - s_texture_load_cv.notify_one(); + std::unique_lock lock(s_state.texture_load_mutex); + s_state.texture_load_queue.emplace_back(name); + s_state.texture_load_cv.notify_one(); } return tex_ptr->get(); @@ -429,21 +406,21 @@ GPUTexture* ImGuiFullscreen::GetCachedTextureAsync(std::string_view name) bool ImGuiFullscreen::InvalidateCachedTexture(const std::string& path) { - return s_texture_cache.Remove(path); + return s_state.texture_cache.Remove(path); } void ImGuiFullscreen::UploadAsyncTextures() { - std::unique_lock lock(s_texture_load_mutex); - while (!s_texture_upload_queue.empty()) + std::unique_lock lock(s_state.texture_load_mutex); + while (!s_state.texture_upload_queue.empty()) { - std::pair it(std::move(s_texture_upload_queue.front())); - s_texture_upload_queue.pop_front(); + std::pair it(std::move(s_state.texture_upload_queue.front())); + s_state.texture_upload_queue.pop_front(); lock.unlock(); std::shared_ptr tex = UploadTexture(it.first.c_str(), it.second); if (tex) - s_texture_cache.Insert(std::move(it.first), std::move(tex)); + s_state.texture_cache.Insert(std::move(it.first), std::move(tex)); lock.lock(); } @@ -453,21 +430,21 @@ void ImGuiFullscreen::TextureLoaderThread() { Threading::SetNameOfCurrentThread("ImGuiFullscreen Texture Loader"); - std::unique_lock lock(s_texture_load_mutex); + std::unique_lock lock(s_state.texture_load_mutex); for (;;) { - s_texture_load_cv.wait(lock, []() { - return (s_texture_load_thread_quit.load(std::memory_order_acquire) || !s_texture_load_queue.empty()); + s_state.texture_load_cv.wait(lock, []() { + return (s_state.texture_load_thread_quit.load(std::memory_order_acquire) || !s_state.texture_load_queue.empty()); }); - if (s_texture_load_thread_quit.load(std::memory_order_acquire)) + if (s_state.texture_load_thread_quit.load(std::memory_order_acquire)) break; - while (!s_texture_load_queue.empty()) + while (!s_state.texture_load_queue.empty()) { - std::string path(std::move(s_texture_load_queue.front())); - s_texture_load_queue.pop_front(); + std::string path(std::move(s_state.texture_load_queue.front())); + s_state.texture_load_queue.pop_front(); lock.unlock(); std::optional image(LoadTextureImage(path.c_str(), 0, 0)); @@ -475,11 +452,11 @@ void ImGuiFullscreen::TextureLoaderThread() // don't bother queuing back if it doesn't exist if (image) - s_texture_upload_queue.emplace_back(std::move(path), std::move(image.value())); + s_state.texture_upload_queue.emplace_back(std::move(path), std::move(image.value())); } } - s_texture_load_queue.clear(); + s_state.texture_load_queue.clear(); } bool ImGuiFullscreen::UpdateLayoutScale() @@ -490,26 +467,26 @@ bool ImGuiFullscreen::UpdateLayoutScale() const float screen_width = io.DisplaySize.x; const float screen_height = io.DisplaySize.y; const float screen_ratio = screen_width / screen_height; - const float old_scale = g_layout_scale; + const float old_scale = UIStyle.LayoutScale; if (screen_ratio > LAYOUT_RATIO) { // screen is wider, use height, pad width - g_layout_scale = std::max(screen_height / LAYOUT_SCREEN_HEIGHT, 0.1f); - g_layout_padding_top = 0.0f; - g_layout_padding_left = (screen_width - (LAYOUT_SCREEN_WIDTH * g_layout_scale)) / 2.0f; + UIStyle.LayoutScale = std::max(screen_height / LAYOUT_SCREEN_HEIGHT, 0.1f); + UIStyle.LayoutPaddingTop = 0.0f; + UIStyle.LayoutPaddingLeft = (screen_width - (LAYOUT_SCREEN_WIDTH * UIStyle.LayoutScale)) / 2.0f; } else { // screen is taller, use width, pad height - g_layout_scale = std::max(screen_width / LAYOUT_SCREEN_WIDTH, 0.1f); - g_layout_padding_top = (screen_height - (LAYOUT_SCREEN_HEIGHT * g_layout_scale)) / 2.0f; - g_layout_padding_left = 0.0f; + UIStyle.LayoutScale = std::max(screen_width / LAYOUT_SCREEN_WIDTH, 0.1f); + UIStyle.LayoutPaddingTop = (screen_height - (LAYOUT_SCREEN_HEIGHT * UIStyle.LayoutScale)) / 2.0f; + UIStyle.LayoutPaddingLeft = 0.0f; } - g_rcp_layout_scale = 1.0f / g_layout_scale; + UIStyle.RcpLayoutScale = 1.0f / UIStyle.LayoutScale; - return g_layout_scale != old_scale; + return UIStyle.LayoutScale != old_scale; } ImRect ImGuiFullscreen::CenterImage(const ImVec2& fit_size, const ImVec2& image_size) @@ -549,7 +526,7 @@ void ImGuiFullscreen::BeginLayout() { // we evict from the texture cache at the start of the frame, in case we go over mid-frame, // we need to keep all those textures alive until the end of the frame - s_texture_cache.ManualEvict(); + s_state.texture_cache.ManualEvict(); PushResetLayout(); } @@ -574,10 +551,10 @@ void ImGuiFullscreen::EndLayout() PopResetLayout(); - s_fullscreen_footer_text.clear(); + s_state.fullscreen_footer_text.clear(); - s_rendered_menu_item_border = false; - s_had_hovered_menu_item = std::exchange(s_has_hovered_menu_item, false); + s_state.rendered_menu_item_border = false; + s_state.had_hovered_menu_item = std::exchange(s_state.has_hovered_menu_item, false); } void ImGuiFullscreen::PushResetLayout() @@ -594,17 +571,17 @@ void ImGuiFullscreen::PushResetLayout() ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_TabRounding, LayoutScale(4.0f)); - ImGui::PushStyleColor(ImGuiCol_Text, UISecondaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TextDisabled, UIDisabledColor); - ImGui::PushStyleColor(ImGuiCol_Button, UISecondaryColor); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, UIBackgroundColor); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, UIBackgroundHighlightColor); - ImGui::PushStyleColor(ImGuiCol_Border, UIBackgroundLineColor); - ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, UIBackgroundColor); - ImGui::PushStyleColor(ImGuiCol_ScrollbarGrab, UIPrimaryColor); - ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabHovered, UIPrimaryLightColor); - ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabActive, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_PopupBg, UIPopupBackgroundColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.SecondaryTextColor); + ImGui::PushStyleColor(ImGuiCol_TextDisabled, UIStyle.DisabledColor); + ImGui::PushStyleColor(ImGuiCol_Button, UIStyle.SecondaryColor); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, UIStyle.BackgroundColor); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, UIStyle.BackgroundHighlight); + ImGui::PushStyleColor(ImGuiCol_Border, UIStyle.BackgroundLineColor); + ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, UIStyle.BackgroundColor); + ImGui::PushStyleColor(ImGuiCol_ScrollbarGrab, UIStyle.PrimaryColor); + ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabHovered, UIStyle.PrimaryLightColor); + ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabActive, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_PopupBg, UIStyle.PopupBackgroundColor); } void ImGuiFullscreen::PopResetLayout() @@ -615,13 +592,13 @@ void ImGuiFullscreen::PopResetLayout() void ImGuiFullscreen::QueueResetFocus(FocusResetType type) { - s_focus_reset_queued = type; - s_close_button_state = 0; + s_state.focus_reset_queued = type; + s_state.close_button_state = 0; } bool ImGuiFullscreen::ResetFocusHere() { - if (s_focus_reset_queued == FocusResetType::None) + if (s_state.focus_reset_queued == FocusResetType::None) return false; // don't take focus from dialogs @@ -635,16 +612,16 @@ bool ImGuiFullscreen::ResetFocusHere() if (!GImGui->NavDisableHighlight && GImGui->NavDisableMouseHover) { window->Appearing = true; - s_has_hovered_menu_item = s_had_hovered_menu_item; + s_state.has_hovered_menu_item = s_state.had_hovered_menu_item; } ImGui::SetWindowFocus(); // If this is a popup closing, we don't want to reset the current nav item, since we were presumably opened by one. - if (s_focus_reset_queued != FocusResetType::PopupClosed) + if (s_state.focus_reset_queued != FocusResetType::PopupClosed) ImGui::NavInitWindow(window, true); - s_focus_reset_queued = FocusResetType::None; + s_state.focus_reset_queued = FocusResetType::None; // only do the active selection magic when we're using keyboard/gamepad return (GImGui->NavInputSource == ImGuiInputSource_Keyboard || GImGui->NavInputSource == ImGuiInputSource_Gamepad); @@ -652,17 +629,18 @@ bool ImGuiFullscreen::ResetFocusHere() bool ImGuiFullscreen::IsFocusResetQueued() { - return (s_focus_reset_queued != FocusResetType::None); + return (s_state.focus_reset_queued != FocusResetType::None); } bool ImGuiFullscreen::IsFocusResetFromWindowChange() { - return (s_focus_reset_queued != FocusResetType::None && s_focus_reset_queued != FocusResetType::PopupClosed); + return (s_state.focus_reset_queued != FocusResetType::None && + s_state.focus_reset_queued != FocusResetType::PopupClosed); } ImGuiFullscreen::FocusResetType ImGuiFullscreen::GetQueuedFocusResetType() { - return s_focus_reset_queued; + return s_state.focus_reset_queued; } void ImGuiFullscreen::ForceKeyNavEnabled() @@ -683,37 +661,37 @@ bool ImGuiFullscreen::WantsToCloseMenu() ImGuiContext& g = *GImGui; // Wait for the Close button to be released, THEN pressed - if (s_close_button_state == 0) + if (s_state.close_button_state == 0) { if (ImGui::IsKeyPressed(ImGuiKey_Escape, false)) - s_close_button_state = 1; + s_state.close_button_state = 1; else if (ImGui::IsKeyPressed(ImGuiKey_NavGamepadCancel, false)) - s_close_button_state = 2; + s_state.close_button_state = 2; } - else if ((s_close_button_state == 1 && ImGui::IsKeyReleased(ImGuiKey_Escape)) || - (s_close_button_state == 2 && ImGui::IsKeyReleased(ImGuiKey_NavGamepadCancel))) + else if ((s_state.close_button_state == 1 && ImGui::IsKeyReleased(ImGuiKey_Escape)) || + (s_state.close_button_state == 2 && ImGui::IsKeyReleased(ImGuiKey_NavGamepadCancel))) { - s_close_button_state = 3; + s_state.close_button_state = 3; } - return s_close_button_state > 1; + return s_state.close_button_state > 1; } void ImGuiFullscreen::ResetCloseMenuIfNeeded() { // If s_close_button_state reached the "Released" state, reset it after the tick - if (s_close_button_state > 1) + if (s_state.close_button_state > 1) { - s_close_button_state = 0; + s_state.close_button_state = 0; } } void ImGuiFullscreen::PushPrimaryColor() { - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_Button, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, UIPrimaryColor); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, UIPrimaryLightColor); - ImGui::PushStyleColor(ImGuiCol_Border, UIPrimaryLightColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_Button, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, UIStyle.PrimaryColor); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, UIStyle.PrimaryLightColor); + ImGui::PushStyleColor(ImGuiCol_Border, UIStyle.PrimaryLightColor); } void ImGuiFullscreen::PopPrimaryColor() @@ -723,7 +701,7 @@ void ImGuiFullscreen::PopPrimaryColor() bool ImGuiFullscreen::BeginFullscreenColumns(const char* title, float pos_y, bool expand_to_screen_width, bool footer) { - ImGui::SetNextWindowPos(ImVec2(expand_to_screen_width ? 0.0f : g_layout_padding_left, pos_y)); + ImGui::SetNextWindowPos(ImVec2(expand_to_screen_width ? 0.0f : UIStyle.LayoutPaddingLeft, pos_y)); ImGui::SetNextWindowSize( ImVec2(expand_to_screen_width ? ImGui::GetIO().DisplaySize.x : LayoutScale(LAYOUT_SCREEN_WIDTH), ImGui::GetIO().DisplaySize.y - pos_y - (footer ? LayoutScale(LAYOUT_FOOTER_HEIGHT) : 0.0f))); @@ -735,7 +713,7 @@ bool ImGuiFullscreen::BeginFullscreenColumns(const char* title, float pos_y, boo bool clipped; if (title) { - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); clipped = ImGui::Begin(title, nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize); ImGui::PopFont(); } @@ -790,7 +768,7 @@ bool ImGuiFullscreen::BeginFullscreenWindow(float left, float top, float width, if (top < 0.0f) top = (LAYOUT_SCREEN_HEIGHT - height) * -top; - const ImVec2 pos(ImVec2(LayoutScale(left) + g_layout_padding_left, LayoutScale(top) + g_layout_padding_top)); + const ImVec2 pos(ImVec2(LayoutScale(left) + UIStyle.LayoutPaddingLeft, LayoutScale(top) + UIStyle.LayoutPaddingTop)); const ImVec2 size(LayoutScale(ImVec2(width, height))); return BeginFullscreenWindow(pos, size, name, background, rounding, padding, flags); } @@ -807,7 +785,7 @@ bool ImGuiFullscreen::BeginFullscreenWindow(const ImVec2& position, const ImVec2 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(padding)); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(rounding)); - ImGui::PushStyleVar(ImGuiStyleVar_ScrollSmooth, s_smooth_scrolling ? SMOOTH_SCROLLING_SPEED : 1.0f); + ImGui::PushStyleVar(ImGuiStyleVar_ScrollSmooth, s_state.smooth_scrolling ? SMOOTH_SCROLLING_SPEED : 1.0f); return ImGui::Begin(name, nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | @@ -843,20 +821,20 @@ void ImGuiFullscreen::CreateFooterTextString(SmallStringBase& dest, void ImGuiFullscreen::SetFullscreenFooterText(std::string_view text) { - s_fullscreen_footer_text.assign(text); + s_state.fullscreen_footer_text.assign(text); } void ImGuiFullscreen::SetFullscreenFooterText(std::span> items) { - CreateFooterTextString(s_fullscreen_footer_text, items); + CreateFooterTextString(s_state.fullscreen_footer_text, items); } void ImGuiFullscreen::DrawFullscreenFooter() { const ImGuiIO& io = ImGui::GetIO(); - if (s_fullscreen_footer_text.empty()) + if (s_state.fullscreen_footer_text.empty()) { - s_last_fullscreen_footer_text.clear(); + s_state.last_fullscreen_footer_text.clear(); return; } @@ -864,60 +842,63 @@ void ImGuiFullscreen::DrawFullscreenFooter() const float height = LayoutScale(LAYOUT_FOOTER_HEIGHT); ImDrawList* dl = ImGui::GetForegroundDrawList(); - dl->AddRectFilled(ImVec2(0.0f, io.DisplaySize.y - height), io.DisplaySize, ImGui::GetColorU32(UIPrimaryColor), 0.0f); + dl->AddRectFilled(ImVec2(0.0f, io.DisplaySize.y - height), io.DisplaySize, ImGui::GetColorU32(UIStyle.PrimaryColor), + 0.0f); - ImFont* const font = g_medium_font; + ImFont* const font = UIStyle.MediumFont; const float max_width = io.DisplaySize.x - padding * 2.0f; float prev_opacity = 0.0f; - if (!s_last_fullscreen_footer_text.empty() && s_fullscreen_footer_text != s_last_fullscreen_footer_text) + if (!s_state.last_fullscreen_footer_text.empty() && + s_state.fullscreen_footer_text != s_state.last_fullscreen_footer_text) { - if (s_fullscreen_text_change_time == 0.0f) - s_fullscreen_text_change_time = 0.15f; + if (s_state.fullscreen_text_change_time == 0.0f) + s_state.fullscreen_text_change_time = 0.15f; else - s_fullscreen_text_change_time = std::max(s_fullscreen_text_change_time - io.DeltaTime, 0.0f); + s_state.fullscreen_text_change_time = std::max(s_state.fullscreen_text_change_time - io.DeltaTime, 0.0f); - if (s_fullscreen_text_change_time == 0.0f) - s_last_fullscreen_footer_text = s_fullscreen_footer_text; + if (s_state.fullscreen_text_change_time == 0.0f) + s_state.last_fullscreen_footer_text = s_state.fullscreen_footer_text; - prev_opacity = s_fullscreen_text_change_time * (1.0f / 0.15f); + prev_opacity = s_state.fullscreen_text_change_time * (1.0f / 0.15f); if (prev_opacity > 0.0f) { const ImVec2 text_size = - font->CalcTextSizeA(font->FontSize, 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), - 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()); + font->CalcTextSizeA(font->FontSize, max_width, 0.0f, s_state.last_fullscreen_footer_text.c_str(), + s_state.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), + ImGui::GetColorU32(ImVec4(UIStyle.PrimaryTextColor.x, UIStyle.PrimaryTextColor.y, + UIStyle.PrimaryTextColor.z, prev_opacity)), + s_state.last_fullscreen_footer_text.c_str(), s_state.last_fullscreen_footer_text.end_ptr()); } } - else if (s_last_fullscreen_footer_text.empty()) + else if (s_state.last_fullscreen_footer_text.empty()) { - s_last_fullscreen_footer_text = s_fullscreen_footer_text; + s_state.last_fullscreen_footer_text = s_state.fullscreen_footer_text; } if (prev_opacity < 1.0f) { - const ImVec2 text_size = font->CalcTextSizeA(font->FontSize, 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), - 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()); + const ImVec2 text_size = + font->CalcTextSizeA(font->FontSize, max_width, 0.0f, s_state.fullscreen_footer_text.c_str(), + s_state.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), + ImGui::GetColorU32(ImVec4(UIStyle.PrimaryTextColor.x, UIStyle.PrimaryTextColor.y, + UIStyle.PrimaryTextColor.z, 1.0f - prev_opacity)), + s_state.fullscreen_footer_text.c_str(), s_state.fullscreen_footer_text.end_ptr()); } } void ImGuiFullscreen::PrerenderMenuButtonBorder() { - if (!s_had_hovered_menu_item) + if (!s_state.had_hovered_menu_item) return; // updating might finish the animation - const ImVec2& min = s_menu_button_frame_min_animated.UpdateAndGetValue(); - const ImVec2& max = s_menu_button_frame_max_animated.UpdateAndGetValue(); + const ImVec2& min = s_state.menu_button_frame_min_animated.UpdateAndGetValue(); + const ImVec2& max = s_state.menu_button_frame_max_animated.UpdateAndGetValue(); const ImU32 col = ImGui::GetColorU32(ImGuiCol_ButtonHovered); const float t = static_cast(std::min(std::abs(std::sin(ImGui::GetTime() * 0.75) * 1.1), 1.0)); @@ -927,25 +908,25 @@ void ImGuiFullscreen::PrerenderMenuButtonBorder() ImGui::PopStyleColor(); - s_rendered_menu_item_border = true; + s_state.rendered_menu_item_border = true; } void ImGuiFullscreen::BeginMenuButtons(u32 num_items, float y_align, float x_padding, float y_padding, float item_height) { - s_menu_button_index = 0; + s_state.menu_button_index = 0; // If we're scrolling up and down, it's possible that the first menu item won't be enabled. // If so, track when the scroll happens, and if we moved to a new ID. If not, scroll the parent window. if (GImGui->NavMoveDir != ImGuiDir_None) { - s_has_pending_nav_move = GImGui->NavMoveDir; + s_state.has_pending_nav_move = GImGui->NavMoveDir; } - else if (s_has_pending_nav_move != ImGuiDir_None) + else if (s_state.has_pending_nav_move != ImGuiDir_None) { if (GImGui->NavJustMovedToId == 0) { - switch (s_has_pending_nav_move) + switch (s_state.has_pending_nav_move) { case ImGuiDir_Up: ImGui::SetScrollY(std::max(ImGui::GetScrollY() - item_height, 0.0f)); @@ -958,7 +939,7 @@ void ImGuiFullscreen::BeginMenuButtons(u32 num_items, float y_align, float x_pad } } - s_has_pending_nav_move = ImGuiDir_None; + s_state.has_pending_nav_move = ImGuiDir_None; } ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(x_padding, y_padding)); @@ -988,18 +969,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); + UIStyle.LargeFont->FontSize + 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(UIStyle.LargeFont); 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 + UIStyle.LargeFont->FontSize + 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(); @@ -1088,37 +1069,37 @@ void ImGuiFullscreen::DrawMenuButtonFrame(const ImVec2& p_min, const ImVec2& p_m ImVec2 frame_max = p_max; const ImGuiIO& io = ImGui::GetIO(); - if (s_smooth_scrolling && io.NavVisible) + if (s_state.smooth_scrolling && io.NavVisible) { - if (!s_had_hovered_menu_item || io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f) + if (!s_state.had_hovered_menu_item || io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f) { - s_menu_button_frame_min_animated.Reset(frame_min); - s_menu_button_frame_max_animated.Reset(frame_max); - s_has_hovered_menu_item = true; + s_state.menu_button_frame_min_animated.Reset(frame_min); + s_state.menu_button_frame_max_animated.Reset(frame_max); + s_state.has_hovered_menu_item = true; } else { - if (frame_min.x != s_menu_button_frame_min_animated.GetEndValue().x || - frame_min.y != s_menu_button_frame_min_animated.GetEndValue().y) + if (frame_min.x != s_state.menu_button_frame_min_animated.GetEndValue().x || + frame_min.y != s_state.menu_button_frame_min_animated.GetEndValue().y) { - s_menu_button_frame_min_animated.Start(s_menu_button_frame_min_animated.GetCurrentValue(), frame_min, - MENU_BACKGROUND_ANIMATION_TIME); + s_state.menu_button_frame_min_animated.Start(s_state.menu_button_frame_min_animated.GetCurrentValue(), + frame_min, MENU_BACKGROUND_ANIMATION_TIME); } - if (frame_max.x != s_menu_button_frame_max_animated.GetEndValue().x || - frame_max.y != s_menu_button_frame_max_animated.GetEndValue().y) + if (frame_max.x != s_state.menu_button_frame_max_animated.GetEndValue().x || + frame_max.y != s_state.menu_button_frame_max_animated.GetEndValue().y) { - s_menu_button_frame_max_animated.Start(s_menu_button_frame_max_animated.GetCurrentValue(), frame_max, - MENU_BACKGROUND_ANIMATION_TIME); + s_state.menu_button_frame_max_animated.Start(s_state.menu_button_frame_max_animated.GetCurrentValue(), + frame_max, MENU_BACKGROUND_ANIMATION_TIME); } - frame_min = s_menu_button_frame_min_animated.UpdateAndGetValue(); - frame_max = s_menu_button_frame_max_animated.UpdateAndGetValue(); - s_has_hovered_menu_item = true; + frame_min = s_state.menu_button_frame_min_animated.UpdateAndGetValue(); + frame_max = s_state.menu_button_frame_max_animated.UpdateAndGetValue(); + s_state.has_hovered_menu_item = true; } } - if (!s_rendered_menu_item_border) + if (!s_state.rendered_menu_item_border) { - s_rendered_menu_item_border = true; + s_state.rendered_menu_item_border = true; ImGui::RenderFrame(frame_min, frame_max, fill_col, border, rounding); } } @@ -1136,8 +1117,8 @@ bool ImGuiFullscreen::MenuButtonFrame(const char* str_id, bool enabled, float he void ImGuiFullscreen::ResetMenuButtonFrame() { - s_had_hovered_menu_item = false; - s_has_hovered_menu_item = false; + s_state.had_hovered_menu_item = false; + s_state.has_hovered_menu_item = false; } void ImGuiFullscreen::MenuHeading(const char* title, bool draw_line /*= true*/) @@ -1152,14 +1133,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(UIStyle.LargeFont); 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 + UIStyle.LargeFont->FontSize + 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); @@ -1180,13 +1161,13 @@ bool ImGuiFullscreen::MenuHeadingButton(const char* title, const char* value /*= if (!enabled) ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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::max(), 0.0f, value)); + UIStyle.LargeFont->CalcTextSizeA(UIStyle.LargeFont->FontSize, std::numeric_limits::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); } @@ -1197,7 +1178,7 @@ bool ImGuiFullscreen::MenuHeadingButton(const char* title, const char* value /*= 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 + UIStyle.LargeFont->FontSize + 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); @@ -1230,7 +1211,8 @@ bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* r const ImVec2 border_size_v = ImVec2(border_size, border_size); ImVec2 pos, size; GetMenuButtonFrameBounds(height, &pos, &size); - ImGui::RenderFrame(pos + border_size_v, pos + size - border_size_v, ImGui::GetColorU32(UIPrimaryColor), false); + ImGui::RenderFrame(pos + border_size_v, pos + size - border_size_v, ImGui::GetColorU32(UIStyle.PrimaryColor), + false); } ImRect bb; @@ -1260,7 +1242,7 @@ bool ImGuiFullscreen::ActiveButtonWithRightText(const char* title, const char* r if (!enabled) ImGui::PopStyleColor(); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } @@ -1295,7 +1277,7 @@ bool ImGuiFullscreen::MenuButton(const char* title, const char* summary, bool en if (!enabled) ImGui::PopStyleColor(); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } @@ -1322,7 +1304,7 @@ bool ImGuiFullscreen::MenuButtonWithoutSummary(const char* title, bool enabled, if (!enabled) ImGui::PopStyleColor(); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } @@ -1363,7 +1345,7 @@ bool ImGuiFullscreen::MenuImageButton(const char* title, const char* summary, Im if (!enabled) ImGui::PopStyleColor(); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } @@ -1511,12 +1493,12 @@ bool ImGuiFullscreen::ToggleButton(const char* title, const char* summary, bool* ImU32 col_knob; if (!enabled) { - col_bg = ImGui::GetColorU32(UIDisabledColor); + col_bg = ImGui::GetColorU32(UIStyle.DisabledColor); col_knob = IM_COL32(200, 200, 200, 200); } else { - col_bg = ImGui::GetColorU32(ImLerp(HEX_TO_IMVEC4(0x8C8C8C, 0xff), UISecondaryStrongColor, t)); + col_bg = ImGui::GetColorU32(ImLerp(HEX_TO_IMVEC4(0x8C8C8C, 0xff), UIStyle.SecondaryStrongColor, t)); col_knob = IM_COL32(255, 255, 255, 255); } @@ -1526,7 +1508,7 @@ bool ImGuiFullscreen::ToggleButton(const char* title, const char* summary, bool* ImVec2(toggle_pos.x + toggle_radius + t * (toggle_width - toggle_radius * 2.0f), toggle_pos.y + toggle_radius), toggle_radius - 1.5f, col_knob, 32); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } @@ -1595,10 +1577,10 @@ bool ImGuiFullscreen::ThreeWayToggleButton(const char* title, const char* summar col_bg = IM_COL32(0x75, 0x75, 0x75, 0xff); else if (hovered) col_bg = ImGui::GetColorU32(ImLerp(v->has_value() ? HEX_TO_IMVEC4(0xf05100, 0xff) : HEX_TO_IMVEC4(0x9e9e9e, 0xff), - UISecondaryStrongColor, color_t)); + UIStyle.SecondaryStrongColor, color_t)); else col_bg = ImGui::GetColorU32(ImLerp(v->has_value() ? HEX_TO_IMVEC4(0xc45100, 0xff) : HEX_TO_IMVEC4(0x757575, 0xff), - UISecondaryStrongColor, color_t)); + UIStyle.SecondaryStrongColor, color_t)); dl->AddRectFilled(toggle_pos, ImVec2(toggle_pos.x + toggle_width, toggle_pos.y + toggle_height), col_bg, toggle_height * 0.5f); @@ -1606,7 +1588,7 @@ bool ImGuiFullscreen::ThreeWayToggleButton(const char* title, const char* summar ImVec2(toggle_pos.x + toggle_radius + t * (toggle_width - toggle_radius * 2.0f), toggle_pos.y + toggle_radius), toggle_radius - 1.5f, IM_COL32(255, 255, 255, 255), 32); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } @@ -1657,7 +1639,7 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, s32* v ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -1675,7 +1657,8 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, s32* v changed = ImGui::SliderInt("##value", value, min, max, format, ImGuiSliderFlags_NoInput); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - if (MenuButtonWithoutSummary(ok_text, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, ImVec2(0.5f, 0.0f))) + if (MenuButtonWithoutSummary(ok_text, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, + ImVec2(0.5f, 0.0f))) ImGui::CloseCurrentPopup(); EndMenuButtons(); @@ -1735,7 +1718,7 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, float* ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING)); @@ -1752,7 +1735,8 @@ bool ImGuiFullscreen::RangeButton(const char* title, const char* summary, float* changed = ImGui::SliderFloat("##value", value, min, max, format, ImGuiSliderFlags_NoInput); - if (MenuButtonWithoutSummary(ok_text, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, g_large_font, ImVec2(0.5f, 0.0f))) + if (MenuButtonWithoutSummary(ok_text, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, UIStyle.LargeFont, + ImVec2(0.5f, 0.0f))) ImGui::CloseCurrentPopup(); EndMenuButtons(); @@ -1813,9 +1797,9 @@ bool ImGuiFullscreen::EnumChoiceButtonImpl(const char* title, const char* summar if (pressed) { - s_enum_choice_button_id = ImGui::GetID(title); - s_enum_choice_button_value = *value_pointer; - s_enum_choice_button_set = false; + s_state.enum_choice_button_id = ImGui::GetID(title); + s_state.enum_choice_button_value = *value_pointer; + s_state.enum_choice_button_set = false; ChoiceDialogOptions options; options.reserve(count); @@ -1824,23 +1808,23 @@ bool ImGuiFullscreen::EnumChoiceButtonImpl(const char* title, const char* summar static_cast(*value_pointer) == i); OpenChoiceDialog(title, false, std::move(options), [](s32 index, const std::string& title, bool checked) { if (index >= 0) - s_enum_choice_button_value = index; + s_state.enum_choice_button_value = index; - s_enum_choice_button_set = true; + s_state.enum_choice_button_set = true; CloseChoiceDialog(); }); } bool changed = false; - if (s_enum_choice_button_set && s_enum_choice_button_id == ImGui::GetID(title)) + if (s_state.enum_choice_button_set && s_state.enum_choice_button_id == ImGui::GetID(title)) { - changed = s_enum_choice_button_value != *value_pointer; + changed = s_state.enum_choice_button_value != *value_pointer; if (changed) - *value_pointer = s_enum_choice_button_value; + *value_pointer = s_state.enum_choice_button_value; - s_enum_choice_button_id = 0; - s_enum_choice_button_value = 0; - s_enum_choice_button_set = false; + s_state.enum_choice_button_id = 0; + s_state.enum_choice_button_value = 0; + s_state.enum_choice_button_set = false; } return changed; @@ -1850,14 +1834,14 @@ void ImGuiFullscreen::DrawShadowedText(ImDrawList* dl, ImFont* font, const ImVec const char* text_end /*= nullptr*/, float wrap_width /*= 0.0f*/) { dl->AddText(font, font->FontSize, pos + LayoutScale(1.0f, 1.0f), - s_light_theme ? IM_COL32(255, 255, 255, 100) : IM_COL32(0, 0, 0, 100), text, text_end, wrap_width); + s_state.light_theme ? IM_COL32(255, 255, 255, 100) : IM_COL32(0, 0, 0, 100), text, text_end, wrap_width); dl->AddText(font, font->FontSize, pos, col, text, text_end, wrap_width); } void ImGuiFullscreen::BeginNavBar(float x_padding /*= LAYOUT_MENU_BUTTON_X_PADDING*/, float y_padding /*= LAYOUT_MENU_BUTTON_Y_PADDING*/) { - s_menu_button_index = 0; + s_state.menu_button_index = 0; ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, LayoutScale(x_padding, y_padding)); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f); @@ -1879,7 +1863,7 @@ void ImGuiFullscreen::NavTitle(const char* title, float height /*= LAYOUT_MENU_B if (window->SkipItems) return; - s_menu_button_index++; + s_state.menu_button_index++; const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits::max(), 0.0f, title)); const ImVec2 pos(window->DC.CursorPos); @@ -1923,7 +1907,7 @@ bool ImGuiFullscreen::NavButton(const char* title, bool is_active, bool enabled if (window->SkipItems) return false; - s_menu_button_index++; + s_state.menu_button_index++; const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits::max(), 0.0f, title)); const ImVec2 pos(window->DC.CursorPos); @@ -1992,7 +1976,7 @@ bool ImGuiFullscreen::NavTab(const char* title, bool is_active, bool enabled /* if (window->SkipItems) return false; - s_menu_button_index++; + s_state.menu_button_index++; const ImVec2 text_size(font->CalcTextSizeA(font->FontSize, std::numeric_limits::max(), 0.0f, title)); const ImVec2 pos(window->DC.CursorPos); @@ -2066,7 +2050,7 @@ bool ImGuiFullscreen::NavTab(const char* title, bool is_active, bool enabled /* bool ImGuiFullscreen::BeginHorizontalMenu(const char* name, const ImVec2& position, const ImVec2& size, u32 num_items) { - s_menu_button_index = 0; + s_state.menu_button_index = 0; const float item_padding = LayoutScale(LAYOUT_HORIZONTAL_MENU_PADDING); const float item_width = LayoutScale(LAYOUT_HORIZONTAL_MENU_ITEM_WIDTH); @@ -2079,7 +2063,7 @@ bool ImGuiFullscreen::BeginHorizontalMenu(const char* name, const ImVec2& positi ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, LayoutScale(1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(item_spacing, 0.0f)); - if (!BeginFullscreenWindow(position, size, name, UIBackgroundColor, 0.0f, ImVec2())) + if (!BeginFullscreenWindow(position, size, name, UIStyle.BackgroundColor, 0.0f, ImVec2())) return false; ImGui::SetCursorPos(ImVec2((size.x - menu_width) * 0.5f, (size.y - menu_height) * 0.5f)); @@ -2135,7 +2119,7 @@ bool ImGuiFullscreen::HorizontalMenuItem(GPUTexture* icon, const char* title, co ImDrawList* dl = ImGui::GetWindowDrawList(); dl->AddImage(reinterpret_cast(icon), icon_pos, icon_pos + ImVec2(icon_size, icon_size)); - ImFont* title_font = g_large_font; + ImFont* title_font = UIStyle.LargeFont; const ImVec2 title_size = title_font->CalcTextSizeA(title_font->FontSize, std::numeric_limits::max(), avail_width, title); const ImVec2 title_pos = @@ -2145,7 +2129,7 @@ bool ImGuiFullscreen::HorizontalMenuItem(GPUTexture* icon, const char* title, co dl->AddText(title_font, title_font->FontSize, title_pos, ImGui::GetColorU32(ImGuiCol_Text), title, nullptr, 0.0f, &title_bb); - ImFont* desc_font = g_medium_font; + ImFont* desc_font = UIStyle.MediumFont; const ImVec2 desc_size = desc_font->CalcTextSizeA(desc_font->FontSize, std::numeric_limits::max(), avail_width, description); const ImVec2 desc_pos = ImVec2(bb.Min.x + (avail_width - desc_size.x) * 0.5f, title_bb.w + LayoutScale(10.0f)); @@ -2156,48 +2140,49 @@ bool ImGuiFullscreen::HorizontalMenuItem(GPUTexture* icon, const char* title, co ImGui::SameLine(); - s_menu_button_index++; + s_state.menu_button_index++; return pressed; } void ImGuiFullscreen::PopulateFileSelectorItems() { - s_file_selector_items.clear(); + s_state.file_selector_items.clear(); - if (s_file_selector_current_directory.empty()) + if (s_state.file_selector_current_directory.empty()) { for (std::string& root_path : FileSystem::GetRootDirectoryList()) - s_file_selector_items.emplace_back(fmt::format(ICON_FA_FOLDER " {}", root_path), std::move(root_path), false); + s_state.file_selector_items.emplace_back(fmt::format(ICON_FA_FOLDER " {}", root_path), std::move(root_path), + false); } else { FileSystem::FindResultsArray results; - FileSystem::FindFiles(s_file_selector_current_directory.c_str(), "*", + FileSystem::FindFiles(s_state.file_selector_current_directory.c_str(), "*", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_FOLDERS | FILESYSTEM_FIND_HIDDEN_FILES | FILESYSTEM_FIND_RELATIVE_PATHS | FILESYSTEM_FIND_SORT_BY_NAME, &results); std::string parent_path; - std::string::size_type sep_pos = s_file_selector_current_directory.rfind(FS_OSPATH_SEPARATOR_CHARACTER); + std::string::size_type sep_pos = s_state.file_selector_current_directory.rfind(FS_OSPATH_SEPARATOR_CHARACTER); if (sep_pos != std::string::npos) - parent_path = Path::Canonicalize(s_file_selector_current_directory.substr(0, sep_pos)); + parent_path = Path::Canonicalize(s_state.file_selector_current_directory.substr(0, sep_pos)); - s_file_selector_items.emplace_back(ICON_FA_FOLDER_OPEN " ", std::move(parent_path), false); + s_state.file_selector_items.emplace_back(ICON_FA_FOLDER_OPEN " ", std::move(parent_path), false); for (const FILESYSTEM_FIND_DATA& fd : results) { std::string full_path = - fmt::format("{}" FS_OSPATH_SEPARATOR_STR "{}", s_file_selector_current_directory, fd.FileName); + fmt::format("{}" FS_OSPATH_SEPARATOR_STR "{}", s_state.file_selector_current_directory, fd.FileName); if (fd.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY) { std::string title = fmt::format(ICON_FA_FOLDER " {}", fd.FileName); - s_file_selector_items.emplace_back(std::move(title), std::move(full_path), false); + s_state.file_selector_items.emplace_back(std::move(title), std::move(full_path), false); } else { - if (s_file_selector_filters.empty() || - std::none_of(s_file_selector_filters.begin(), s_file_selector_filters.end(), + if (s_state.file_selector_filters.empty() || + std::none_of(s_state.file_selector_filters.begin(), s_state.file_selector_filters.end(), [&fd](const std::string& filter) { return StringUtil::WildcardMatch(fd.FileName.c_str(), filter.c_str(), false); })) @@ -2206,7 +2191,7 @@ void ImGuiFullscreen::PopulateFileSelectorItems() } std::string title = fmt::format(ICON_FA_FILE " {}", fd.FileName); - s_file_selector_items.emplace_back(std::move(title), std::move(full_path), true); + s_state.file_selector_items.emplace_back(std::move(title), std::move(full_path), true); } } } @@ -2217,13 +2202,13 @@ void ImGuiFullscreen::SetFileSelectorDirectory(std::string dir) while (!dir.empty() && dir.back() == FS_OSPATH_SEPARATOR_CHARACTER) dir.erase(dir.size() - 1); - s_file_selector_current_directory = std::move(dir); + s_state.file_selector_current_directory = std::move(dir); PopulateFileSelectorItems(); } bool ImGuiFullscreen::IsFileSelectorOpen() { - return s_file_selector_open; + return s_state.file_selector_open; } void ImGuiFullscreen::OpenFileSelector(std::string_view title, bool select_directory, FileSelectorCallback callback, @@ -2239,14 +2224,14 @@ void ImGuiFullscreen::OpenFileSelector(std::string_view title, bool select_direc return; } - if (s_file_selector_open) + if (s_state.file_selector_open) CloseFileSelector(); - s_file_selector_open = true; - s_file_selector_directory = select_directory; - s_file_selector_title = fmt::format("{}##file_selector", title); - s_file_selector_callback = std::move(callback); - s_file_selector_filters = std::move(filters); + s_state.file_selector_open = true; + s_state.file_selector_directory = select_directory; + s_state.file_selector_title = fmt::format("{}##file_selector", title); + s_state.file_selector_callback = std::move(callback); + s_state.file_selector_filters = std::move(filters); SetFileSelectorDirectory(std::move(initial_directory)); QueueResetFocus(FocusResetType::PopupOpened); @@ -2254,67 +2239,67 @@ void ImGuiFullscreen::OpenFileSelector(std::string_view title, bool select_direc void ImGuiFullscreen::CloseFileSelector() { - if (!s_file_selector_open) + if (!s_state.file_selector_open) return; - if (ImGui::IsPopupOpen(s_file_selector_title.c_str(), 0)) + if (ImGui::IsPopupOpen(s_state.file_selector_title.c_str(), 0)) ImGui::ClosePopupToLevel(GImGui->OpenPopupStack.Size - 1, true); - s_file_selector_open = false; - s_file_selector_directory = false; - std::string().swap(s_file_selector_title); - FileSelectorCallback().swap(s_file_selector_callback); - FileSelectorFilters().swap(s_file_selector_filters); - std::string().swap(s_file_selector_current_directory); - s_file_selector_items.clear(); + s_state.file_selector_open = false; + s_state.file_selector_directory = false; + std::string().swap(s_state.file_selector_title); + FileSelectorCallback().swap(s_state.file_selector_callback); + FileSelectorFilters().swap(s_state.file_selector_filters); + std::string().swap(s_state.file_selector_current_directory); + s_state.file_selector_items.clear(); ImGui::CloseCurrentPopup(); QueueResetFocus(FocusResetType::PopupClosed); } void ImGuiFullscreen::DrawFileSelector() { - if (!s_file_selector_open) + if (!s_state.file_selector_open) return; ImGui::SetNextWindowSize(LayoutScale(1000.0f, 650.0f)); ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::OpenPopup(s_file_selector_title.c_str()); + ImGui::OpenPopup(s_state.file_selector_title.c_str()); FileSelectorItem* selected = nullptr; - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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); - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIPrimaryColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); bool is_open = !WantsToCloseMenu(); bool directory_selected = false; - if (ImGui::BeginPopupModal(s_file_selector_title.c_str(), &is_open, + if (ImGui::BeginPopupModal(s_state.file_selector_title.c_str(), &is_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { - ImGui::PushStyleColor(ImGuiCol_Text, UIBackgroundTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); ResetFocusHere(); BeginMenuButtons(); - if (!s_file_selector_current_directory.empty()) + if (!s_state.file_selector_current_directory.empty()) { - MenuButton(SmallString::from_format(ICON_FA_FOLDER_OPEN " {}", s_file_selector_current_directory).c_str(), + MenuButton(SmallString::from_format(ICON_FA_FOLDER_OPEN " {}", s_state.file_selector_current_directory).c_str(), nullptr, false, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); } - if (s_file_selector_directory && !s_file_selector_current_directory.empty()) + if (s_state.file_selector_directory && !s_state.file_selector_current_directory.empty()) { if (MenuButton(ICON_FA_FOLDER_PLUS " ", nullptr, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) directory_selected = true; } - for (FileSelectorItem& item : s_file_selector_items) + for (FileSelectorItem& item : s_state.file_selector_items) { if (MenuButton(item.display_name.c_str(), nullptr, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) selected = &item; @@ -2336,13 +2321,13 @@ void ImGuiFullscreen::DrawFileSelector() ImGui::PopFont(); if (is_open) - GetFileSelectorHelpText(s_fullscreen_footer_text); + GetFileSelectorHelpText(s_state.fullscreen_footer_text); if (selected) { if (selected->is_file) { - s_file_selector_callback(selected->full_path); + s_state.file_selector_callback(selected->full_path); } else { @@ -2352,22 +2337,22 @@ void ImGuiFullscreen::DrawFileSelector() } else if (directory_selected) { - s_file_selector_callback(s_file_selector_current_directory); + s_state.file_selector_callback(s_state.file_selector_current_directory); } else if (!is_open) { std::string no_path; - s_file_selector_callback(no_path); + s_state.file_selector_callback(no_path); CloseFileSelector(); } else { if (ImGui::IsKeyPressed(ImGuiKey_Backspace, false) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadMenu, false)) { - if (!s_file_selector_items.empty() && s_file_selector_items.front().display_name == ICON_FA_FOLDER_OPEN - " ") + if (!s_state.file_selector_items.empty() && + s_state.file_selector_items.front().display_name == ICON_FA_FOLDER_OPEN " ") { - SetFileSelectorDirectory(std::move(s_file_selector_items.front().full_path)); + SetFileSelectorDirectory(std::move(s_state.file_selector_items.front().full_path)); QueueResetFocus(FocusResetType::Other); } } @@ -2376,81 +2361,81 @@ void ImGuiFullscreen::DrawFileSelector() bool ImGuiFullscreen::IsChoiceDialogOpen() { - return s_choice_dialog_open; + return s_state.choice_dialog_open; } void ImGuiFullscreen::OpenChoiceDialog(std::string_view title, bool checkable, ChoiceDialogOptions options, ChoiceDialogCallback callback) { - if (s_choice_dialog_open) + if (s_state.choice_dialog_open) CloseChoiceDialog(); - s_choice_dialog_open = true; - s_choice_dialog_checkable = checkable; - s_choice_dialog_title = fmt::format("{}##choice_dialog", title); - s_choice_dialog_options = std::move(options); - s_choice_dialog_callback = std::move(callback); + s_state.choice_dialog_open = true; + s_state.choice_dialog_checkable = checkable; + s_state.choice_dialog_title = fmt::format("{}##choice_dialog", title); + s_state.choice_dialog_options = std::move(options); + s_state.choice_dialog_callback = std::move(callback); QueueResetFocus(FocusResetType::PopupOpened); } void ImGuiFullscreen::CloseChoiceDialog() { - if (!s_choice_dialog_open) + if (!s_state.choice_dialog_open) return; - if (ImGui::IsPopupOpen(s_choice_dialog_title.c_str(), 0)) + if (ImGui::IsPopupOpen(s_state.choice_dialog_title.c_str(), 0)) ImGui::ClosePopupToLevel(GImGui->OpenPopupStack.Size - 1, true); - s_choice_dialog_open = false; - s_choice_dialog_checkable = false; - std::string().swap(s_choice_dialog_title); - ChoiceDialogOptions().swap(s_choice_dialog_options); - ChoiceDialogCallback().swap(s_choice_dialog_callback); + s_state.choice_dialog_open = false; + s_state.choice_dialog_checkable = false; + std::string().swap(s_state.choice_dialog_title); + ChoiceDialogOptions().swap(s_state.choice_dialog_options); + ChoiceDialogCallback().swap(s_state.choice_dialog_callback); QueueResetFocus(FocusResetType::PopupClosed); } void ImGuiFullscreen::DrawChoiceDialog() { - if (!s_choice_dialog_open) + if (!s_state.choice_dialog_open) return; - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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); - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIPrimaryColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); 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; + UIStyle.LargeFont->FontSize + 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(s_choice_dialog_options.size())); + static_cast(s_state.choice_dialog_options.size())); ImGui::SetNextWindowSize(ImVec2(width, height)); ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::OpenPopup(s_choice_dialog_title.c_str()); + ImGui::OpenPopup(s_state.choice_dialog_title.c_str()); bool is_open = true; s32 choice = -1; - if (ImGui::BeginPopupModal(s_choice_dialog_title.c_str(), &is_open, + if (ImGui::BeginPopupModal(s_state.choice_dialog_title.c_str(), &is_open, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { - ImGui::PushStyleColor(ImGuiCol_Text, UIBackgroundTextColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.BackgroundTextColor); ResetFocusHere(); BeginMenuButtons(); - if (s_choice_dialog_checkable) + if (s_state.choice_dialog_checkable) { - for (s32 i = 0; i < static_cast(s_choice_dialog_options.size()); i++) + for (s32 i = 0; i < static_cast(s_state.choice_dialog_options.size()); i++) { - auto& option = s_choice_dialog_options[i]; + auto& option = s_state.choice_dialog_options[i]; const SmallString title = SmallString::from_format("{0} {1}", option.second ? ICON_FA_CHECK_SQUARE : ICON_FA_SQUARE, option.first); @@ -2463,15 +2448,15 @@ void ImGuiFullscreen::DrawChoiceDialog() } else { - for (s32 i = 0; i < static_cast(s_choice_dialog_options.size()); i++) + for (s32 i = 0; i < static_cast(s_state.choice_dialog_options.size()); i++) { - auto& option = s_choice_dialog_options[i]; + auto& option = s_state.choice_dialog_options[i]; if (ActiveButtonWithRightText(option.first.c_str(), option.second ? ICON_FA_CHECK : nullptr, option.second, true, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) { choice = i; - for (s32 j = 0; j < static_cast(s_choice_dialog_options.size()); j++) - s_choice_dialog_options[j].second = (j == i); + for (s32 j = 0; j < static_cast(s_state.choice_dialog_options.size()); j++) + s_state.choice_dialog_options[j].second = (j == i); } } } @@ -2491,90 +2476,90 @@ void ImGuiFullscreen::DrawChoiceDialog() if (choice >= 0) { - const auto& option = s_choice_dialog_options[choice]; - s_choice_dialog_callback(choice, option.first, option.second); + const auto& option = s_state.choice_dialog_options[choice]; + s_state.choice_dialog_callback(choice, option.first, option.second); } else if (!is_open) { std::string no_string; - s_choice_dialog_callback(-1, no_string, false); + s_state.choice_dialog_callback(-1, no_string, false); CloseChoiceDialog(); } else { - GetChoiceDialogHelpText(s_fullscreen_footer_text); + GetChoiceDialogHelpText(s_state.fullscreen_footer_text); } } bool ImGuiFullscreen::IsInputDialogOpen() { - return s_input_dialog_open; + return s_state.input_dialog_open; } void ImGuiFullscreen::OpenInputStringDialog(std::string title, std::string message, std::string caption, std::string ok_button_text, InputStringDialogCallback callback) { - s_input_dialog_open = true; - s_input_dialog_title = std::move(title); - s_input_dialog_message = std::move(message); - s_input_dialog_caption = std::move(caption); - s_input_dialog_ok_text = std::move(ok_button_text); - s_input_dialog_callback = std::move(callback); + s_state.input_dialog_open = true; + s_state.input_dialog_title = std::move(title); + s_state.input_dialog_message = std::move(message); + s_state.input_dialog_caption = std::move(caption); + s_state.input_dialog_ok_text = std::move(ok_button_text); + s_state.input_dialog_callback = std::move(callback); QueueResetFocus(FocusResetType::PopupOpened); } void ImGuiFullscreen::DrawInputDialog() { - if (!s_input_dialog_open) + if (!s_state.input_dialog_open) return; ImGui::SetNextWindowSize(LayoutScale(700.0f, 0.0f)); ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); - ImGui::OpenPopup(s_input_dialog_title.c_str()); + ImGui::OpenPopup(s_state.input_dialog_title.c_str()); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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); - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIPrimaryColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); bool is_open = true; - if (ImGui::BeginPopupModal(s_input_dialog_title.c_str(), &is_open, + if (ImGui::BeginPopupModal(s_state.input_dialog_title.c_str(), &is_open, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove)) { ResetFocusHere(); - ImGui::TextWrapped("%s", s_input_dialog_message.c_str()); + ImGui::TextWrapped("%s", s_state.input_dialog_message.c_str()); BeginMenuButtons(); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - if (!s_input_dialog_caption.empty()) + if (!s_state.input_dialog_caption.empty()) { const float prev = ImGui::GetCursorPosX(); - ImGui::TextUnformatted(s_input_dialog_caption.c_str()); + ImGui::TextUnformatted(s_state.input_dialog_caption.c_str()); ImGui::SetNextItemWidth(ImGui::GetCursorPosX() - prev); } else { ImGui::SetNextItemWidth(ImGui::GetCurrentWindow()->WorkRect.GetWidth()); } - ImGui::InputText("##input", &s_input_dialog_text); + ImGui::InputText("##input", &s_state.input_dialog_text); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f)); - const bool ok_enabled = !s_input_dialog_text.empty(); + const bool ok_enabled = !s_state.input_dialog_text.empty(); - if (ActiveButton(s_input_dialog_ok_text.c_str(), false, ok_enabled) && ok_enabled) + if (ActiveButton(s_state.input_dialog_ok_text.c_str(), false, ok_enabled) && ok_enabled) { // have to move out in case they open another dialog in the callback - InputStringDialogCallback cb(std::move(s_input_dialog_callback)); - std::string text(std::move(s_input_dialog_text)); + InputStringDialogCallback cb(std::move(s_state.input_dialog_callback)); + std::string text(std::move(s_state.input_dialog_text)); CloseInputDialog(); ImGui::CloseCurrentPopup(); cb(std::move(text)); @@ -2594,7 +2579,7 @@ void ImGuiFullscreen::DrawInputDialog() if (!is_open) CloseInputDialog(); else - GetInputDialogHelpText(s_fullscreen_footer_text); + GetInputDialogHelpText(s_state.fullscreen_footer_text); ImGui::PopStyleColor(3); ImGui::PopStyleVar(3); @@ -2603,24 +2588,24 @@ void ImGuiFullscreen::DrawInputDialog() void ImGuiFullscreen::CloseInputDialog() { - if (!s_input_dialog_open) + if (!s_state.input_dialog_open) return; - if (ImGui::IsPopupOpen(s_input_dialog_title.c_str(), 0)) + if (ImGui::IsPopupOpen(s_state.input_dialog_title.c_str(), 0)) ImGui::ClosePopupToLevel(GImGui->OpenPopupStack.Size - 1, true); - s_input_dialog_open = false; - s_input_dialog_title = {}; - s_input_dialog_message = {}; - s_input_dialog_caption = {}; - s_input_dialog_ok_text = {}; - s_input_dialog_text = {}; - s_input_dialog_callback = {}; + s_state.input_dialog_open = false; + s_state.input_dialog_title = {}; + s_state.input_dialog_message = {}; + s_state.input_dialog_caption = {}; + s_state.input_dialog_ok_text = {}; + s_state.input_dialog_text = {}; + s_state.input_dialog_callback = {}; } bool ImGuiFullscreen::IsMessageBoxDialogOpen() { - return s_message_dialog_open; + return s_state.message_dialog_open; } void ImGuiFullscreen::OpenConfirmMessageDialog(std::string title, std::string message, @@ -2629,12 +2614,12 @@ void ImGuiFullscreen::OpenConfirmMessageDialog(std::string title, std::string me { CloseMessageDialog(); - s_message_dialog_open = true; - s_message_dialog_title = std::move(title); - s_message_dialog_message = std::move(message); - s_message_dialog_callback = std::move(callback); - s_message_dialog_buttons[0] = std::move(yes_button_text); - s_message_dialog_buttons[1] = std::move(no_button_text); + s_state.message_dialog_open = true; + s_state.message_dialog_title = std::move(title); + s_state.message_dialog_message = std::move(message); + s_state.message_dialog_callback = std::move(callback); + s_state.message_dialog_buttons[0] = std::move(yes_button_text); + s_state.message_dialog_buttons[1] = std::move(no_button_text); QueueResetFocus(FocusResetType::PopupOpened); } @@ -2643,11 +2628,11 @@ void ImGuiFullscreen::OpenInfoMessageDialog(std::string title, std::string messa { CloseMessageDialog(); - s_message_dialog_open = true; - s_message_dialog_title = std::move(title); - s_message_dialog_message = std::move(message); - s_message_dialog_callback = std::move(callback); - s_message_dialog_buttons[0] = std::move(button_text); + s_state.message_dialog_open = true; + s_state.message_dialog_title = std::move(title); + s_state.message_dialog_message = std::move(message); + s_state.message_dialog_callback = std::move(callback); + s_state.message_dialog_buttons[0] = std::move(button_text); QueueResetFocus(FocusResetType::PopupOpened); } @@ -2657,57 +2642,57 @@ void ImGuiFullscreen::OpenMessageDialog(std::string title, std::string message, { CloseMessageDialog(); - s_message_dialog_open = true; - s_message_dialog_title = std::move(title); - s_message_dialog_message = std::move(message); - s_message_dialog_callback = std::move(callback); - s_message_dialog_buttons[0] = std::move(first_button_text); - s_message_dialog_buttons[1] = std::move(second_button_text); - s_message_dialog_buttons[2] = std::move(third_button_text); + s_state.message_dialog_open = true; + s_state.message_dialog_title = std::move(title); + s_state.message_dialog_message = std::move(message); + s_state.message_dialog_callback = std::move(callback); + s_state.message_dialog_buttons[0] = std::move(first_button_text); + s_state.message_dialog_buttons[1] = std::move(second_button_text); + s_state.message_dialog_buttons[2] = std::move(third_button_text); QueueResetFocus(FocusResetType::PopupOpened); } void ImGuiFullscreen::CloseMessageDialog() { - if (!s_message_dialog_open) + if (!s_state.message_dialog_open) return; - if (ImGui::IsPopupOpen(s_message_dialog_title.c_str(), 0)) + if (ImGui::IsPopupOpen(s_state.message_dialog_title.c_str(), 0)) ImGui::ClosePopupToLevel(GImGui->OpenPopupStack.Size - 1, true); - s_message_dialog_open = false; - s_message_dialog_title = {}; - s_message_dialog_message = {}; - s_message_dialog_buttons = {}; - s_message_dialog_callback = {}; + s_state.message_dialog_open = false; + s_state.message_dialog_title = {}; + s_state.message_dialog_message = {}; + s_state.message_dialog_buttons = {}; + s_state.message_dialog_callback = {}; QueueResetFocus(FocusResetType::PopupClosed); } void ImGuiFullscreen::DrawMessageDialog() { - if (!s_message_dialog_open) + if (!s_state.message_dialog_open) return; - const char* win_id = s_message_dialog_title.empty() ? "##messagedialog" : s_message_dialog_title.c_str(); + const char* win_id = s_state.message_dialog_title.empty() ? "##messagedialog" : s_state.message_dialog_title.c_str(); ImGui::SetNextWindowSize(LayoutScale(700.0f, 0.0f)); ImGui::SetNextWindowPos((ImGui::GetIO().DisplaySize - LayoutScale(0.0f, LAYOUT_FOOTER_HEIGHT)) * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::OpenPopup(win_id); - ImGui::PushFont(g_large_font); + ImGui::PushFont(UIStyle.LargeFont); 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)); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, UIPrimaryTextColor); - ImGui::PushStyleColor(ImGuiCol_TitleBg, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIPrimaryColor); + ImGui::PushStyleColor(ImGuiCol_Text, UIStyle.PrimaryTextColor); + ImGui::PushStyleColor(ImGuiCol_TitleBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, UIStyle.PrimaryColor); bool is_open = true; const u32 flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | - (s_message_dialog_title.empty() ? ImGuiWindowFlags_NoTitleBar : 0); + (s_state.message_dialog_title.empty() ? ImGuiWindowFlags_NoTitleBar : 0); std::optional result; if (ImGui::BeginPopupModal(win_id, &is_open, flags)) @@ -2715,13 +2700,13 @@ void ImGuiFullscreen::DrawMessageDialog() ResetFocusHere(); BeginMenuButtons(); - ImGui::TextWrapped("%s", s_message_dialog_message.c_str()); + ImGui::TextWrapped("%s", s_state.message_dialog_message.c_str()); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(20.0f)); - for (s32 button_index = 0; button_index < static_cast(s_message_dialog_buttons.size()); button_index++) + for (s32 button_index = 0; button_index < static_cast(s_state.message_dialog_buttons.size()); button_index++) { - if (!s_message_dialog_buttons[button_index].empty() && - ActiveButton(s_message_dialog_buttons[button_index].c_str(), false)) + if (!s_state.message_dialog_buttons[button_index].empty() && + ActiveButton(s_state.message_dialog_buttons[button_index].c_str(), false)) { result = button_index; ImGui::CloseCurrentPopup(); @@ -2740,7 +2725,7 @@ void ImGuiFullscreen::DrawMessageDialog() if (!is_open || result.has_value()) { // have to move out in case they open another dialog in the callback - auto cb = (std::move(s_message_dialog_callback)); + auto cb = (std::move(s_state.message_dialog_callback)); CloseMessageDialog(); if (std::holds_alternative(cb)) @@ -2758,7 +2743,7 @@ void ImGuiFullscreen::DrawMessageDialog() } else { - GetChoiceDialogHelpText(s_fullscreen_footer_text); + GetChoiceDialogHelpText(s_state.fullscreen_footer_text); } } @@ -2790,10 +2775,10 @@ void ImGuiFullscreen::OpenBackgroundProgressDialog(const char* str_id, std::stri { const ImGuiID id = GetBackgroundProgressID(str_id); - std::unique_lock lock(s_background_progress_lock); + std::unique_lock lock(s_state.background_progress_lock); #if defined(_DEBUG) || defined(_DEVEL) - for (const BackgroundProgressDialogData& data : s_background_progress_dialogs) + for (const BackgroundProgressDialogData& data : s_state.background_progress_dialogs) { DebugAssert(data.id != id); } @@ -2805,7 +2790,7 @@ void ImGuiFullscreen::OpenBackgroundProgressDialog(const char* str_id, std::stri data.min = min; data.max = max; data.value = value; - s_background_progress_dialogs.push_back(std::move(data)); + s_state.background_progress_dialogs.push_back(std::move(data)); } void ImGuiFullscreen::UpdateBackgroundProgressDialog(const char* str_id, std::string message, s32 min, s32 max, @@ -2813,9 +2798,9 @@ void ImGuiFullscreen::UpdateBackgroundProgressDialog(const char* str_id, std::st { const ImGuiID id = GetBackgroundProgressID(str_id); - std::unique_lock lock(s_background_progress_lock); + std::unique_lock lock(s_state.background_progress_lock); - for (BackgroundProgressDialogData& data : s_background_progress_dialogs) + for (BackgroundProgressDialogData& data : s_state.background_progress_dialogs) { if (data.id == id) { @@ -2834,13 +2819,13 @@ void ImGuiFullscreen::CloseBackgroundProgressDialog(const char* str_id) { const ImGuiID id = GetBackgroundProgressID(str_id); - std::unique_lock lock(s_background_progress_lock); + std::unique_lock lock(s_state.background_progress_lock); - for (auto it = s_background_progress_dialogs.begin(); it != s_background_progress_dialogs.end(); ++it) + for (auto it = s_state.background_progress_dialogs.begin(); it != s_state.background_progress_dialogs.end(); ++it) { if (it->id == id) { - s_background_progress_dialogs.erase(it); + s_state.background_progress_dialogs.erase(it); return; } } @@ -2852,9 +2837,9 @@ bool ImGuiFullscreen::IsBackgroundProgressDialogOpen(const char* str_id) { const ImGuiID id = GetBackgroundProgressID(str_id); - std::unique_lock lock(s_background_progress_lock); + std::unique_lock lock(s_state.background_progress_lock); - for (auto it = s_background_progress_dialogs.begin(); it != s_background_progress_dialogs.end(); ++it) + for (auto it = s_state.background_progress_dialogs.begin(); it != s_state.background_progress_dialogs.end(); ++it) { if (it->id == id) return true; @@ -2865,24 +2850,24 @@ bool ImGuiFullscreen::IsBackgroundProgressDialogOpen(const char* str_id) void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spacing) { - std::unique_lock lock(s_background_progress_lock); - if (s_background_progress_dialogs.empty()) + std::unique_lock lock(s_state.background_progress_lock); + if (s_state.background_progress_dialogs.empty()) return; const float window_width = LayoutScale(500.0f); const float window_height = LayoutScale(75.0f); - ImGui::PushStyleColor(ImGuiCol_WindowBg, UIPrimaryDarkColor); - ImGui::PushStyleColor(ImGuiCol_PlotHistogram, UISecondaryStrongColor); + ImGui::PushStyleColor(ImGuiCol_WindowBg, UIStyle.PrimaryDarkColor); + ImGui::PushStyleColor(ImGuiCol_PlotHistogram, UIStyle.SecondaryStrongColor); ImGui::PushStyleVar(ImGuiStyleVar_PopupRounding, LayoutScale(4.0f)); 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(UIStyle.MediumFont); ImDrawList* dl = ImGui::GetForegroundDrawList(); - for (const BackgroundProgressDialogData& data : s_background_progress_dialogs) + for (const BackgroundProgressDialogData& data : s_state.background_progress_dialogs) { const float window_pos_x = position.x; const float window_pos_y = position.y - ((s_notification_vertical_direction < 0.0f) ? window_height : 0.0f); @@ -2892,25 +2877,25 @@ 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(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, pos, IM_COL32(255, 255, 255, 255), + data.message.c_str(), nullptr, 0.0f); + pos.y += UIStyle.MediumFont->FontSize + 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)); + dl->AddRectFilled(pos, box_end, ImGui::GetColorU32(UIStyle.PrimaryDarkColor)); if (data.min != data.max) { const float fraction = static_cast(data.value - data.min) / static_cast(data.max - data.min); dl->AddRectFilled(pos, ImVec2(pos.x + fraction * (box_end.x - pos.x), box_end.y), - ImGui::GetColorU32(UISecondaryColor)); + ImGui::GetColorU32(UIStyle.SecondaryColor)); const auto text = TinyString::from_format("{}%", static_cast(std::round(fraction * 100.0f))); const ImVec2 text_size(ImGui::CalcTextSize(text)); 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(), text.end_ptr()); + dl->AddText(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, text_pos, + ImGui::GetColorU32(UIStyle.PrimaryTextColor), text.c_str(), text.end_ptr()); } else { @@ -2920,7 +2905,7 @@ void ImGuiFullscreen::DrawBackgroundProgressDialogs(ImVec2& position, float spac const ImVec2 bar_start(pos.x + ImLerp(0.0f, box_end.x, fraction) - bar_width, pos.y); const ImVec2 bar_end(std::min(bar_start.x + bar_width, box_end.x), pos.y + LayoutScale(25.0f)); dl->AddRectFilled(ImClamp(bar_start, pos, box_end), ImClamp(bar_end, pos, box_end), - ImGui::GetColorU32(UISecondaryColor)); + ImGui::GetColorU32(UIStyle.SecondaryColor)); } position.y += s_notification_vertical_direction * (window_height + spacing); @@ -2942,7 +2927,7 @@ void ImGuiFullscreen::AddNotification(std::string key, float duration, std::stri if (!key.empty()) { - for (auto it = s_notifications.begin(); it != s_notifications.end(); ++it) + for (auto it = s_state.notifications.begin(); it != s_state.notifications.end(); ++it) { if (it->key == key) { @@ -2969,17 +2954,17 @@ void ImGuiFullscreen::AddNotification(std::string key, float duration, std::stri notif.move_time = current_time; notif.target_y = -1.0f; notif.last_y = -1.0f; - s_notifications.push_back(std::move(notif)); + s_state.notifications.push_back(std::move(notif)); } void ImGuiFullscreen::ClearNotifications() { - s_notifications.clear(); + s_state.notifications.clear(); } void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing) { - if (s_notifications.empty()) + if (s_state.notifications.empty()) return; static constexpr float MOVE_DURATION = 0.5f; @@ -2997,21 +2982,23 @@ 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; + ImFont* const title_font = ImGuiFullscreen::UIStyle.LargeFont; + ImFont* const text_font = ImGuiFullscreen::UIStyle.MediumFont; - const u32 toast_background_color = s_light_theme ? IM_COL32(241, 241, 241, 255) : IM_COL32(0x21, 0x21, 0x21, 255); - const u32 toast_border_color = s_light_theme ? IM_COL32(0x88, 0x88, 0x88, 255) : IM_COL32(0x48, 0x48, 0x48, 255); - const u32 toast_title_color = s_light_theme ? IM_COL32(1, 1, 1, 255) : IM_COL32(0xff, 0xff, 0xff, 255); - const u32 toast_text_color = s_light_theme ? IM_COL32(0, 0, 0, 255) : IM_COL32(0xff, 0xff, 0xff, 255); + const u32 toast_background_color = + s_state.light_theme ? IM_COL32(241, 241, 241, 255) : IM_COL32(0x21, 0x21, 0x21, 255); + const u32 toast_border_color = + s_state.light_theme ? IM_COL32(0x88, 0x88, 0x88, 255) : IM_COL32(0x48, 0x48, 0x48, 255); + const u32 toast_title_color = s_state.light_theme ? IM_COL32(1, 1, 1, 255) : IM_COL32(0xff, 0xff, 0xff, 255); + const u32 toast_text_color = s_state.light_theme ? IM_COL32(0, 0, 0, 255) : IM_COL32(0xff, 0xff, 0xff, 255); - for (u32 index = 0; index < static_cast(s_notifications.size());) + for (u32 index = 0; index < static_cast(s_state.notifications.size());) { - Notification& notif = s_notifications[index]; + Notification& notif = s_state.notifications[index]; const float time_passed = static_cast(Timer::ConvertValueToSeconds(current_time - notif.start_time)); if (time_passed >= notif.duration) { - s_notifications.erase(s_notifications.begin() + index); + s_state.notifications.erase(s_state.notifications.begin() + index); continue; } @@ -3104,119 +3091,121 @@ void ImGuiFullscreen::DrawNotifications(ImVec2& position, float spacing) void ImGuiFullscreen::ShowToast(std::string title, std::string message, float duration) { - s_toast_title = std::move(title); - s_toast_message = std::move(message); - s_toast_start_time = Timer::GetCurrentValue(); - s_toast_duration = duration; + s_state.toast_title = std::move(title); + s_state.toast_message = std::move(message); + s_state.toast_start_time = Timer::GetCurrentValue(); + s_state.toast_duration = duration; } void ImGuiFullscreen::ClearToast() { - s_toast_message = {}; - s_toast_title = {}; - s_toast_start_time = 0; - s_toast_duration = 0.0f; + s_state.toast_message = {}; + s_state.toast_title = {}; + s_state.toast_start_time = 0; + s_state.toast_duration = 0.0f; } void ImGuiFullscreen::DrawToast() { - if (s_toast_title.empty() && s_toast_message.empty()) + if (s_state.toast_title.empty() && s_state.toast_message.empty()) return; - const float elapsed = static_cast(Timer::ConvertValueToSeconds(Timer::GetCurrentValue() - s_toast_start_time)); - if (elapsed >= s_toast_duration) + const float elapsed = + static_cast(Timer::ConvertValueToSeconds(Timer::GetCurrentValue() - s_state.toast_start_time)); + if (elapsed >= s_state.toast_duration) { ClearToast(); return; } // fade out the last second - const float alpha = std::min(std::min(elapsed * 4.0f, s_toast_duration - elapsed), 1.0f); + const float alpha = std::min(std::min(elapsed * 4.0f, s_state.toast_duration - elapsed), 1.0f); const float max_width = LayoutScale(600.0f); - ImFont* title_font = g_large_font; - ImFont* message_font = g_medium_font; + ImFont* title_font = UIStyle.LargeFont; + ImFont* message_font = UIStyle.MediumFont; 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 float margin = LayoutScale(20.0f + (s_state.fullscreen_footer_text.empty() ? 0.0f : LAYOUT_FOOTER_HEIGHT)); + const float spacing = s_state.toast_title.empty() ? 0.0f : LayoutScale(10.0f); const ImVec2 display_size(ImGui::GetIO().DisplaySize); - const ImVec2 title_size(s_toast_title.empty() ? + const ImVec2 title_size(s_state.toast_title.empty() ? ImVec2(0.0f, 0.0f) : - title_font->CalcTextSizeA(title_font->FontSize, 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, - s_toast_message.c_str(), - s_toast_message.c_str() + s_toast_message.length())); + title_font->CalcTextSizeA(title_font->FontSize, FLT_MAX, max_width, + s_state.toast_title.c_str(), + s_state.toast_title.c_str() + s_state.toast_title.length())); + const ImVec2 message_size( + s_state.toast_message.empty() ? + ImVec2(0.0f, 0.0f) : + message_font->CalcTextSizeA(message_font->FontSize, FLT_MAX, max_width, s_state.toast_message.c_str(), + s_state.toast_message.c_str() + s_state.toast_message.length())); const ImVec2 comb_size(std::max(title_size.x, message_size.x), title_size.y + spacing + message_size.y); const ImVec2 box_size(comb_size.x + total_padding, comb_size.y + total_padding); const ImVec2 box_pos((display_size.x - box_size.x) * 0.5f, (display_size.y - margin - box_size.y)); ImDrawList* dl = ImGui::GetForegroundDrawList(); - dl->AddRectFilled(box_pos, box_pos + box_size, ImGui::GetColorU32(ModAlpha(UIPrimaryColor, alpha)), padding); - if (!s_toast_title.empty()) + dl->AddRectFilled(box_pos, box_pos + box_size, ImGui::GetColorU32(ModAlpha(UIStyle.PrimaryColor, alpha)), padding); + if (!s_state.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), - ImGui::GetColorU32(ModAlpha(UIPrimaryTextColor, alpha)), s_toast_title.c_str(), - s_toast_title.c_str() + s_toast_title.length(), max_width); + ImGui::GetColorU32(ModAlpha(UIStyle.PrimaryTextColor, alpha)), s_state.toast_title.c_str(), + s_state.toast_title.c_str() + s_state.toast_title.length(), max_width); } - if (!s_toast_message.empty()) + if (!s_state.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), - ImGui::GetColorU32(ModAlpha(UIPrimaryTextColor, alpha)), s_toast_message.c_str(), - s_toast_message.c_str() + s_toast_message.length(), max_width); + ImGui::GetColorU32(ModAlpha(UIStyle.PrimaryTextColor, alpha)), s_state.toast_message.c_str(), + s_state.toast_message.c_str() + s_state.toast_message.length(), max_width); } } void ImGuiFullscreen::SetTheme(bool light) { - s_light_theme = light; + s_state.light_theme = light; if (!light) { // dark - UIBackgroundColor = HEX_TO_IMVEC4(0x212121, 0xff); - UIBackgroundTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); - UIBackgroundLineColor = HEX_TO_IMVEC4(0xf0f0f0, 0xff); - UIBackgroundHighlightColor = HEX_TO_IMVEC4(0x4b4b4b, 0xff); - UIPopupBackgroundColor = HEX_TO_IMVEC4(0x212121, 0xf2); - UIPrimaryColor = HEX_TO_IMVEC4(0x2e2e2e, 0xff); - UIPrimaryLightColor = HEX_TO_IMVEC4(0x484848, 0xff); - UIPrimaryDarkColor = HEX_TO_IMVEC4(0x000000, 0xff); - UIPrimaryTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); - UIDisabledColor = HEX_TO_IMVEC4(0xaaaaaa, 0xff); - UITextHighlightColor = HEX_TO_IMVEC4(0x90caf9, 0xff); - UIPrimaryLineColor = HEX_TO_IMVEC4(0xffffff, 0xff); - UISecondaryColor = HEX_TO_IMVEC4(0x0d47a1, 0xff); - UISecondaryStrongColor = HEX_TO_IMVEC4(0x63a4ff, 0xff); - UISecondaryWeakColor = HEX_TO_IMVEC4(0x002171, 0xff); - UISecondaryTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); + UIStyle.BackgroundColor = HEX_TO_IMVEC4(0x212121, 0xff); + UIStyle.BackgroundTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); + UIStyle.BackgroundLineColor = HEX_TO_IMVEC4(0xf0f0f0, 0xff); + UIStyle.BackgroundHighlight = HEX_TO_IMVEC4(0x4b4b4b, 0xff); + UIStyle.PopupBackgroundColor = HEX_TO_IMVEC4(0x212121, 0xf2); + UIStyle.PrimaryColor = HEX_TO_IMVEC4(0x2e2e2e, 0xff); + UIStyle.PrimaryLightColor = HEX_TO_IMVEC4(0x484848, 0xff); + UIStyle.PrimaryDarkColor = HEX_TO_IMVEC4(0x000000, 0xff); + UIStyle.PrimaryTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); + UIStyle.DisabledColor = HEX_TO_IMVEC4(0xaaaaaa, 0xff); + UIStyle.TextHighlightColor = HEX_TO_IMVEC4(0x90caf9, 0xff); + UIStyle.PrimaryLineColor = HEX_TO_IMVEC4(0xffffff, 0xff); + UIStyle.SecondaryColor = HEX_TO_IMVEC4(0x0d47a1, 0xff); + UIStyle.SecondaryStrongColor = HEX_TO_IMVEC4(0x63a4ff, 0xff); + UIStyle.SecondaryWeakColor = HEX_TO_IMVEC4(0x002171, 0xff); + UIStyle.SecondaryTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); } else { // light - UIBackgroundColor = HEX_TO_IMVEC4(0xc8c8c8, 0xff); - UIBackgroundTextColor = HEX_TO_IMVEC4(0x000000, 0xff); - UIBackgroundLineColor = HEX_TO_IMVEC4(0xe1e2e1, 0xff); - UIBackgroundHighlightColor = HEX_TO_IMVEC4(0xe1e2e1, 0xff); - UIPopupBackgroundColor = HEX_TO_IMVEC4(0xd8d8d8, 0xf2); - UIPrimaryColor = HEX_TO_IMVEC4(0x2a3e78, 0xff); - UIPrimaryLightColor = HEX_TO_IMVEC4(0x235cd9, 0xff); - UIPrimaryDarkColor = HEX_TO_IMVEC4(0x1d2953, 0xff); - UIPrimaryTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); - UIDisabledColor = HEX_TO_IMVEC4(0x999999, 0xff); - UITextHighlightColor = HEX_TO_IMVEC4(0x8e8e8e, 0xff); - UIPrimaryLineColor = HEX_TO_IMVEC4(0x000000, 0xff); - UISecondaryColor = HEX_TO_IMVEC4(0x2a3e78, 0xff); - UISecondaryStrongColor = HEX_TO_IMVEC4(0x464db1, 0xff); - UISecondaryWeakColor = HEX_TO_IMVEC4(0xc0cfff, 0xff); - UISecondaryTextColor = HEX_TO_IMVEC4(0x000000, 0xff); + UIStyle.BackgroundColor = HEX_TO_IMVEC4(0xc8c8c8, 0xff); + UIStyle.BackgroundTextColor = HEX_TO_IMVEC4(0x000000, 0xff); + UIStyle.BackgroundLineColor = HEX_TO_IMVEC4(0xe1e2e1, 0xff); + UIStyle.BackgroundHighlight = HEX_TO_IMVEC4(0xe1e2e1, 0xff); + UIStyle.PopupBackgroundColor = HEX_TO_IMVEC4(0xd8d8d8, 0xf2); + UIStyle.PrimaryColor = HEX_TO_IMVEC4(0x2a3e78, 0xff); + UIStyle.PrimaryLightColor = HEX_TO_IMVEC4(0x235cd9, 0xff); + UIStyle.PrimaryDarkColor = HEX_TO_IMVEC4(0x1d2953, 0xff); + UIStyle.PrimaryTextColor = HEX_TO_IMVEC4(0xffffff, 0xff); + UIStyle.DisabledColor = HEX_TO_IMVEC4(0x999999, 0xff); + UIStyle.TextHighlightColor = HEX_TO_IMVEC4(0x8e8e8e, 0xff); + UIStyle.PrimaryLineColor = HEX_TO_IMVEC4(0x000000, 0xff); + UIStyle.SecondaryColor = HEX_TO_IMVEC4(0x2a3e78, 0xff); + UIStyle.SecondaryStrongColor = HEX_TO_IMVEC4(0x464db1, 0xff); + UIStyle.SecondaryWeakColor = HEX_TO_IMVEC4(0xc0cfff, 0xff); + UIStyle.SecondaryTextColor = HEX_TO_IMVEC4(0x000000, 0xff); } } \ No newline at end of file diff --git a/src/util/imgui_fullscreen.h b/src/util/imgui_fullscreen.h index 8f1fecbfa..a9bbba568 100644 --- a/src/util/imgui_fullscreen.h +++ b/src/util/imgui_fullscreen.h @@ -43,57 +43,62 @@ static constexpr float LAYOUT_HORIZONTAL_MENU_HEIGHT = 320.0f; static constexpr float LAYOUT_HORIZONTAL_MENU_PADDING = 30.0f; static constexpr float LAYOUT_HORIZONTAL_MENU_ITEM_WIDTH = 250.0f; -extern ImFont* g_medium_font; -extern ImFont* g_large_font; +struct ALIGN_TO_CACHE_LINE UIStyles +{ + ImVec4 BackgroundColor; + ImVec4 BackgroundTextColor; + ImVec4 BackgroundLineColor; + ImVec4 BackgroundHighlight; + ImVec4 PopupBackgroundColor; + ImVec4 DisabledColor; + ImVec4 PrimaryColor; + ImVec4 PrimaryLightColor; + ImVec4 PrimaryDarkColor; + ImVec4 PrimaryTextColor; + ImVec4 TextHighlightColor; + ImVec4 PrimaryLineColor; + ImVec4 SecondaryColor; + ImVec4 SecondaryWeakColor; // Not currently used. + ImVec4 SecondaryStrongColor; + ImVec4 SecondaryTextColor; -extern float g_layout_scale; -extern float g_rcp_layout_scale; -extern float g_layout_padding_left; -extern float g_layout_padding_top; + ImFont* MediumFont; + ImFont* LargeFont; -extern ImVec4 UIBackgroundColor; -extern ImVec4 UIBackgroundTextColor; -extern ImVec4 UIBackgroundLineColor; -extern ImVec4 UIBackgroundHighlightColor; -extern ImVec4 UIPopupBackgroundColor; -extern ImVec4 UIDisabledColor; -extern ImVec4 UIPrimaryColor; -extern ImVec4 UIPrimaryLightColor; -extern ImVec4 UIPrimaryDarkColor; -extern ImVec4 UIPrimaryTextColor; -extern ImVec4 UITextHighlightColor; -extern ImVec4 UIPrimaryLineColor; -extern ImVec4 UISecondaryColor; -extern ImVec4 UISecondaryWeakColor; // Not currently used. -extern ImVec4 UISecondaryStrongColor; -extern ImVec4 UISecondaryTextColor; + float LayoutScale; + float RcpLayoutScale; + float LayoutPaddingLeft; + float LayoutPaddingTop; +}; + +extern UIStyles UIStyle; ALWAYS_INLINE static float LayoutScale(float v) { - return ImCeil(g_layout_scale * v); + return ImCeil(UIStyle.LayoutScale * v); } ALWAYS_INLINE static ImVec2 LayoutScale(const ImVec2& v) { - return ImVec2(ImCeil(v.x * g_layout_scale), ImCeil(v.y * g_layout_scale)); + return ImVec2(ImCeil(v.x * UIStyle.LayoutScale), ImCeil(v.y * UIStyle.LayoutScale)); } ALWAYS_INLINE static ImVec2 LayoutScale(float x, float y) { - return ImVec2(ImCeil(x * g_layout_scale), ImCeil(y * g_layout_scale)); + return ImVec2(ImCeil(x * UIStyle.LayoutScale), ImCeil(y * UIStyle.LayoutScale)); } ALWAYS_INLINE static float LayoutUnscale(float v) { - return ImCeil(g_rcp_layout_scale * v); + return ImCeil(UIStyle.RcpLayoutScale * v); } ALWAYS_INLINE static ImVec2 LayoutUnscale(const ImVec2& v) { - return ImVec2(ImCeil(v.x * g_rcp_layout_scale), ImCeil(v.y * g_rcp_layout_scale)); + return ImVec2(ImCeil(v.x * UIStyle.RcpLayoutScale), ImCeil(v.y * UIStyle.RcpLayoutScale)); } ALWAYS_INLINE static ImVec2 LayoutUnscale(float x, float y) { - return ImVec2(ImCeil(x * g_rcp_layout_scale), ImCeil(y * g_rcp_layout_scale)); + return ImVec2(ImCeil(x * UIStyle.RcpLayoutScale), ImCeil(y * UIStyle.RcpLayoutScale)); } ALWAYS_INLINE static ImVec4 ModAlpha(const ImVec4& v, float a) @@ -170,7 +175,7 @@ bool BeginFullscreenColumns(const char* title = nullptr, float pos_y = 0.0f, boo void EndFullscreenColumns(); bool BeginFullscreenColumnWindow(float start, float end, const char* name, - const ImVec4& background = UIBackgroundColor); + const ImVec4& background = UIStyle.BackgroundColor); void EndFullscreenColumnWindow(); bool BeginFullscreenWindow(float left, float top, float width, float height, const char* name, @@ -200,39 +205,41 @@ void ResetMenuButtonFrame(); 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); + float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = UIStyle.LargeFont); bool DefaultActiveButton(const char* 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, ImFont* font = UIStyle.LargeFont); 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, ImFont* font = UIStyle.LargeFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); bool MenuButtonWithoutSummary(const char* title, bool enabled = true, - float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = g_large_font, + float height = LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, ImFont* font = UIStyle.LargeFont, 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, ImFont* font = UIStyle.LargeFont, + ImFont* summary_font = UIStyle.MediumFont); 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); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont); 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, + bool enabled = true, ImFont* font = UIStyle.LargeFont, 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); + float height = LAYOUT_MENU_BUTTON_HEIGHT, ImFont* font = UIStyle.LargeFont, + ImFont* summary_font = UIStyle.MediumFont); bool ThreeWayToggleButton(const char* title, const char* summary, std::optional* 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, ImFont* font = UIStyle.LargeFont, + ImFont* summary_font = UIStyle.MediumFont); bool RangeButton(const char* title, const char* summary, s32* value, s32 min, s32 max, s32 increment, const char* format = "%d", bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT, - ImFont* font = g_large_font, ImFont* summary_font = g_medium_font, const char* ok_text = "OK"); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont, + const char* ok_text = "OK"); bool RangeButton(const char* title, const char* summary, float* value, float min, float max, float increment, const char* format = "%f", bool enabled = true, float height = LAYOUT_MENU_BUTTON_HEIGHT, - ImFont* font = g_large_font, ImFont* summary_font = g_medium_font, const char* ok_text = "OK"); + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont, + const char* ok_text = "OK"); 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); @@ -241,7 +248,7 @@ template ALWAYS_INLINE static 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) + ImFont* font = UIStyle.LargeFont, ImFont* summary_font = UIStyle.MediumFont) { s32 value = static_cast(*value_pointer); auto to_display_name_wrapper = [](s32 value, void* opaque) -> const char* { @@ -265,13 +272,13 @@ void DrawShadowedText(ImDrawList* dl, ImFont* font, const ImVec2& pos, u32 col, 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, ImFont* font = UIStyle.LargeFont); 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, ImFont* font = UIStyle.LargeFont); bool NavTab(const char* title, bool is_active, bool enabled, float width, float height, const ImVec4& background, - ImFont* font = g_large_font); + ImFont* font = UIStyle.LargeFont); bool BeginHorizontalMenu(const char* name, const ImVec2& position, const ImVec2& size, u32 num_items); void EndHorizontalMenu();