From e5cd4d69e95ca4ce586dcb202e075014e71f7635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 15 Mar 2026 11:30:43 +0100 Subject: [PATCH] Smooth out the fading of background textures on the main menu --- UI/Background.h | 1 + UI/MainScreen.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/UI/Background.h b/UI/Background.h index 2c31bf18d3..fd64e9dff9 100644 --- a/UI/Background.h +++ b/UI/Background.h @@ -11,5 +11,6 @@ void UIBackgroundInit(UIContext &dc); void UIBackgroundShutdown(); void DrawGameBackground(UIContext &dc, const Path &gamePath, Lin::Vec3 focus, float alpha); void DrawBackground(UIContext &dc, float alpha, Lin::Vec3 focus); +void DrawBackgroundTexture(UIContext &dc, Draw::Texture *texture, Lin::Vec3 focus, float alpha); uint32_t GetBackgroundColorWithAlpha(const UIContext &dc); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 6a95582fb1..591b03145c 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1619,14 +1619,21 @@ void MainScreen::OnLoadFile(UI::EventParams &e) { } void MainScreen::DrawBackground(UIContext &dc) { + if (highlightedBackgrounds_.empty()) { + return; + } + constexpr float fadeTime = 0.5f; // double now = time_now_d(); for (auto iter = highlightedBackgrounds_.begin(); iter != highlightedBackgrounds_.end(); ) { - float timeSinceStart = float(now - iter->startTime); + std::shared_ptr ginfo; + ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), iter->gamePath, GameInfoFlags::PIC1); + float timeSinceStart = float(now - std::max(iter->startTime, ginfo->pic1.timeLoaded)); float alpha = std::clamp(timeSinceStart / fadeTime, 0.0f, 1.0f); if (iter->endTime > 0.0) { + // TODO: Consider only fading out if it's the last one in the list, to avoid background shine-through. float fadeOutAlpha = std::max(0.0f, float(now - iter->endTime) / fadeTime); if (fadeOutAlpha > 1.0f) { iter = highlightedBackgrounds_.erase(iter); @@ -1634,8 +1641,13 @@ void MainScreen::DrawBackground(UIContext &dc) { } alpha *= 1.0f - fadeOutAlpha; } - DrawBackgroundFor(dc, iter->gamePath, alpha); iter++; + + if (!ginfo->pic1.texture) { + continue; + } + + DrawBackgroundTexture(dc, ginfo->pic1.texture, Lin::Vec3(0.0f, 0.0f, 0.0f), alpha); } }