[Scummvm-cvs-logs] CVS: scummvm/scumm/smush smush_font.cpp,1.17,1.18 smush_font.h,1.10,1.11 smush_player.cpp,1.118,1.119

Max Horn fingolfin at users.sourceforge.net
Fri Apr 16 13:50:01 CEST 2004


Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv861/scumm/smush

Modified Files:
	smush_font.cpp smush_font.h smush_player.cpp 
Log Message:
Unify some code

Index: smush_font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- smush_font.cpp	15 Apr 2004 15:56:21 -0000	1.17
+++ smush_font.cpp	16 Apr 2004 20:49:14 -0000	1.18
@@ -157,27 +157,8 @@
 #define MAX_WORDS	60
 
 
-void SmushFont::drawStringAbsolute(const char *str, byte *buffer, int dst_width, int x, int y) {
-	debug(9, "SmushFont::drawStringAbsolute(%s, %d, %d)", str, x, y);
-
-	while (str) {
-		char line[256];
-		char *pos = strchr(str, '\n');
-		if (pos) {
-			memcpy(line, str, pos - str - 1);
-			line[pos - str - 1] = 0;
-			str = pos + 1;
-		} else {
-			strcpy(line, str);
-			str = 0;
-		}
-		drawSubstring(line, buffer, dst_width, x, y);
-		y += getStringHeight(line);
-	}
-}
-
-void SmushFont::drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y) {
-	debug(9, "SmushFont::drawStringCentered(%s, %d, %d)", str, x, y);
+void SmushFont::drawString(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center) {
+	debug(0, "SmushFont::drawString(%s, %d, %d, %d)", str, x, y, center);
 
 	while (str) {
 		char line[256];
@@ -190,13 +171,13 @@
 			strcpy(line, str);
 			str = 0;
 		}
-		drawSubstring(line, buffer, dst_width, x - getStringWidth(line) / 2, y);
+		drawSubstring(line, buffer, dst_width, center ? (x - getStringWidth(line) / 2) : x, y);
 		y += getStringHeight(line);
 	}
 }
 
-void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
-	debug(9, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d)", str, x, y, left, right);
+void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center) {
+	debug(0, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d, %d)", str, x, y, left, right, center);
 
 	const int width = right - left;
 	char *s = strdup(str);
@@ -243,81 +224,56 @@
 	if (y > dst_height - height) {
 		y = dst_height - height;
 	}
-
-	if (x > dst_width - max_width)
-		x = dst_width - max_width;
-
-	for (i = 0; i < line_count; i++) {
-		drawSubstring(substrings[i], buffer, dst_width, x, y);
-		y += getStringHeight(substrings[i]);
+	
+	if (center) {
+		max_width = (max_width + 1) / 2;
+		x = left + width / 2;
+	
+		if (x < left + max_width)
+			x = left + max_width;
+		if (x > right - max_width)
+			x = right - max_width;
+	
+		for (i = 0; i < line_count; i++) {
+			drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y);
+			y += getStringHeight(substrings[i]);
+		}
+	} else {
+		if (x > dst_width - max_width)
+			x = dst_width - max_width;
+	
+		for (i = 0; i < line_count; i++) {
+			drawSubstring(substrings[i], buffer, dst_width, x, y);
+			y += getStringHeight(substrings[i]);
+		}
 	}
 	
 	free(s);
 }
 
-void SmushFont::drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
-	debug(9, "SmushFont::drawStringWrapCentered(%s, %d, %d, %d, %d)", str, x, y, left, right);
-	
-	const int width = right - left;
-	char *s = strdup(str);
-	char *words[MAX_WORDS];
-	int word_count = 0;
+} // End of namespace Scumm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
-	char *tmp = s;
-	while (tmp) {
-		assert(word_count < MAX_WORDS);
-		words[word_count++] = tmp;
-		tmp = strpbrk(tmp, " \t\r\n");
-		if (tmp == 0)
-			break;
-		*tmp++ = 0;
-	}
 
-	int i = 0, max_width = 0, height = 0, line_count = 0;
 
-	char *substrings[MAX_WORDS];
-	int substr_widths[MAX_WORDS];
-	const int space_width = getCharWidth(' ');
 
-	i = 0;
-	while (i < word_count) {
-		char *substr = words[i++];
-		int substr_width = getStringWidth(substr);
 
-		while (i < word_count) {
-			int word_width = getStringWidth(words[i]);
-			if ((substr_width + space_width + word_width) >= width)
-				break;
-			substr_width += word_width + space_width;
-			*(words[i]-1) = ' ';	// Convert 0 byte back to space
-			i++;
-		}
 
-		substrings[line_count] = substr;
-		substr_widths[line_count++] = substr_width;
-		if (max_width < substr_width)
-			max_width = substr_width;
-		height += getStringHeight(substr);
-	}
 
-	if (y > dst_height - height) {
-		y = dst_height - height;
-	}
 
-	max_width = (max_width + 1) / 2;
-	x = left + width / 2;
 
-	if (x < left + max_width)
-		x = left + max_width;
-	if (x > right - max_width)
-		x = right - max_width;
 
-	for (i = 0; i < line_count; i++) {
-		drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y);
-		y += getStringHeight(substrings[i]);
-	}
-	
-	free(s);
-}
 
-} // End of namespace Scumm

Index: smush_font.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- smush_font.h	6 Jan 2004 12:45:31 -0000	1.10
+++ smush_font.h	16 Apr 2004 20:49:14 -0000	1.11
@@ -45,10 +45,8 @@
 	SmushFont(bool use_original_colors, bool new_colors);
 
 	void setColor(byte c) { _color = c; }
-	void drawStringAbsolute    (const char *str, byte *buffer, int dst_width, int x, int y);
-	void drawStringCentered    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y);
-	void drawStringWrap        (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
-	void drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
+	void drawString    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center);
+	void drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center);
 };
 
 } // End of namespace Scumm

Index: smush_player.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_player.cpp,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- smush_player.cpp	13 Apr 2004 19:20:16 -0000	1.118
+++ smush_player.cpp	16 Apr 2004 20:49:14 -0000	1.119
@@ -569,10 +569,10 @@
 	// bit 3 - wrap around  8
 	switch (flags & 9) {
 	case 0: 
-		sf->drawStringAbsolute(str, _dst, _width, pos_x, pos_y);
+		sf->drawString(str, _dst, _width, _height, pos_x, pos_y, false);
 		break;
 	case 1:
-		sf->drawStringCentered(str, _dst, _width, _height, pos_x, MAX(pos_y, top));
+		sf->drawString(str, _dst, _width, _height, pos_x, MAX(pos_y, top), true);
 		break;
 	case 8:
 		// FIXME: Is 'right' the maximum line width here, just
@@ -580,7 +580,7 @@
 		// in The Dig's intro, where 'left' and 'right' are
 		// always 0 and 321 respectively, and apparently we
 		// handle that correctly.
-		sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right);
+		sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right, false);
 		break;
 	case 9:
 		// In this case, the 'right' parameter is actually the
@@ -589,7 +589,7 @@
 		//
 		// Note that in The Dig's "Spacetime Six" movie it's
 		// 621. I have no idea what that means.
-		sf->drawStringWrapCentered(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width));
+		sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width), true);
 		break;
 	default:
 		warning("SmushPlayer::handleTextResource. Not handled flags: %d", flags);





More information about the Scummvm-git-logs mailing list