Fix graphical bug when drawing inline sprites caused by using strlen instead of get_string_length

This commit is contained in:
Duncan Frost 2014-09-15 20:47:42 +01:00
parent 9aee80e5a6
commit 7c6a35af7a
3 changed files with 58 additions and 2 deletions

View File

@ -1819,7 +1819,7 @@ int gfx_draw_string_centred_wrapped(rct_drawpixelinfo *dpi, void *args, int x, i
int half_width = gfx_get_string_width(buffer) / 2;
gfx_draw_string(dpi, buffer, 0xFE, x - half_width, line_y);
buffer += strlen(buffer) + 1;
buffer += get_string_length(buffer) + 1;
line_y += line_height;
}
@ -1874,7 +1874,7 @@ int gfx_draw_string_left_wrapped(rct_drawpixelinfo *dpi, void *args, int x, int
for (int line = 0; line <= num_lines; ++line) {
gfx_draw_string(dpi, buffer, 0xFE, x, line_y);
buffer += strlen(buffer) + 1;
buffer += get_string_length(buffer) + 1;
line_y += line_height;
}

View File

@ -1691,4 +1691,59 @@ void reset_saved_strings() {
for (int i = 0; i < 1024; i++) {
RCT2_ADDRESS(0x135A8F4, uint8)[i * 32] = 0;
}
}
/**
* Return the length of the string in buffer.
* note you can't use strlen as there can be inline sprites!
*
* buffer (esi)
*/
int get_string_length(char* buffer)
{
// Length of string
int length = 0;
for (uint8* curr_char = (uint8*)buffer; *curr_char != (uint8)0; curr_char++) {
length++;
if (*curr_char >= 0x20) {
continue;
}
switch (*curr_char) {
case FORMAT_MOVE_X:
case FORMAT_ADJUST_PALETTE:
case 3:
case 4:
curr_char++;
length++;
break;
case FORMAT_NEWLINE:
case FORMAT_NEWLINE_SMALLER:
case FORMAT_TINYFONT:
case FORMAT_BIGFONT:
case FORMAT_MEDIUMFONT:
case FORMAT_SMALLFONT:
case FORMAT_OUTLINE:
case FORMAT_OUTLINE_OFF:
case FORMAT_WINDOW_COLOUR_1:
case FORMAT_WINDOW_COLOUR_2:
case FORMAT_WINDOW_COLOUR_3:
case 0x10:
continue;
case FORMAT_INLINE_SPRITE:
length += 4;
curr_char += 4;
break;
default:
if (*curr_char <= 0x16) { //case 0x11? FORMAT_NEW_LINE_X_Y
length += 2;
curr_char += 2;
continue;
}
length += 4;
curr_char += 4;//never happens?
break;
}
}
return length;
}

View File

@ -30,6 +30,7 @@ void error_string_quit(int error, rct_string_id format);
char format_get_code(const char *token);
const char *format_get_token(char code);
int get_string_length(char* buffer);
enum {
// Font format codes