From f98bafb73df73e29b039cd3b62aa17f221912e90 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Apr 2021 10:57:40 -0700 Subject: [PATCH] UI: Centralize BG pic choosing a bit. It's in several places. --- UI/GameInfoCache.h | 8 ++++++++ UI/MainScreen.cpp | 8 ++------ UI/MiscScreens.cpp | 33 ++++++++------------------------- UI/TextureUtil.cpp | 8 +++----- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index 8563d111f9..ce9a2bf7b7 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -100,6 +100,14 @@ public: std::string GetTitle(); void SetTitle(const std::string &newTitle); + GameInfoTex *GetBGPic() { + if (pic0.texture) + return &pic0; + if (pic1.texture) + return &pic1; + return nullptr; + } + // Hold this when reading or writing from the GameInfo. // Don't need to hold it when just passing around the pointer, // and obviously also not when creating it and holding the only pointer diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 8ab0288b8b..90be90c501 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1309,12 +1309,8 @@ bool MainScreen::DrawBackgroundFor(UIContext &dc, const std::string &gamePath, f return false; } - Draw::Texture *texture = nullptr; - if (ginfo->pic1.texture) { - texture = ginfo->pic1.texture->GetTexture(); - } else if (ginfo->pic0.texture) { - texture = ginfo->pic0.texture->GetTexture(); - } + auto pic = ginfo->GetBGPic(); + Draw::Texture *texture = pic ? pic->texture->GetTexture() : nullptr; uint32_t color = whiteAlpha(ease(progress)) & 0xFFc0c0c0; if (texture) { diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index af1133b540..4667fb4273 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -180,24 +180,14 @@ private: return g_gameInfoCache->GetInfo(dc.GetDrawContext(), g_Config.recentIsos[index], GAMEINFO_WANTBG); } - Draw::Texture *GetTex(std::shared_ptr &ginfo) { - if (ginfo && ginfo->pic1.texture) { - return ginfo->pic1.texture->GetTexture(); - } - if (ginfo && ginfo->pic0.texture) { - return ginfo->pic0.texture->GetTexture(); - } - return nullptr; - } - void DrawTex(UIContext &dc, std::shared_ptr &ginfo, float amount) { if (!ginfo || amount <= 0.0f) return; - Draw::Texture *tex = GetTex(ginfo); - if (!tex) + GameInfoTex *pic = ginfo->GetBGPic(); + if (!pic) return; - dc.GetDrawContext()->BindTexture(0, tex); + dc.GetDrawContext()->BindTexture(0, pic->texture->GetTexture()); uint32_t color = whiteAlpha(amount) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, color); dc.Flush(); @@ -281,19 +271,12 @@ void DrawGameBackground(UIContext &dc, const std::string &gamePath) { ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath, GAMEINFO_WANTBG); dc.Flush(); - bool hasPic = false; - double loadTime; - if (ginfo && ginfo->pic1.texture) { - dc.GetDrawContext()->BindTexture(0, ginfo->pic1.texture->GetTexture()); - loadTime = ginfo->pic1.timeLoaded; - hasPic = true; - } else if (ginfo && ginfo->pic0.texture) { - dc.GetDrawContext()->BindTexture(0, ginfo->pic0.texture->GetTexture()); - loadTime = ginfo->pic0.timeLoaded; - hasPic = true; + GameInfoTex *pic = ginfo ? ginfo->GetBGPic() : nullptr; + if (pic) { + dc.GetDrawContext()->BindTexture(0, pic->texture->GetTexture()); } - if (hasPic) { - uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3)) & 0xFFc0c0c0; + if (pic) { + uint32_t color = whiteAlpha(ease((time_now_d() - pic->timeLoaded) * 3)) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0,0,1,1, color); dc.Flush(); dc.RebindTexture(); diff --git a/UI/TextureUtil.cpp b/UI/TextureUtil.cpp index 3d986e765a..9a5b377a90 100644 --- a/UI/TextureUtil.cpp +++ b/UI/TextureUtil.cpp @@ -236,11 +236,9 @@ void GameIconView::Draw(UIContext &dc) { // Fade icon with the backgrounds. double loadTime = info->icon.timeLoaded; - if (info->pic1.texture) { - loadTime = std::max(loadTime, info->pic1.timeLoaded); - } - if (info->pic0.texture) { - loadTime = std::max(loadTime, info->pic0.timeLoaded); + auto pic = info->GetBGPic(); + if (pic) { + loadTime = std::max(loadTime, pic->timeLoaded); } uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3));