From d20e8e1a820dae003f8a5499cef61a6d807e19f6 Mon Sep 17 00:00:00 2001 From: Jonek Date: Wed, 6 Nov 2024 21:44:10 +0100 Subject: [PATCH] Display big items in UI more conviniently (#18) --- src/client/thingtype.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/client/thingtype.cpp b/src/client/thingtype.cpp index deeafd0..eaf4fa2 100644 --- a/src/client/thingtype.cpp +++ b/src/client/thingtype.cpp @@ -563,16 +563,19 @@ DrawQueueItem* ThingType::draw(const Rect& dest, int layer, int xPattern, int yP if (!size.isValid()) return nullptr; - // size correction for some too big items - if ((m_size.width() > 1 || m_size.height() > 1) && - textureRect.width() <= g_sprites.spriteSize() && textureRect.height() <= g_sprites.spriteSize()) { - size = Size(g_sprites.spriteSize(), g_sprites.spriteSize()); - textureOffset = Point((g_sprites.spriteSize() - textureRect.width()) / m_size.width(), - (g_sprites.spriteSize() - textureRect.height()) / m_size.height()); + float scaleX = (float)dest.width() / size.width(); + float scaleY = (float)dest.height() / size.height(); + Size finalDrawSize = textureRect.size(); + if (scaleX < 1) { + textureOffset.x = 0; + finalDrawSize.setWidth(dest.width()); + } + if (scaleY < 1) { + textureOffset.y = 0; + finalDrawSize.setHeight(dest.height()); } - float scale = std::min((float)dest.width() / size.width(), (float)dest.height() / size.height()); - return g_drawQueue->addTexturedRect(Rect(dest.topLeft() + (textureOffset * scale), textureRect.size() * scale), texture, textureRect, color); + return g_drawQueue->addTexturedRect(Rect(dest.topLeft() + textureOffset, finalDrawSize), texture, textureRect, color); } std::shared_ptr ThingType::drawOutfit(const Point& dest, int maskLayer, int xPattern, int yPattern, int zPattern, int animationPhase, Color color, LightView* lightView)