UI: Centralize BG pic choosing a bit.

It's in several places.
This commit is contained in:
Unknown W. Brackets
2021-04-04 10:57:40 -07:00
parent e2a8c83b9f
commit f98bafb73d
4 changed files with 21 additions and 36 deletions
+8
View File
@@ -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
+2 -6
View File
@@ -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) {
+8 -25
View File
@@ -180,24 +180,14 @@ private:
return g_gameInfoCache->GetInfo(dc.GetDrawContext(), g_Config.recentIsos[index], GAMEINFO_WANTBG);
}
Draw::Texture *GetTex(std::shared_ptr<GameInfo> &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<GameInfo> &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();
+3 -5
View File
@@ -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));