color item icon backgrounds in the UI from visuals.toml
This commit is contained in:
@@ -541,37 +541,14 @@ void WorldRenderer::drawPortItems(QPainter& painter, const WorldCoordinates& coo
|
||||
void WorldRenderer::drawWorldItem(QPainter& painter, const std::string& itemId,
|
||||
QPointF center, float halfPx)
|
||||
{
|
||||
if (!m_itemIcons) { return; }
|
||||
|
||||
// The colored square carrying the item's icon (REQ-GW-TILE-SIZE, REQ-UI-ITEM-ICON).
|
||||
// The composition lives in the icon cache, which draws it the same way here and in
|
||||
// the UI's item displays, so an item reads the same on a belt as in a panel.
|
||||
const QRectF itemRect(center.x() - halfPx, center.y() - halfPx,
|
||||
halfPx * 2, halfPx * 2);
|
||||
|
||||
// The colored square from visuals.toml (REQ-GW-TILE-SIZE) backs every item, icon or
|
||||
// not: it is what gives the item contrast against the tile beneath it, and its dark
|
||||
// outline is what separates neighbouring items where they overlap on a belt.
|
||||
const std::map<std::string, ItemVisuals>::const_iterator it =
|
||||
m_visuals.items.find(itemId);
|
||||
if (it != m_visuals.items.end())
|
||||
{
|
||||
painter.fillRect(itemRect, it->second.fill);
|
||||
painter.setPen(QPen(it->second.outline, 1));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawRect(itemRect);
|
||||
}
|
||||
|
||||
if (!m_itemIcons || !m_itemIcons->hasIcon(itemId)) { return; }
|
||||
|
||||
// The icon goes on top, inset so a frame of the square's color stays visible all
|
||||
// around it (REQ-UI-ITEM-ICON). The inset is needed because each icon's viewBox is
|
||||
// cropped tight to its artwork: drawn at the full rect, a solid icon would cover the
|
||||
// square entirely. It is rasterized once at the inset pixel size and cached, so this
|
||||
// is a plain pixmap blit per frame.
|
||||
constexpr double kIconInsetFraction = 0.15;
|
||||
const double inset = kIconInsetFraction * static_cast<double>(halfPx * 2.0f);
|
||||
const QRectF iconRect = itemRect.adjusted(inset, inset, -inset, -inset);
|
||||
|
||||
int sizePx = qRound(iconRect.width());
|
||||
if (sizePx < 1) { sizePx = 1; }
|
||||
painter.drawPixmap(iconRect, m_itemIcons->getPixmap(itemId, sizePx),
|
||||
QRectF(0, 0, sizePx, sizePx));
|
||||
m_itemIcons->paintItem(painter, itemRect, itemId);
|
||||
}
|
||||
|
||||
void WorldRenderer::drawBeltItems(QPainter& painter, const WorldCoordinates& coordinates,
|
||||
|
||||
Reference in New Issue
Block a user