1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-07 23:02:07 +00:00

Add Lua function text_getStringWidth()

This commit is contained in:
fgenesis 2015-03-08 20:43:41 +01:00
commit b70de7f94b
6 changed files with 53 additions and 1 deletions

View file

@ -425,6 +425,30 @@ int BitmapText::getNumLines()
return lines.size();
}
float BitmapText::getStringWidth(const std::string& text)
{
std::string tmp;
int maxsize = 0;
tmp.reserve(text.length());
for (size_t i = 0; i < text.size(); i++)
{
if(text[i] == '\n')
{
std::pair<int, int> dim;
bmpFont->font.GetStringSize(tmp, &dim);
maxsize = std::max(maxsize, dim.first);
tmp.resize(0);
}
else
tmp += text[i];
}
std::pair<int, int> dim;
bmpFont->font.GetStringSize(tmp, &dim);
maxsize = std::max(maxsize, dim.first);
return maxsize * bmpFont->scale;
}
/*
BitmapText::BitmapText() : RenderObject()
{