1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 12:09:41 +02:00

Made multi-line text drawing more efficient

Instead of splitting everything at once, split off one line at a time.
The code could be more compact but I want to avoid using substr on the
very common special case when a string contains no newlines.
This commit is contained in:
Maarten ter Huurne 2014-07-18 05:03:57 +02:00
parent 5c7ca19f4b
commit 2effd1fc99

View File

@ -66,17 +66,19 @@ void Font::write(Surface *surface, const string &text,
return; return;
} }
if (text.find("\n", 0) == string::npos) { size_t pos = text.find('\n', 0);
if (pos == string::npos) {
writeLine(surface, text, x, y, halign, valign); writeLine(surface, text, x, y, halign, valign);
return; } else {
} size_t prev = 0;
do {
vector<string> v; writeLine(surface, text.substr(prev, pos - prev),
split(v, text, "\n"); x, y, halign, valign);
y += lineSpacing;
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) { prev = pos + 1;
writeLine(surface, *it, x, y, halign, valign); pos = text.find('\n', prev);
y += lineSpacing; } while (pos != string::npos);
writeLine(surface, text.substr(prev), x, y, halign, valign);
} }
} }