Skip to content

Commit

Permalink
Add mStructureIcons field to FactoryListBox
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRStevens committed Feb 16, 2025
1 parent f451143 commit 227a75c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 5 additions & 10 deletions appOPHD/UI/FactoryListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<int> rect, bool highlight)
{
Factory* f = item.factory;

Expand All @@ -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)
{
Expand All @@ -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");
}


Expand Down Expand Up @@ -135,6 +129,7 @@ void FactoryListBox::update()
renderer,
mFont,
mFontBold,
mStructureIcons,
*static_cast<FactoryListBoxItem*>(mItems[i]),
{
{positionX(),
Expand Down
3 changes: 3 additions & 0 deletions appOPHD/UI/FactoryListBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ class FactoryListBox : public ListBoxBase
Factory* selectedFactory();

void update() override;

private:
const NAS2D::Image& mStructureIcons;
};

0 comments on commit 227a75c

Please sign in to comment.