Path code cleanup, move some UI code (#21037)

* Move a bunch of path logic into Core/Util/PathUtil.cpp/h

.

* Move GameImageView out from SaveDataScreen

* More cleanup, add a translation string
This commit is contained in:
Henrik Rydgård
2025-11-25 00:44:24 +01:00
committed by GitHub
parent 3116eba395
commit b8fced5b41
72 changed files with 416 additions and 330 deletions
+52
View File
@@ -158,3 +158,55 @@ PaneTitleBar::PaneTitleBar(const Path &gamePath, std::string_view title, const s
});
}
}
void GameImageView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = textureWidth_;
h = textureHeight_;
}
void GameImageView::Draw(UIContext &dc) {
using namespace UI;
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath_, image_);
if (!info->Ready(image_) || !info->icon.texture) {
return;
}
Draw::Texture *texture = nullptr;
switch (image_) {
case GameInfoFlags::ICON:
texture = info->icon.texture;
break;
case GameInfoFlags::PIC0:
texture = info->pic0.texture;
break;
case GameInfoFlags::PIC1:
texture = info->pic1.texture;
break;
}
if (!texture) {
return;
}
textureWidth_ = texture->Width() * scale_;
textureHeight_ = texture->Height() * scale_;
// Fade icon with the backgrounds.
double loadTime = info->icon.timeLoaded;
auto pic = info->GetPIC1();
if (pic) {
loadTime = std::max(loadTime, pic->timeLoaded);
}
uint32_t color = whiteAlpha(ease((time_now_d() - loadTime) * 3));
// Adjust size so we don't stretch the image vertically or horizontally.
// Make sure it's not wider than 144 (like Doom Legacy homebrew), ugly in the grid mode.
float nw = std::min(bounds_.h * textureWidth_ / textureHeight_, (float)bounds_.w);
int x = bounds_.x + (bounds_.w - nw) / 2.0f;
dc.Flush();
dc.GetDrawContext()->BindTexture(0, texture);
dc.Draw()->Rect(x, bounds_.y, nw, bounds_.h, color);
dc.Flush();
dc.RebindTexture();
}