From a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Thu, 7 Apr 2016 01:35:50 +0100 Subject: DRASCULA: Improve text centering and spacing between lines This in particular fixes bug #7111: Incorrect position in texts, not as the original. However this codes centers the text better than what we see in DosBox, so the result is not identical. This change is based on the code before the commit 7cf7f4b "Rewrote the very confusing centerText() function into something that makes more sense". The changes in that commit do not all make sense to me so I reverted the line spacing (to add back 2 pixels between text lines) and part of the logic to center text. The result looks a lot closer to the original engine in DosBox, but not identical. --- engines/drascula/graphics.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'engines/drascula') diff --git a/engines/drascula/graphics.cpp b/engines/drascula/graphics.cpp index 077047a6eb..5e37d2c3b0 100644 --- a/engines/drascula/graphics.cpp +++ b/engines/drascula/graphics.cpp @@ -319,9 +319,12 @@ int DrasculaEngine::print_abc_opc(const char *said, int screenY, int game) { } bool DrasculaEngine::textFitsCentered(char *text, int x) { - int len = strlen(text); - int tmp = CLIP(x - len * CHAR_WIDTH / 2, 60, 255); - return (tmp + len * CHAR_WIDTH) <= 320; + int half_len = strlen(text) * CHAR_WIDTH / 2; + // Clip center between 60 and 255 + x = CLIP(x, 60, 259); + // We want a text centered on x thats fits on screen + // CHAR_WIDTH is even so x - length / 2 + length is always equal to x + length / 2 + return (x - half_len >= 2 && x + half_len <= 317); } void DrasculaEngine::centerText(const char *message, int textX, int textY) { @@ -340,7 +343,7 @@ void DrasculaEngine::centerText(const char *message, int textX, int textY) { // If the message fits on screen as-is, just print it here if (textFitsCentered(msg, textX)) { - x = CLIP(textX - strlen(msg) * CHAR_WIDTH / 2, 60, 255); + x = CLIP(textX, 60, 259) - strlen(msg) * CHAR_WIDTH / 2; print_abc(msg, x, y); return; } @@ -351,7 +354,7 @@ void DrasculaEngine::centerText(const char *message, int textX, int textY) { // with the German translation. if (!strchr(msg, ' ')) { int len = strlen(msg); - x = CLIP(textX - len * CHAR_WIDTH / 2, 0, 319 - len * CHAR_WIDTH); + x = CLIP(textX - len * CHAR_WIDTH / 2, 2, 317 - len * CHAR_WIDTH); print_abc(msg, x, y); return; } @@ -372,8 +375,8 @@ void DrasculaEngine::centerText(const char *message, int textX, int textY) { // Line doesn't fit, so show the current line on screen and // create a new one // If it goes off screen, print_abc will adjust it - x = CLIP(textX - strlen(messageLine) * CHAR_WIDTH / 2, 60, 255); - print_abc(messageLine, x, y + curLine * CHAR_HEIGHT); + x = CLIP(textX, 60, 259) - strlen(messageLine) * CHAR_WIDTH / 2; + print_abc(messageLine, x, y + curLine * (CHAR_HEIGHT + 2)); Common::strlcpy(messageLine, curWord, 200); Common::strlcpy(tmpMessageLine, curWord, 200); curLine++; @@ -383,8 +386,8 @@ void DrasculaEngine::centerText(const char *message, int textX, int textY) { curWord = strtok(NULL, " "); if (curWord == NULL) { - x = CLIP(textX - strlen(messageLine) * CHAR_WIDTH / 2, 60, 255); - print_abc(messageLine, x, y + curLine * CHAR_HEIGHT); + x = CLIP(textX, 60, 259) - strlen(messageLine) * CHAR_WIDTH / 2; + print_abc(messageLine, x, y + curLine * (CHAR_HEIGHT + 2)); } } } -- cgit v1.2.3