From 4ab9cdd75a6f5b2ce89eaf2a1bbaf78d0da499ab Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 15 Mar 2023 14:35:34 +0300 Subject: [PATCH 1/2] infobar: fix tiny rendering --- client/adventureMap/CInfoBar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/adventureMap/CInfoBar.cpp b/client/adventureMap/CInfoBar.cpp index 582199a9f..fdaac2f84 100644 --- a/client/adventureMap/CInfoBar.cpp +++ b/client/adventureMap/CInfoBar.cpp @@ -401,11 +401,11 @@ void CInfoBar::prepareComponents(const std::vector & components, std: // Order matters - priority form should be chosen first if(imageH + textH < CInfoBar::data_height) pushComponents(components, message, textH, false, timer); - else if(!imageH && tinyH < CInfoBar::data_height) + else if(imageH + tinyH < CInfoBar::data_height) pushComponents(components, message, tinyH, true, timer); else if(imageH + headerH < CInfoBar::data_height) pushComponents(components, header, headerH, false, timer); - else if(imageH + headerTinyH < CInfoBar::data_height - 2 * CInfoBar::offset) + else if(imageH + headerTinyH < CInfoBar::data_height) pushComponents(components, header, headerTinyH, true, timer); else pushComponents(components, "", 0, false, timer); From c497f17dd11c96d1c3a36ffb4e3a527fdc09cc7c Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 15 Mar 2023 14:35:55 +0300 Subject: [PATCH 2/2] TextControls: fix centering of the yellow text --- client/widgets/TextControls.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index e31d34647..53c69c912 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -140,6 +140,13 @@ void CTextContainer::blitLine(SDL_Surface * to, Rect destRect, std::string what) { const auto f = graphics->fonts[font]; Point where = destRect.topLeft(); + const std::string delimeters = "{}"; + auto delimitersCount = std::count_if(what.cbegin(), what.cend(), [&delimeters](char c) + { + return delimeters.find(c) != std::string::npos; + }); + //We should count delimiters length from string to correct centering later. + delimitersCount *= f->getStringWidth(delimeters)/2; // input is rect in which given text should be placed // calculate proper position for top-left corner of the text @@ -151,18 +158,17 @@ void CTextContainer::blitLine(SDL_Surface * to, Rect destRect, std::string what) if(alignment == ETextAlignment::CENTER) { - where.x += (int(destRect.w) - int(f->getStringWidth(what))) / 2; + where.x += (int(destRect.w) - int(f->getStringWidth(what) - delimitersCount)) / 2; where.y += (int(destRect.h) - int(f->getLineHeight())) / 2; } if(alignment == ETextAlignment::BOTTOMRIGHT) { - where.x += getBorderSize().x + destRect.w - (int)f->getStringWidth(what); + where.x += getBorderSize().x + destRect.w - ((int)f->getStringWidth(what) - delimitersCount); where.y += getBorderSize().y + destRect.h - (int)f->getLineHeight(); } size_t begin = 0; - std::string delimeters = "{}"; size_t currDelimeter = 0; do