Smooth out the fading of background textures on the main menu

This commit is contained in:
Henrik Rydgård committed 2026-03-15 11:30:43 +01:00
1 parent c4b81a37a4
commit e5cd4d69e9
2 files changed
+15 -2

No files matched your search

+1
View File
@@ -11,5 +11,6 @@ void UIBackgroundInit(UIContext &dc);
void UIBackgroundShutdown(); void UIBackgroundShutdown();
void DrawGameBackground(UIContext &dc, const Path &gamePath, Lin::Vec3 focus, float alpha); void DrawGameBackground(UIContext &dc, const Path &gamePath, Lin::Vec3 focus, float alpha);
void DrawBackground(UIContext &dc, float alpha, Lin::Vec3 focus); 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); uint32_t GetBackgroundColorWithAlpha(const UIContext &dc);
+14 -2
View File
@@ -1619,14 +1619,21 @@ void MainScreen::OnLoadFile(UI::EventParams &e) {
} }
void MainScreen::DrawBackground(UIContext &dc) { void MainScreen::DrawBackground(UIContext &dc) {
if (highlightedBackgrounds_.empty()) {
return;
}
constexpr float fadeTime = 0.5f; // constexpr float fadeTime = 0.5f; //
double now = time_now_d(); double now = time_now_d();
for (auto iter = highlightedBackgrounds_.begin(); iter != highlightedBackgrounds_.end(); ) { for (auto iter = highlightedBackgrounds_.begin(); iter != highlightedBackgrounds_.end(); ) {
float timeSinceStart = float(now - iter->startTime); std::shared_ptr<GameInfo> 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); float alpha = std::clamp(timeSinceStart / fadeTime, 0.0f, 1.0f);
if (iter->endTime > 0.0) { 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); float fadeOutAlpha = std::max(0.0f, float(now - iter->endTime) / fadeTime);
if (fadeOutAlpha > 1.0f) { if (fadeOutAlpha > 1.0f) {
iter = highlightedBackgrounds_.erase(iter); iter = highlightedBackgrounds_.erase(iter);
@@ -1634,8 +1641,13 @@ void MainScreen::DrawBackground(UIContext &dc) {
} }
alpha *= 1.0f - fadeOutAlpha; alpha *= 1.0f - fadeOutAlpha;
} }
DrawBackgroundFor(dc, iter->gamePath, alpha);
iter++; iter++;
if (!ginfo->pic1.texture) {
continue;
}
DrawBackgroundTexture(dc, ginfo->pic1.texture, Lin::Vec3(0.0f, 0.0f, 0.0f), alpha);
} }
} }