1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-24 19:25:30 +02:00

Don't issue warnings when rendering empty string

This commit is contained in:
Maarten ter Huurne 2014-07-18 04:26:48 +02:00
parent 08fffbff6a
commit 5c7ca19f4b
2 changed files with 12 additions and 8 deletions

View File

@ -67,7 +67,7 @@ void Font::write(Surface *surface, const string &text,
}
if (text.find("\n", 0) == string::npos) {
writeLine(surface, text.c_str(), x, y, halign, valign);
writeLine(surface, text, x, y, halign, valign);
return;
}
@ -75,17 +75,21 @@ void Font::write(Surface *surface, const string &text,
split(v, text, "\n");
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
writeLine(surface, it->c_str(), x, y, halign, valign);
writeLine(surface, *it, x, y, halign, valign);
y += lineSpacing;
}
}
void Font::writeLine(Surface *surface, const char *text,
void Font::writeLine(Surface *surface, std::string const& text,
int x, int y, HAlign halign, VAlign valign)
{
if (!font) {
return;
}
if (text.empty()) {
// SDL_ttf will return a nullptr when rendering the empty string.
return;
}
switch (valign) {
case VAlignTop:
@ -99,9 +103,9 @@ void Font::writeLine(Surface *surface, const char *text,
}
SDL_Color color = { 0, 0, 0, 0 };
SDL_Surface *s = TTF_RenderUTF8_Blended(font, text, color);
SDL_Surface *s = TTF_RenderUTF8_Blended(font, text.c_str(), color);
if (!s) {
ERROR("Font rendering failed for text \"%s\"\n", text);
ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
return;
}
@ -140,9 +144,9 @@ void Font::writeLine(Surface *surface, const char *text,
color.g = 0xff;
color.b = 0xff;
s = TTF_RenderUTF8_Blended(font, text, color);
s = TTF_RenderUTF8_Blended(font, text.c_str(), color);
if (!s) {
ERROR("Font rendering failed for text \"%s\"\n", text);
ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
return;
}
SDL_BlitSurface(s, NULL, surface->raw, &rect);

View File

@ -41,7 +41,7 @@ public:
private:
Font(TTF_Font *font);
void writeLine(Surface *surface, const char *text,
void writeLine(Surface *surface, std::string const& text,
int x, int y, HAlign halign, VAlign valign);
TTF_Font *font;