[Scummvm-cvs-logs] CVS: scummvm/queen talk.cpp,1.79,1.80 talk.h,1.28,1.29

Gregory Montoir cyx at users.sourceforge.net
Sat Jan 10 13:58:02 CET 2004


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv22409/queen

Modified Files:
	talk.cpp talk.h 
Log Message:
new Talk::splitOption() code (same value for text margins, word width is computed without the ending space char)

Index: talk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.cpp,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- talk.cpp	10 Jan 2004 20:33:05 -0000	1.79
+++ talk.cpp	10 Jan 2004 21:56:47 -0000	1.80
@@ -1230,6 +1230,7 @@
 }
 
 int Talk::splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]) {
+	debug(6, "Talk::splitOption(%s)", str);
 	// Check to see if option fits on one line, and exit early
 	if (_vm->resource()->getLanguage() == ENGLISH || 
 		_vm->display()->textWidth(str) <= MAX_TEXT_WIDTH) {
@@ -1239,6 +1240,7 @@
 
 	// Split up multiple line option at closest space character
 	memset(optionText, 0, 5 * MAX_STRING_SIZE);
+	uint16 spaceCharWidth = _vm->display()->textWidth(" ");
 	uint16 width = 0;
 	uint16 optionLines = 0;
 	uint16 maxTextLen = MAX_TEXT_WIDTH;
@@ -1246,25 +1248,30 @@
 	while (p) {
 		p = strchr(str, ' ');
 		if (p) {
-			uint16 len = p - str + 1;
-			width += _vm->display()->textWidth(str, len);
-			if (width > maxTextLen) {
-				strncat(optionText[optionLines], str, len - 1);
+			uint16 len = p - str;
+			uint16 wordWidth = _vm->display()->textWidth(str, len);
+			width += wordWidth;
+			if (width> maxTextLen) {
 				++optionLines;
-				width = 0;
-				maxTextLen = MAX_TEXT_WIDTH - 16; // compensate left margin
+				strncpy(optionText[optionLines], str, len + 1);
+				width = wordWidth;
+				maxTextLen = MAX_TEXT_WIDTH - OPTION_TEXT_MARGIN;
 			} else {
-				strncat(optionText[optionLines], str, len);
+				strncat(optionText[optionLines], str, len + 1);
 			}
+			width += spaceCharWidth;
 			str = p + 1;
+		} else {
+			if (str[0]) {
+				if (width + _vm->display()->textWidth(str) > maxTextLen) {
+					++optionLines;
+				}
+				strcat(optionText[optionLines], str);
+			}
+			++optionLines;
 		}
 	}
-	width += _vm->display()->textWidth(str);
-	if (width > maxTextLen) {
-		++optionLines;
-	}
-	strcat(optionText[optionLines], str);
-	return optionLines + 1;
+	return optionLines;
 }
 
 static char *removeStar(char *str) {
@@ -1356,7 +1363,7 @@
 					if (yOffset < 5) {
 						//debug(6, "Draw text '%s'", optionText[j]);
 						_vm->display()->setText(
-								(j == 0) ? 0 : 24, 
+								(j == 0) ? 0 : OPTION_TEXT_MARGIN, 
 								150 - PUSHUP + yOffset * LINE_HEIGHT, 
 								optionText[j]);
 					}

Index: talk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- talk.h	10 Jan 2004 19:55:54 -0000	1.28
+++ talk.h	10 Jan 2004 21:56:47 -0000	1.29
@@ -61,7 +61,8 @@
 	  ARROW_BOB_DOWN = 63,
 	  ARROW_ZONE_UP   = 5,
 	  ARROW_ZONE_DOWN = 6,
-	  DOG_HEADER_SIZE = 20
+	  DOG_HEADER_SIZE = 20,
+	  OPTION_TEXT_MARGIN = 24
 	};
 
 	//! Special commands for speech





More information about the Scummvm-git-logs mailing list