diff --git a/Common/UI/Context.h b/Common/UI/Context.h index 94432bd8ad..74cf390c32 100644 --- a/Common/UI/Context.h +++ b/Common/UI/Context.h @@ -114,7 +114,7 @@ public: void SetBounds(const Bounds &b) { bounds_ = b; } const Bounds &GetBounds() const { return bounds_; } Bounds GetLayoutBounds(bool ignoreBottomInset = false) const; - Draw::DrawContext *GetDrawContext() { return draw_; } + Draw::DrawContext *GetDrawContext() const { return draw_; } const UI::Theme &GetTheme() const { return *theme; } diff --git a/UI/MiscViews.cpp b/UI/MiscViews.cpp index 9dc392af35..da94334e51 100644 --- a/UI/MiscViews.cpp +++ b/UI/MiscViews.cpp @@ -160,36 +160,50 @@ 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_; + std::shared_ptr info = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath_, image_); + GameInfoTex *tex = GetTex(info); + w = 0; + h = 0; + if (!tex || !tex->texture) { + return; + } + Draw::Texture *texture = tex->texture; + w = tex->texture->Width(); + h = tex->texture->Height(); +} + +GameInfoTex *GameImageView::GetTex(std::shared_ptr info) const { + GameInfoTex *tex = nullptr; + switch (image_) { + case GameInfoFlags::ICON: + tex = &info->icon; + break; + case GameInfoFlags::PIC0: + tex = &info->pic0; + break; + case GameInfoFlags::PIC1: + tex = &info->pic1; + break; + } + return tex; } void GameImageView::Draw(UIContext &dc) { using namespace UI; std::shared_ptr info = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath_, image_); - if (!info->Ready(image_) || !info->icon.texture) { + if (!info->Ready(image_)) { 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) { + GameInfoTex *tex = GetTex(info); + if (!tex || !tex->texture) { return; } - textureWidth_ = texture->Width() * scale_; - textureHeight_ = texture->Height() * scale_; + Draw::Texture *texture = tex->texture; + + float textureWidth_ = texture->Width() * scale_; + float textureHeight_ = texture->Height() * scale_; // Fade icon with the backgrounds. double loadTime = info->icon.timeLoaded; diff --git a/UI/MiscViews.h b/UI/MiscViews.h index e7021229e4..4fed63ce60 100644 --- a/UI/MiscViews.h +++ b/UI/MiscViews.h @@ -70,9 +70,9 @@ public: std::string DescribeText() const override { return ""; } private: + GameInfoTex *GetTex(std::shared_ptr info) const; + Path gamePath_; GameInfoFlags image_; float scale_ = 1.0f; - int textureWidth_ = 0; - int textureHeight_ = 0; };