mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 06:15:21 +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:
parent
5c7ca19f4b
commit
2effd1fc99
22
src/font.cpp
22
src/font.cpp
@ -66,17 +66,19 @@ void Font::write(Surface *surface, const string &text,
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
vector<string> v;
|
||||
split(v, text, "\n");
|
||||
|
||||
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
|
||||
writeLine(surface, *it, x, y, halign, valign);
|
||||
y += lineSpacing;
|
||||
} else {
|
||||
size_t prev = 0;
|
||||
do {
|
||||
writeLine(surface, text.substr(prev, pos - prev),
|
||||
x, y, halign, valign);
|
||||
y += lineSpacing;
|
||||
prev = pos + 1;
|
||||
pos = text.find('\n', prev);
|
||||
} while (pos != string::npos);
|
||||
writeLine(surface, text.substr(prev), x, y, halign, valign);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user