aboutsummaryrefslogtreecommitdiff
path: root/engines/drascula
diff options
context:
space:
mode:
authorThierry Crozat2016-04-07 01:35:50 +0100
committerThierry Crozat2016-04-07 01:36:23 +0100
commita7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6 (patch)
tree62a7b2c6a687518f3fc22954e826be01dbd43d2a /engines/drascula
parent1cbab62211b24e265da0eff4c8e16c83b3e3953f (diff)
downloadscummvm-rg350-a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6.tar.gz
scummvm-rg350-a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6.tar.bz2
scummvm-rg350-a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6.zip
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.
Diffstat (limited to 'engines/drascula')
-rw-r--r--engines/drascula/graphics.cpp21
1 files changed, 12 insertions, 9 deletions
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<int>(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<int>(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<int>(textX - strlen(msg) * CHAR_WIDTH / 2, 60, 255);
+ x = CLIP<int>(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<int>(textX - len * CHAR_WIDTH / 2, 0, 319 - len * CHAR_WIDTH);
+ x = CLIP<int>(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<int>(textX - strlen(messageLine) * CHAR_WIDTH / 2, 60, 255);
- print_abc(messageLine, x, y + curLine * CHAR_HEIGHT);
+ x = CLIP<int>(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<int>(textX - strlen(messageLine) * CHAR_WIDTH / 2, 60, 255);
- print_abc(messageLine, x, y + curLine * CHAR_HEIGHT);
+ x = CLIP<int>(textX, 60, 259) - strlen(messageLine) * CHAR_WIDTH / 2;
+ print_abc(messageLine, x, y + curLine * (CHAR_HEIGHT + 2));
}
}
}