2023-02-01 15:42:21 +02:00
|
|
|
/*
|
2023-02-01 16:42:03 +02:00
|
|
|
* IFont.cpp, part of VCMI engine
|
2023-02-01 15:42:21 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "IFont.h"
|
2023-02-01 15:42:21 +02:00
|
|
|
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../../lib/Point.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../lib/texts/TextOperations.h"
|
2023-02-01 15:42:21 +02:00
|
|
|
|
|
|
|
size_t IFont::getStringWidth(const std::string & data) const
|
|
|
|
{
|
|
|
|
size_t width = 0;
|
|
|
|
|
2023-02-12 23:52:35 +02:00
|
|
|
for(size_t i=0; i<data.size(); i += TextOperations::getUnicodeCharacterSize(data[i]))
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
width += getGlyphWidth(data.data() + i);
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
void IFont::renderTextLeft(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
renderText(surface, data, color, pos);
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
void IFont::renderTextRight(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
Point size((int)getStringWidth(data), (int)getLineHeight());
|
|
|
|
renderText(surface, data, color, pos - size);
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
void IFont::renderTextCenter(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
Point size((int)getStringWidth(data), (int)getLineHeight());
|
|
|
|
renderText(surface, data, color, pos - size / 2);
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
void IFont::renderTextLinesLeft(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
Point currPos = pos;
|
|
|
|
|
|
|
|
for(const std::string & line : data)
|
|
|
|
{
|
|
|
|
renderTextLeft(surface, line, color, currPos);
|
|
|
|
currPos.y += (int)getLineHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
void IFont::renderTextLinesRight(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
void IFont::renderTextLinesCenter(SDL_Surface * surface, const std::vector<std::string> & data, const ColorRGBA & color, const Point & pos) const
|
2023-02-01 15:42:21 +02:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|