[Scummvm-cvs-logs] SF.net SVN: scummvm:[34558] scummvm/trunk/engines/drascula
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Mon Sep 15 15:37:31 CEST 2008
Revision: 34558
http://scummvm.svn.sourceforge.net/scummvm/?rev=34558&view=rev
Author: thebluegr
Date: 2008-09-15 13:37:28 +0000 (Mon, 15 Sep 2008)
Log Message:
-----------
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"
Modified Paths:
--------------
scummvm/trunk/engines/drascula/drascula.h
scummvm/trunk/engines/drascula/graphics.cpp
Modified: scummvm/trunk/engines/drascula/drascula.h
===================================================================
--- scummvm/trunk/engines/drascula/drascula.h 2008-09-15 12:37:24 UTC (rev 34557)
+++ scummvm/trunk/engines/drascula/drascula.h 2008-09-15 13:37:28 UTC (rev 34558)
@@ -467,6 +467,7 @@
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);
Modified: scummvm/trunk/engines/drascula/graphics.cpp
===================================================================
--- scummvm/trunk/engines/drascula/graphics.cpp 2008-09-15 12:37:24 UTC (rev 34557)
+++ scummvm/trunk/engines/drascula/graphics.cpp 2008-09-15 13:37:28 UTC (rev 34558)
@@ -301,64 +301,66 @@
}
}
-// TODO: Clean this up and refactor it if possible
+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;
+}
+
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;
+ 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;
- strcpy(m1, " ");
- strcpy(m2, " ");
- strcpy(m3, " ");
- strcpy(messageReversed, " ");
+ strcpy(msg, message);
- for (h = 0; h < 10; h++)
- strcpy(msgMultiLine[h], " ");
+ // 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;
+ }
- strcpy(m1, message);
- textX1 = CLIP<int>(textX, 60, 255);
+ // Message doesn't fit on screen, split it
- if (textX1 > 160)
- textX1 = 315 - textX1;
+ // 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++;
+ }
- while (true) {
- strcpy(messageReversed, m1);
- scumm_strrev(messageReversed);
+ // Get next word
+ curWord = strtok (NULL, " ");
- 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;
-
- strcpy(msgMultiLine[numLines], m1);
-
- if (!strcmp(m2, ""))
- break;
-
- scumm_strrev(m2);
- m2[strlen(m2) - 1] = '\0';
- scumm_strrev(m2);
- strcpy(m1, m2);
- strcpy(m2, "");
- numLines++;
+ if (curWord == NULL) {
+ x = CLIP<int>(textX - strlen(messageLine) * CHAR_WIDTH / 2, 60, 255);
+ print_abc(messageLine, x, y + curLine * CHAR_HEIGHT);
+ }
}
-
- fil = textY - (((numLines + 3) * CHAR_HEIGHT));
-
- 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;
- }
}
void DrasculaEngine::screenSaver() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list