[Scummvm-cvs-logs] scummvm master -> a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6

criezy criezy at scummvm.org
Thu Apr 7 02:41:35 CEST 2016


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a7bafd1c5d DRASCULA: Improve text centering and spacing between lines


Commit: a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6
    https://github.com/scummvm/scummvm/commit/a7bafd1c5dc59d3c0fcfce78f8b87646fbba81b6
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2016-04-07T01:36:23+01:00

Commit Message:
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.

Changed paths:
    engines/drascula/graphics.cpp



diff --git a/engines/drascula/graphics.cpp b/engines/drascula/graphics.cpp
index 077047a..5e37d2c 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));
 		}
 	}
 }






More information about the Scummvm-git-logs mailing list