mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Implement TOPCENTER text alignment
This commit is contained in:
		| @@ -9,4 +9,4 @@ | |||||||
|  */ |  */ | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| enum class ETextAlignment {TOPLEFT, CENTER, BOTTOMRIGHT}; | enum class ETextAlignment {TOPLEFT, TOPCENTER, CENTER, BOTTOMRIGHT}; | ||||||
|   | |||||||
| @@ -149,6 +149,7 @@ void Canvas::drawText(const Point & position, const EFonts & font, const SDL_Col | |||||||
| 	switch (alignment) | 	switch (alignment) | ||||||
| 	{ | 	{ | ||||||
| 	case ETextAlignment::TOPLEFT:      return graphics->fonts[font]->renderTextLeft  (surface, text, colorDest, renderArea.topLeft() + position); | 	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::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); | 	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) | 	switch (alignment) | ||||||
| 	{ | 	{ | ||||||
| 	case ETextAlignment::TOPLEFT:      return graphics->fonts[font]->renderTextLinesLeft  (surface, text, colorDest, renderArea.topLeft() + position); | 	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::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); | 	case ETextAlignment::BOTTOMRIGHT:  return graphics->fonts[font]->renderTextLinesRight (surface, text, colorDest, renderArea.topLeft() + position); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -456,7 +456,7 @@ CreatureTooltip::CreatureTooltip(Point pos, const CGCreature * creature) | |||||||
| 	/*std::shared_ptr<CLabel> = std::make_shared<CLabel>(parent->pos.w / 2, 103, | 	/*std::shared_ptr<CLabel> = std::make_shared<CLabel>(parent->pos.w / 2, 103, | ||||||
| 			FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, creature->getHoverText(LOCPLINT->playerID));*/ | 			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) | void MoraleLuckBox::set(const AFactionMember * node) | ||||||
|   | |||||||
| @@ -158,6 +158,12 @@ void CTextContainer::blitLine(Canvas & to, Rect destRect, std::string what) | |||||||
| 		where.y += getBorderSize().y; | 		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) | 	if(alignment == ETextAlignment::CENTER) | ||||||
| 	{ | 	{ | ||||||
| 		where.x += (int(destRect.w) - int(f->getStringWidth(what) - delimitersCount)) / 2; | 		where.x += (int(destRect.w) - int(f->getStringWidth(what) - delimitersCount)) / 2; | ||||||
| @@ -268,6 +274,7 @@ Rect CMultiLineLabel::getTextLocation() | |||||||
| 	switch(alignment) | 	switch(alignment) | ||||||
| 	{ | 	{ | ||||||
| 	case ETextAlignment::TOPLEFT:     return Rect(pos.topLeft(), textSize); | 	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::CENTER:      return Rect(pos.topLeft() + textOffset / 2, textSize); | ||||||
| 	case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize); | 	case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize); | ||||||
| 	} | 	} | ||||||
| @@ -477,6 +484,7 @@ Point CGStatusBar::getBorderSize() | |||||||
| 	switch(alignment) | 	switch(alignment) | ||||||
| 	{ | 	{ | ||||||
| 	case ETextAlignment::TOPLEFT:     return Point(borderSize.x, borderSize.y); | 	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::CENTER:      return Point(pos.w / 2, pos.h / 2); | ||||||
| 	case ETextAlignment::BOTTOMRIGHT: return Point(pos.w - borderSize.x, pos.h - borderSize.y); | 	case ETextAlignment::BOTTOMRIGHT: return Point(pos.w - borderSize.x, pos.h - borderSize.y); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -244,6 +244,9 @@ CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, const Point &p, ETextAlignment alig | |||||||
| 	case ETextAlignment::TOPLEFT: | 	case ETextAlignment::TOPLEFT: | ||||||
| 		init(p.x, p.y); | 		init(p.x, p.y); | ||||||
| 		break; | 		break; | ||||||
|  | 	case ETextAlignment::TOPCENTER: | ||||||
|  | 		init(p.x - Bitmap->w/2, p.y); | ||||||
|  | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		assert(0); //not implemented | 		assert(0); //not implemented | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user