fix drawing of 2x2 items on UIItem

This commit is contained in:
Eduardo Bart 2012-04-09 16:33:40 -03:00
parent 2017fb366e
commit 353aa5215e
1 changed files with 6 additions and 2 deletions

View File

@ -36,16 +36,20 @@ void UIItem::drawSelf()
if(m_item) { if(m_item) {
Rect drawRect = getClippingRect(); Rect drawRect = getClippingRect();
float scaleFactor = std::min(drawRect.width() / 32.0f, drawRect.height() / 32.0f); Point dest = drawRect.topLeft();
float scaleFactor = std::min(drawRect.width() / (float)m_item->getExactSize(), drawRect.height() / (float)m_item->getExactSize());
dest += (1 - scaleFactor)*32;
dest += m_item->getDisplacement() * scaleFactor;
g_painter.setColor(Color::white); g_painter.setColor(Color::white);
m_item->draw(drawRect.topLeft(), scaleFactor, true); m_item->draw(dest, scaleFactor, true);
if(m_font && m_item->isStackable() && m_item->getCount() > 1) { if(m_font && m_item->isStackable() && m_item->getCount() > 1) {
std::string count = Fw::tostring(m_item->getCount()); std::string count = Fw::tostring(m_item->getCount());
g_painter.setColor(Color(231, 231, 231)); g_painter.setColor(Color(231, 231, 231));
m_font->drawText(count, Rect(m_rect.topLeft(), m_rect.bottomRight() - Point(3, 0)), Fw::AlignBottomRight); m_font->drawText(count, Rect(m_rect.topLeft(), m_rect.bottomRight() - Point(3, 0)), Fw::AlignBottomRight);
} }
//m_font->drawText(Fw::tostring(m_item->getId()), m_rect, Fw::AlignBottomRight);
} }
} }