Forráskód Böngészése

Implement TOPCENTER text alignment

Dydzio 2 éve
szülő
commit
e1e41d1107

+ 1 - 1
client/gui/TextAlignment.h

@@ -9,4 +9,4 @@
  */
 #pragma once
 
-enum class ETextAlignment {TOPLEFT, CENTER, BOTTOMRIGHT};
+enum class ETextAlignment {TOPLEFT, TOPCENTER, CENTER, BOTTOMRIGHT};

+ 2 - 0
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);
 	}

+ 1 - 1
client/widgets/MiscWidgets.cpp

@@ -456,7 +456,7 @@ CreatureTooltip::CreatureTooltip(Point pos, const CGCreature * creature)
 	/*std::shared_ptr<CLabel> = std::make_shared<CLabel>(parent->pos.w / 2, 103,
 			FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, creature->getHoverText(LOCPLINT->playerID));*/
 
-	tooltipTextbox = std::make_shared<CTextBox>(textContent, Rect(15, 95, 230, 150), 0, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
+	tooltipTextbox = std::make_shared<CTextBox>(textContent, Rect(15, 95, 230, 150), 0, FONT_SMALL, ETextAlignment::TOPCENTER, Colors::WHITE);
 }
 
 void MoraleLuckBox::set(const AFactionMember * node)

+ 8 - 0
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);
 	}

+ 3 - 0
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
 	}