[Scummvm-cvs-logs] CVS: scummvm/scumm/smush frenderer.cpp,1.6,1.7 frenderer.h,1.5,1.6 player.cpp,1.13,1.14

Pawe? Ko?odziejski aquadran at users.sourceforge.net
Thu Sep 19 22:47:01 CEST 2002


Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory usw-pr-cvs1:/tmp/cvs-serv23307

Modified Files:
	frenderer.cpp frenderer.h player.cpp 
Log Message:
fixed placement subtitles in smush(the dig)

Index: frenderer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/frenderer.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- frenderer.cpp	31 Aug 2002 13:29:10 -0000	1.6
+++ frenderer.cpp	20 Sep 2002 05:46:03 -0000	1.7
@@ -232,3 +232,77 @@
 	delete []substrings;
 	return true;
 }
+
+bool FontRenderer::drawStringWrap(const char * str, char * buffer, const Point & size, int32 x, int32 y, int32 width) const {
+	debug(9, "FontRenderer::drawStringWrap(%s, %d, %d)", str, x, y);
+	assert(strchr(str, '\n') == 0);
+	char * * words = split(str, ' ');
+	int32 nb_sub = 0;
+
+	while(words[nb_sub]) nb_sub++;
+
+	int32 * sizes = new int32[nb_sub];
+	int32 i = 0, max_width = 0, height = 0, nb_subs = 0, left_x;
+
+	for(i = 0; i < nb_sub; i++)
+		sizes[i] = stringWidth(words[i]);
+
+	char * * substrings = new char *[nb_sub];
+	int32 * substr_widths = new int32[nb_sub];
+	int32 space_width = charWidth(' ');
+
+	i = 0;
+	while(i < nb_sub) {
+		int32 substr_width = sizes[i];
+		char * substr = new char[1000];
+		strcpy(substr, words[i]);
+		int32 j = i + 1;
+
+		while(j < nb_sub && (substr_width + space_width + sizes[j]) < width) {
+			substr_width += sizes[j++] + space_width;
+		}
+
+		for(int32 k = i + 1; k < j; k++) {
+			strcat(substr, " ");
+			strcat(substr, words[k]);
+		}
+
+		substrings[nb_subs] = substr;
+		substr_widths[nb_subs++] = substr_width;
+		i = j;
+		height += stringHeight(substr);
+	}
+
+	delete []sizes;
+	for(i = 0; i < nb_sub; i++) {
+		delete []words[i];
+	}
+	delete []words;
+
+	if(y + height > size.getY()) {
+		y = size.getY() - height;
+	}
+
+	for(i = 0; i < nb_subs; i++)
+		max_width = MAX(max_width, substr_widths[i]);
+
+	if(max_width + x > size.getX())
+		left_x = size.getX() - max_width + charWidth(' ');
+	else
+		left_x = x;
+
+	if(max_width + left_x > size.getX())
+		left_x = size.getX() - max_width;
+
+	for(i = 0; i < nb_subs; i++) {
+		int32 substr_width = substr_widths[i];
+		drawSubstring((const byte *)substrings[i], buffer, size, left_x, y);
+		y += stringHeight(substrings[i]);
+		delete []substrings[i];
+	}
+
+	delete []substr_widths;
+	delete []substrings;
+	return true;
+}
+

Index: frenderer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/frenderer.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- frenderer.h	31 Aug 2002 13:29:10 -0000	1.5
+++ frenderer.h	20 Sep 2002 05:46:03 -0000	1.6
@@ -148,6 +148,7 @@
 		@return \c true if everything went fine, \c false otherwise
 	*/
 	bool drawStringCentered(const char * str, char * buffer, const Point & size, int32 y, int32 xmin, int32 width, int32 offset) const;
+	bool drawStringWrap(const char * str, char * buffer, const Point & size, int32 x, int32 y, int32 width) const;
 	/*!	@brief draw a string at an absolute position.
 	
 		@param str		the string to draw.

Index: player.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/player.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- player.cpp	15 Sep 2002 19:28:34 -0000	1.13
+++ player.cpp	20 Sep 2002 05:46:03 -0000	1.14
@@ -380,11 +380,35 @@
 	assert(fr != 0);
 	fr->setColor(color);
 	if(!_curBuffer) { _curBuffer = _renderer->lockFrame(_frame); }
-	if(flags == 0 || flags == 4) {
+
+	// flags:
+	// bit 0 - center				1
+	// bit 1 - not used			2
+	// bit 2 - ???					4
+	// bit 3 - wrap around	8
+	if(flags == 0) {
 		fr->drawStringAbsolute(str, _curBuffer, _frameSize, pos_x, pos_y);
-	} else {
+	}
+	else if(flags == 1) {
+		fr->drawStringCentered(str, _curBuffer, _frameSize, MAX(pos_y, top), left, width, pos_x);
+	}
+	else if(flags == 4) {
+		fr->drawStringAbsolute(str, _curBuffer, _frameSize, pos_x, pos_y);
+	}
+	else if(flags == 5) {
+		fr->drawStringCentered(str, _curBuffer, _frameSize, MAX(pos_y, top), left, width, pos_x);
+	}
+	else if(flags == 8) {
+		fr->drawStringWrap(str, _curBuffer, _frameSize, pos_x, MAX(pos_y, top), width);
+	}
+	else if(flags == 12) {
+		fr->drawStringWrap(str, _curBuffer, _frameSize, pos_x, MAX(pos_y, top), width);
+	}
+	else if(flags == 13) {
 		fr->drawStringCentered(str, _curBuffer, _frameSize, MAX(pos_y, top), left, width, pos_x);
 	}
+	else
+		warning("SmushPlayer::handleTextResource. Not handled flags: %d\n", flags);
 }
 
 void SmushPlayer::readPalette(Palette & out, Chunk & in) {





More information about the Scummvm-git-logs mailing list