mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 13:29:42 +02:00
Improve performance in Font::writeLine.
Asking FreeType for metrics before asking it for a render, when rendering would compute the metrics anyway, is wasteful. Now the width of text, for horizontal alignment purposes, is simply the width of the render.
This commit is contained in:
parent
099bd24556
commit
08fffbff6a
30
src/font.cpp
30
src/font.cpp
@ -87,17 +87,6 @@ void Font::writeLine(Surface *surface, const char *text,
|
||||
return;
|
||||
}
|
||||
|
||||
switch (halign) {
|
||||
case HAlignLeft:
|
||||
break;
|
||||
case HAlignCenter:
|
||||
x -= getTextWidth(text) / 2;
|
||||
break;
|
||||
case HAlignRight:
|
||||
x -= getTextWidth(text);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (valign) {
|
||||
case VAlignTop:
|
||||
break;
|
||||
@ -111,6 +100,21 @@ void Font::writeLine(Surface *surface, const char *text,
|
||||
|
||||
SDL_Color color = { 0, 0, 0, 0 };
|
||||
SDL_Surface *s = TTF_RenderUTF8_Blended(font, text, color);
|
||||
if (!s) {
|
||||
ERROR("Font rendering failed for text \"%s\"\n", text);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (halign) {
|
||||
case HAlignLeft:
|
||||
break;
|
||||
case HAlignCenter:
|
||||
x -= s->w / 2;
|
||||
break;
|
||||
case HAlignRight:
|
||||
x -= s->w;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Rect rect = { (Sint16) x, (Sint16) (y - 1), 0, 0 };
|
||||
SDL_BlitSurface(s, NULL, surface->raw, &rect);
|
||||
@ -137,6 +141,10 @@ void Font::writeLine(Surface *surface, const char *text,
|
||||
color.b = 0xff;
|
||||
|
||||
s = TTF_RenderUTF8_Blended(font, text, color);
|
||||
if (!s) {
|
||||
ERROR("Font rendering failed for text \"%s\"\n", text);
|
||||
return;
|
||||
}
|
||||
SDL_BlitSurface(s, NULL, surface->raw, &rect);
|
||||
SDL_FreeSurface(s);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user