From e1e41d1107df050270709f9b975f1851cde4a4f5 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Wed, 30 Aug 2023 00:35:31 +0200 Subject: [PATCH] Implement TOPCENTER text alignment --- client/gui/TextAlignment.h | 2 +- client/render/Canvas.cpp | 2 ++ client/widgets/MiscWidgets.cpp | 2 +- client/widgets/TextControls.cpp | 8 ++++++++ client/windows/InfoWindows.cpp | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/gui/TextAlignment.h b/client/gui/TextAlignment.h index 8cb379e70..5c716ba31 100644 --- a/client/gui/TextAlignment.h +++ b/client/gui/TextAlignment.h @@ -9,4 +9,4 @@ */ #pragma once -enum class ETextAlignment {TOPLEFT, CENTER, BOTTOMRIGHT}; +enum class ETextAlignment {TOPLEFT, TOPCENTER, CENTER, BOTTOMRIGHT}; diff --git a/client/render/Canvas.cpp b/client/render/Canvas.cpp index dded81c9e..8a20e3d3d 100644 --- a/client/render/Canvas.cpp +++ b/client/render/Canvas.cpp @@ -149,6 +149,7 @@ void Canvas::drawText(const Point & position, const EFonts & font, const SDL_Col switch (alignment) { case ETextAlignment::TOPLEFT: return graphics->fonts[font]->renderTextLeft (surface, text, colorDest, renderArea.topLeft() + position); + case ETextAlignment::TOPCENTER: return graphics->fonts[font]->renderTextCenter(surface, text, colorDest, renderArea.topLeft() + position); case ETextAlignment::CENTER: return graphics->fonts[font]->renderTextCenter(surface, text, colorDest, renderArea.topLeft() + position); case ETextAlignment::BOTTOMRIGHT: return graphics->fonts[font]->renderTextRight (surface, text, colorDest, renderArea.topLeft() + position); } @@ -159,6 +160,7 @@ void Canvas::drawText(const Point & position, const EFonts & font, const SDL_Col switch (alignment) { case ETextAlignment::TOPLEFT: return graphics->fonts[font]->renderTextLinesLeft (surface, text, colorDest, renderArea.topLeft() + position); + case ETextAlignment::TOPCENTER: return graphics->fonts[font]->renderTextLinesCenter(surface, text, colorDest, renderArea.topLeft() + position); case ETextAlignment::CENTER: return graphics->fonts[font]->renderTextLinesCenter(surface, text, colorDest, renderArea.topLeft() + position); case ETextAlignment::BOTTOMRIGHT: return graphics->fonts[font]->renderTextLinesRight (surface, text, colorDest, renderArea.topLeft() + position); } diff --git a/client/widgets/MiscWidgets.cpp b/client/widgets/MiscWidgets.cpp index b223c962f..0fe9a83b9 100644 --- a/client/widgets/MiscWidgets.cpp +++ b/client/widgets/MiscWidgets.cpp @@ -456,7 +456,7 @@ CreatureTooltip::CreatureTooltip(Point pos, const CGCreature * creature) /*std::shared_ptr = std::make_shared(parent->pos.w / 2, 103, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, creature->getHoverText(LOCPLINT->playerID));*/ - tooltipTextbox = std::make_shared(textContent, Rect(15, 95, 230, 150), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE); + tooltipTextbox = std::make_shared(textContent, Rect(15, 95, 230, 150), 0, FONT_SMALL, ETextAlignment::TOPCENTER, Colors::WHITE); } void MoraleLuckBox::set(const AFactionMember * node) diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index 62d7ddd5d..e4e61a0c5 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -158,6 +158,12 @@ void CTextContainer::blitLine(Canvas & to, Rect destRect, std::string what) where.y += getBorderSize().y; } + if(alignment == ETextAlignment::TOPCENTER) + { + where.x += (int(destRect.w) - int(f->getStringWidth(what) - delimitersCount)) / 2; + where.y += getBorderSize().y; + } + if(alignment == ETextAlignment::CENTER) { where.x += (int(destRect.w) - int(f->getStringWidth(what) - delimitersCount)) / 2; @@ -268,6 +274,7 @@ Rect CMultiLineLabel::getTextLocation() switch(alignment) { case ETextAlignment::TOPLEFT: return Rect(pos.topLeft(), textSize); + case ETextAlignment::TOPCENTER: return Rect(pos.topLeft(), textSize); case ETextAlignment::CENTER: return Rect(pos.topLeft() + textOffset / 2, textSize); case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize); } @@ -477,6 +484,7 @@ Point CGStatusBar::getBorderSize() switch(alignment) { case ETextAlignment::TOPLEFT: return Point(borderSize.x, borderSize.y); + case ETextAlignment::TOPCENTER: return Point(pos.w / 2, borderSize.y); case ETextAlignment::CENTER: return Point(pos.w / 2, pos.h / 2); case ETextAlignment::BOTTOMRIGHT: return Point(pos.w - borderSize.x, pos.h - borderSize.y); } diff --git a/client/windows/InfoWindows.cpp b/client/windows/InfoWindows.cpp index a6d89b2d2..55d716884 100644 --- a/client/windows/InfoWindows.cpp +++ b/client/windows/InfoWindows.cpp @@ -244,6 +244,9 @@ CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, const Point &p, ETextAlignment alig case ETextAlignment::TOPLEFT: init(p.x, p.y); break; + case ETextAlignment::TOPCENTER: + init(p.x - Bitmap->w/2, p.y); + break; default: assert(0); //not implemented }