1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-02 09:02:03 +02:00
vcmi/client/render/IFont.cpp
Ivan Savenko 1aa391fdf8 Split CGeneralTextHandler file into 1 file per class form
All text processing code is now located in lib/texts.
No changes other than code being moved around and adjustment of includes

Moved without changes:
Languages.h           -> texts/Languages.h
MetaString.*          -> texts/MetaString.*
TextOperations.*      -> texts/TextOperations.*

Split into parts:
CGeneralTextHandler.* -> texts/CGeneralTextHandler.*
                      -> texts/CLegacyConfigParser.*
                      -> texts/TextLocalizationContainer.*
                      -> texts/TextIdentifier.h
2024-07-20 12:55:17 +00:00

80 lines
2.2 KiB
C++

/*
* IFont.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "IFont.h"
#include "../../lib/Point.h"
#include "../../lib/texts/TextOperations.h"
size_t IFont::getStringWidth(const std::string & data) const
{
size_t width = 0;
for(size_t i=0; i<data.size(); i += TextOperations::getUnicodeCharacterSize(data[i]))
{
width += getGlyphWidth(data.data() + i);
}
return width;
}
void IFont::renderTextLeft(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
{
renderText(surface, data, color, pos);
}
void IFont::renderTextRight(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
{
Point size((int)getStringWidth(data), (int)getLineHeight());
renderText(surface, data, color, pos - size);
}
void IFont::renderTextCenter(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
{
Point size((int)getStringWidth(data), (int)getLineHeight());
renderText(surface, data, color, pos - size / 2);
}
void IFont::renderTextLinesLeft(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
{
Point currPos = pos;
for(const std::string & line : data)
{
renderTextLeft(surface, line, color, currPos);
currPos.y += (int)getLineHeight();
}
}
void IFont::renderTextLinesRight(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
{
Point currPos = pos;
currPos.y -= (int)data.size() * (int)getLineHeight();
for(const std::string & line : data)
{
renderTextRight(surface, line, color, currPos);
currPos.y += (int)getLineHeight();
}
}
void IFont::renderTextLinesCenter(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
{
Point currPos = pos;
currPos.y -= (int)data.size() * (int)getLineHeight() / 2;
for(const std::string & line : data)
{
renderTextCenter(surface, line, color, currPos);
currPos.y += (int)getLineHeight();
}
}