mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 18:43:44 +02:00
Don't issue warnings when rendering empty string
This commit is contained in:
parent
08fffbff6a
commit
5c7ca19f4b
18
src/font.cpp
18
src/font.cpp
@ -67,7 +67,7 @@ void Font::write(Surface *surface, const string &text,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (text.find("\n", 0) == string::npos) {
|
if (text.find("\n", 0) == string::npos) {
|
||||||
writeLine(surface, text.c_str(), x, y, halign, valign);
|
writeLine(surface, text, x, y, halign, valign);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,17 +75,21 @@ void Font::write(Surface *surface, const string &text,
|
|||||||
split(v, text, "\n");
|
split(v, text, "\n");
|
||||||
|
|
||||||
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
|
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;
|
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)
|
int x, int y, HAlign halign, VAlign valign)
|
||||||
{
|
{
|
||||||
if (!font) {
|
if (!font) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (text.empty()) {
|
||||||
|
// SDL_ttf will return a nullptr when rendering the empty string.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (valign) {
|
switch (valign) {
|
||||||
case VAlignTop:
|
case VAlignTop:
|
||||||
@ -99,9 +103,9 @@ void Font::writeLine(Surface *surface, const char *text,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_Color color = { 0, 0, 0, 0 };
|
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) {
|
if (!s) {
|
||||||
ERROR("Font rendering failed for text \"%s\"\n", text);
|
ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,9 +144,9 @@ void Font::writeLine(Surface *surface, const char *text,
|
|||||||
color.g = 0xff;
|
color.g = 0xff;
|
||||||
color.b = 0xff;
|
color.b = 0xff;
|
||||||
|
|
||||||
s = TTF_RenderUTF8_Blended(font, text, color);
|
s = TTF_RenderUTF8_Blended(font, text.c_str(), color);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
ERROR("Font rendering failed for text \"%s\"\n", text);
|
ERROR("Font rendering failed for text \"%s\"\n", text.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SDL_BlitSurface(s, NULL, surface->raw, &rect);
|
SDL_BlitSurface(s, NULL, surface->raw, &rect);
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Font(TTF_Font *font);
|
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);
|
int x, int y, HAlign halign, VAlign valign);
|
||||||
|
|
||||||
TTF_Font *font;
|
TTF_Font *font;
|
||||||
|
Loading…
Reference in New Issue
Block a user