aboutsummaryrefslogtreecommitdiff
path: root/engines/drascula
diff options
context:
space:
mode:
authorFilippos Karapetis2008-09-15 13:37:28 +0000
committerFilippos Karapetis2008-09-15 13:37:28 +0000
commit7cf7f4bbf6dda265146bebafff541727b3f92a1f (patch)
tree879a64855ed56c4d6a7318bdf2b3a9e565c499c3 /engines/drascula
parent1b34b58c01789372c5a1a0bd744ccca2dafaf005 (diff)
downloadscummvm-rg350-7cf7f4bbf6dda265146bebafff541727b3f92a1f.tar.gz
scummvm-rg350-7cf7f4bbf6dda265146bebafff541727b3f92a1f.tar.bz2
scummvm-rg350-7cf7f4bbf6dda265146bebafff541727b3f92a1f.zip
Rewrote the very confusing centerText() function into something that makes more sense, and matches the way that the original printed text on screen (in most cases)
Fixes bugs #2102657 - "DRASCULA: Crash when talking to the piano player" and #2111820 - "DRASCULA: Dialog texts too long" svn-id: r34558
Diffstat (limited to 'engines/drascula')
-rw-r--r--engines/drascula/drascula.h1
-rw-r--r--engines/drascula/graphics.cpp104
2 files changed, 54 insertions, 51 deletions
diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h
index 77f9b530a7..83b99292f7 100644
--- a/engines/drascula/drascula.h
+++ b/engines/drascula/drascula.h
@@ -467,6 +467,7 @@ public:
void fadeToBlack(int fadeSpeed);
signed char adjustToVGA(signed char value);
void color_abc(int cl);
+ bool textFitsCentered(char *text, int x);
void centerText(const char *,int,int);
void playSound(int soundNum);
bool animate(const char *animation, int FPS);
diff --git a/engines/drascula/graphics.cpp b/engines/drascula/graphics.cpp
index a42bd61ee1..b1bf7f8049 100644
--- a/engines/drascula/graphics.cpp
+++ b/engines/drascula/graphics.cpp
@@ -301,63 +301,65 @@ void DrasculaEngine::print_abc_opc(const char *said, int screenY, int game) {
}
}
-// TODO: Clean this up and refactor it if possible
-void DrasculaEngine::centerText(const char *message, int textX, int textY) {
- char messageReversed[200], m2[200], m1[200], m3[200];
- char msgMultiLine[10][50]; // the resulting multiline message to be printed on screen
- int h, fil, textX3, textX2, textX1, numLines = 0;
-
- strcpy(m1, " ");
- strcpy(m2, " ");
- strcpy(m3, " ");
- strcpy(messageReversed, " ");
-
- for (h = 0; h < 10; h++)
- strcpy(msgMultiLine[h], " ");
-
- strcpy(m1, message);
- textX1 = CLIP<int>(textX, 60, 255);
-
- if (textX1 > 160)
- textX1 = 315 - textX1;
-
- while (true) {
- strcpy(messageReversed, m1);
- scumm_strrev(messageReversed);
-
- textX2 = (strlen(m1) / 2) * CHAR_WIDTH;
-
- if (textX1 < textX2) {
- strcpy(m3, strrchr(m1, ' '));
- strcpy(m1, strstr(messageReversed, " "));
- scumm_strrev(m1);
- m1[strlen(m1) - 1] = '\0';
- strcat(m3, m2);
- strcpy(m2, m3);
- };
-
- if (textX1 < textX2)
- continue;
+bool DrasculaEngine::textFitsCentered(char *text, int x) {
+ int len = strlen(text);
+ int x1 = CLIP<int>(x - len * CHAR_WIDTH / 2, 60, 255);
+ // Print up to pixel 280, not 320, to have 40 pixels space to the right
+ // This resembles the way that the original printed text on screen
+ return (x1 + len * CHAR_WIDTH) <= 280;
+}
- strcpy(msgMultiLine[numLines], m1);
+void DrasculaEngine::centerText(const char *message, int textX, int textY) {
+ char msg[200];
+ char messageLine[200];
+ char tmpMessageLine[200];
+ *messageLine = 0;
+ *tmpMessageLine = 0;
+ char *curWord;
+ int curLine = 0;
+ int x = 0;
+ int y = textY - (3 * CHAR_HEIGHT); // original starts printing 3 lines above textY
+ int len = 0;
- if (!strcmp(m2, ""))
- break;
+ strcpy(msg, message);
- scumm_strrev(m2);
- m2[strlen(m2) - 1] = '\0';
- scumm_strrev(m2);
- strcpy(m1, m2);
- strcpy(m2, "");
- numLines++;
+ // 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);
+ print_abc(msg, x, y);
+ return;
}
- fil = textY - (((numLines + 3) * CHAR_HEIGHT));
+ // Message doesn't fit on screen, split it
+
+ // Get a word from the message
+ curWord = strtok(msg, " ");
+ while (curWord != NULL) {
+ // Check if the word and the current line fit on screen
+ if (strlen(tmpMessageLine) > 0)
+ strcat(tmpMessageLine, " ");
+ strcat(tmpMessageLine, curWord);
+ if (textFitsCentered(tmpMessageLine, textX)) {
+ // Line fits, so add the word to the current message line
+ strcpy(messageLine, tmpMessageLine);
+ } else {
+ // 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);
+ strcpy(messageLine, curWord);
+ strcpy(tmpMessageLine, curWord);
+ curLine++;
+ }
- for (h = 0; h < numLines + 1; h++) {
- textX3 = strlen(msgMultiLine[h]) / 2;
- print_abc(msgMultiLine[h], (textX - textX3 * CHAR_WIDTH) - 1, fil);
- fil = fil + CHAR_HEIGHT + 2;
+ // Get next word
+ 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);
+ }
}
}