[Scummvm-cvs-logs] SF.net SVN: scummvm:[34570] scummvm/branches/branch-0-12-0/engines/drascula
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Tue Sep 16 09:25:28 CEST 2008
Revision: 34570
http://scummvm.svn.sourceforge.net/scummvm/?rev=34570&view=rev
Author: thebluegr
Date: 2008-09-16 07:25:27 +0000 (Tue, 16 Sep 2008)
Log Message:
-----------
Backported the changes to centerText()
Modified Paths:
--------------
scummvm/branches/branch-0-12-0/engines/drascula/drascula.h
scummvm/branches/branch-0-12-0/engines/drascula/graphics.cpp
Modified: scummvm/branches/branch-0-12-0/engines/drascula/drascula.h
===================================================================
--- scummvm/branches/branch-0-12-0/engines/drascula/drascula.h 2008-09-16 07:16:26 UTC (rev 34569)
+++ scummvm/branches/branch-0-12-0/engines/drascula/drascula.h 2008-09-16 07:25:27 UTC (rev 34570)
@@ -399,6 +399,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/branches/branch-0-12-0/engines/drascula/graphics.cpp
===================================================================
--- scummvm/branches/branch-0-12-0/engines/drascula/graphics.cpp 2008-09-16 07:16:26 UTC (rev 34569)
+++ scummvm/branches/branch-0-12-0/engines/drascula/graphics.cpp 2008-09-16 07:25:27 UTC (rev 34570)
@@ -300,70 +300,64 @@
}
}
+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;
+}
+
void DrasculaEngine::centerText(const char *message, int textX, int textY) {
- char bb[200], m2[200], m1[200], mb[10][50];
- char m3[200];
- int h, fil, textX3, textX2, textX1, conta_f = 0, ya = 0;
+ char msg[200];
+ char messageLine[200];
+ char tmpMessageLine[200];
+ *messageLine = 0;
+ *tmpMessageLine = 0;
+ char *curWord;
+ int curLine = 0;
+ int x = 0;
+ // original starts printing 4 lines above textY
+ int y = CLIP<int>(textY - (4 * CHAR_HEIGHT), 0, 320);
- strcpy(m1, " ");
- strcpy(m2, " ");
- strcpy(m3, " ");
- strcpy(bb, " ");
+ strcpy(msg, message);
- for (h = 0; h < 10; h++)
- strcpy(mb[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;
+ }
- if (textX > 160)
- ya = 1;
+ // Message doesn't fit on screen, split it
- strcpy(m1, message);
- textX = CLIP<int>(textX, 60, 255);
+ // 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++;
+ }
- textX1 = textX;
+ // Get next word
+ curWord = strtok(NULL, " ");
- if (ya == 1)
- textX1 = 315 - textX;
-
- textX2 = (strlen(m1) / 2) * CHAR_WIDTH;
-
- while (true) {
- strcpy(bb, m1);
- scumm_strrev(bb);
-
- if (textX1 < textX2) {
- strcpy(m3, strrchr(m1, ' '));
- strcpy(m1, strstr(bb, " "));
- scumm_strrev(m1);
- m1[strlen(m1) - 1] = '\0';
- strcat(m3, m2);
- strcpy(m2, m3);
- };
-
- textX2 = (strlen(m1) / 2) * CHAR_WIDTH;
-
- if (textX1 < textX2)
- continue;
-
- strcpy(mb[conta_f], m1);
-
- if (!strcmp(m2, ""))
- break;
-
- scumm_strrev(m2);
- m2[strlen(m2) - 1] = '\0';
- scumm_strrev(m2);
- strcpy(m1, m2);
- strcpy(m2, "");
- conta_f++;
+ if (curWord == NULL) {
+ x = CLIP<int>(textX - strlen(messageLine) * CHAR_WIDTH / 2, 60, 255);
+ print_abc(messageLine, x, y + curLine * CHAR_HEIGHT);
+ }
}
-
- fil = textY - (((conta_f + 3) * CHAR_HEIGHT));
-
- for (h = 0; h < conta_f + 1; h++) {
- textX3 = strlen(mb[h]) / 2;
- print_abc(mb[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