From 227a75cac3eaf28b5f58a7a8093a17ccca88dec2 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Sun, 16 Feb 2025 06:03:25 -0700 Subject: [PATCH] Add `mStructureIcons` field to `FactoryListBox` --- appOPHD/UI/FactoryListBox.cpp | 15 +++++---------- appOPHD/UI/FactoryListBox.h | 3 +++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/appOPHD/UI/FactoryListBox.cpp b/appOPHD/UI/FactoryListBox.cpp index 8f5cd4b9c..637e722ba 100644 --- a/appOPHD/UI/FactoryListBox.cpp +++ b/appOPHD/UI/FactoryListBox.cpp @@ -19,13 +19,7 @@ using namespace NAS2D; -namespace -{ - const Image* STRUCTURE_ICONS = nullptr; -} - - -static void drawItem(Renderer& renderer, const NAS2D::Font& font, const NAS2D::Font& fontBold, FactoryListBox::FactoryListBoxItem& item, NAS2D::Rectangle rect, bool highlight) +static void drawItem(Renderer& renderer, const NAS2D::Font& font, const NAS2D::Font& fontBold, const NAS2D::Image& structureIcons, FactoryListBox::FactoryListBoxItem& item, NAS2D::Rectangle rect, bool highlight) { Factory* f = item.factory; @@ -40,7 +34,7 @@ static void drawItem(Renderer& renderer, const NAS2D::Font& font, const NAS2D::F renderer.drawBox(rect.inset(2), structureColor); const auto subImageRect = NAS2D::Rectangle{item.icon_slice, {46, 46}}; - renderer.drawSubImage(*STRUCTURE_ICONS, rect.position + NAS2D::Vector{8, 8}, subImageRect, NAS2D::Color::White.alphaFade(structureColor.alpha)); + renderer.drawSubImage(structureIcons, rect.position + NAS2D::Vector{8, 8}, subImageRect, NAS2D::Color::White.alphaFade(structureColor.alpha)); renderer.drawText(fontBold, f->name(), rect.position + NAS2D::Vector{64, 29 - fontBold.height() / 2}, structureTextColor); if (productType != ProductType::PRODUCT_NONE) { @@ -59,10 +53,10 @@ FactoryListBox::FactoryListBox() : ListBoxBase{ fontCache.load(constants::FONT_PRIMARY, 12), fontCache.load(constants::FONT_PRIMARY_BOLD, 12) - } + }, + mStructureIcons{imageCache.load("ui/structures.png")} { itemHeight(58); - STRUCTURE_ICONS = &imageCache.load("ui/structures.png"); } @@ -135,6 +129,7 @@ void FactoryListBox::update() renderer, mFont, mFontBold, + mStructureIcons, *static_cast(mItems[i]), { {positionX(), diff --git a/appOPHD/UI/FactoryListBox.h b/appOPHD/UI/FactoryListBox.h index 25f20b795..975b93fa7 100644 --- a/appOPHD/UI/FactoryListBox.h +++ b/appOPHD/UI/FactoryListBox.h @@ -39,4 +39,7 @@ class FactoryListBox : public ListBoxBase Factory* selectedFactory(); void update() override; + +private: + const NAS2D::Image& mStructureIcons; };