mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 17:51:34 +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
20
src/font.cpp
20
src/font.cpp
@ -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);
|
||||||
|
|
||||||
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
|
|
||||||
writeLine(surface, *it, x, y, halign, valign);
|
|
||||||
y += lineSpacing;
|
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