mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-23 02:44:56 +00:00
parent
4165e1ceb4
commit
897f1bb479
@ -306,6 +306,7 @@ bool FontRenderer::drawStringWrap(const char * str, char * buffer, const Point &
|
||||
}
|
||||
|
||||
bool FontRenderer::drawStringWrapCentered(const char * str, char * buffer, const Point & size, int32 x, int32 y, int32 width) const {
|
||||
int32 max_substr_width = 0;
|
||||
debug(9, "FontRenderer::drawStringWrapCentered(%s, %d, %d)", str, x, y);
|
||||
assert(strchr(str, '\n') == 0);
|
||||
char * * words = split(str, ' ');
|
||||
@ -324,13 +325,14 @@ bool FontRenderer::drawStringWrapCentered(const char * str, char * buffer, const
|
||||
int32 space_width = charWidth(' ');
|
||||
|
||||
i = 0;
|
||||
width = MIN(width, size.getX());
|
||||
while(i < nb_sub) {
|
||||
int32 substr_width = sizes[i];
|
||||
char * substr = new char[1000];
|
||||
strcpy(substr, words[i]);
|
||||
int32 j = i + 1;
|
||||
|
||||
while(j < nb_sub && (substr_width + space_width + sizes[j]) < size.getX()) {
|
||||
while(j < nb_sub && (substr_width + space_width + sizes[j]) < width) {
|
||||
substr_width += sizes[j++] + space_width;
|
||||
}
|
||||
|
||||
@ -341,6 +343,7 @@ bool FontRenderer::drawStringWrapCentered(const char * str, char * buffer, const
|
||||
|
||||
substrings[nb_subs] = substr;
|
||||
substr_widths[nb_subs++] = substr_width;
|
||||
max_substr_width = MAX(substr_width, max_substr_width);
|
||||
i = j;
|
||||
height += stringHeight(substr);
|
||||
}
|
||||
@ -355,6 +358,12 @@ bool FontRenderer::drawStringWrapCentered(const char * str, char * buffer, const
|
||||
y = size.getY() - height;
|
||||
}
|
||||
|
||||
if(x - max_substr_width / 2 < 0) {
|
||||
x = max_substr_width / 2;
|
||||
} else if (x + max_substr_width / 2 >= size.getX()) {
|
||||
x = size.getX() - 1 - max_substr_width / 2;
|
||||
}
|
||||
|
||||
for(i = 0; i < nb_subs; i++) {
|
||||
int32 substr_width = substr_widths[i];
|
||||
drawSubstring((const byte *)substrings[i], buffer, size, x - substr_width / 2, y);
|
||||
|
Loading…
x
Reference in New Issue
Block a user