[Scummvm-cvs-logs] SF.net SVN: scummvm:[33402] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Tue Jul 29 11:44:05 CEST 2008


Revision: 33402
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33402&view=rev
Author:   peres001
Date:     2008-07-29 09:44:05 +0000 (Tue, 29 Jul 2008)

Log Message:
-----------
Added dialogue text rendering for BRA.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/balloons.cpp
    scummvm/trunk/engines/parallaction/gfxbase.cpp
    scummvm/trunk/engines/parallaction/graphics.cpp
    scummvm/trunk/engines/parallaction/graphics.h

Modified: scummvm/trunk/engines/parallaction/balloons.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/balloons.cpp	2008-07-29 09:23:54 UTC (rev 33401)
+++ scummvm/trunk/engines/parallaction/balloons.cpp	2008-07-29 09:44:05 UTC (rev 33402)
@@ -23,6 +23,8 @@
  *
  */
 
+#include "common/util.h"
+
 #include "parallaction/graphics.h"
 #include "parallaction/parallaction.h"
 
@@ -76,6 +78,7 @@
 
 	uint	_numBalloons;
 
+	void getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height);
 	void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth);
 	int createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness);
 	Balloon *getBalloon(uint id);
@@ -149,12 +152,12 @@
 
 	int16 w, h;
 
-	_gfx->getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
 
 	int id = createBalloon(w+5, h, winding, 1);
 	Balloon *balloon = &_intBalloons[id];
 
-	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
 
 	// TODO: extract some text to make a name for obj
 	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
@@ -169,12 +172,12 @@
 
 	int16 w, h;
 
-	_gfx->getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
 
 	int id = createBalloon(w+5, h, winding, 1);
 	Balloon *balloon = &_intBalloons[id];
 
-	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
 
 	// TODO: extract some text to make a name for obj
 	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
@@ -193,7 +196,7 @@
 void BalloonManager_ns::setBalloonText(uint id, char *text, byte textColor) {
 	Balloon *balloon = getBalloon(id);
 	balloon->surface->fillRect(balloon->innerBox, 1);
-	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
 }
 
 
@@ -201,11 +204,11 @@
 
 	int16 w, h;
 
-	_gfx->getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
+	getStringExtent(_vm->_dialogueFont, text, MAX_BALLOON_WIDTH, &w, &h);
 
 	int id = createBalloon(w+(endGame ? 5 : 10), h+5, -1, BALLOON_TRANSPARENT_COLOR_NS);
 	Balloon *balloon = &_intBalloons[id];
-	_gfx->drawWrappedText(_vm->_dialogueFont, balloon->surface, text, 0, MAX_BALLOON_WIDTH);
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, 0, MAX_BALLOON_WIDTH);
 
 	// TODO: extract some text to make a name for obj
 	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
@@ -242,13 +245,110 @@
 	_numBalloons = 0;
 }
 
+void BalloonManager_ns::drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth) {
 
+	uint16 lines = 0;
+	uint16 linewidth = 0;
 
+	uint16 rx = 10;
+	uint16 ry = 4;
 
+	uint16 blankWidth = font->getStringWidth(" ");
+	uint16 tokenWidth = 0;
 
+	char token[MAX_TOKEN_LEN];
 
+	if (wrapwidth == -1)
+		wrapwidth = _vm->_screenWidth;
 
+	while (strlen(text) > 0) {
 
+		text = parseNextToken(text, token, MAX_TOKEN_LEN, "   ", true);
+
+		if (!scumm_stricmp(token, "%p")) {
+			lines++;
+			rx = 10;
+			ry = 4 + lines*10;	// y
+
+			strcpy(token, "> .......");
+			strncpy(token+2, _password, strlen(_password));
+			tokenWidth = font->getStringWidth(token);
+		} else {
+			tokenWidth = font->getStringWidth(token);
+
+			linewidth += tokenWidth;
+
+			if (linewidth > wrapwidth) {
+				// wrap line
+				lines++;
+				rx = 10;			// x
+				ry = 4 + lines*10;	// y
+				linewidth = tokenWidth;
+			}
+
+			if (!scumm_stricmp(token, "%s")) {
+				sprintf(token, "%d", _score);
+			}
+
+		}
+
+		_gfx->drawText(font, surf, rx, ry, token, color);
+
+		rx += tokenWidth + blankWidth;
+		linewidth += blankWidth;
+
+		text = Common::ltrim(text);
+	}
+
+}
+
+void BalloonManager_ns::getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height) {
+
+	uint16 lines = 0;
+	uint16 w = 0;
+	*width = 0;
+
+	uint16 blankWidth = font->getStringWidth(" ");
+	uint16 tokenWidth = 0;
+
+	char token[MAX_TOKEN_LEN];
+
+	while (strlen(text) != 0) {
+
+		text = parseNextToken(text, token, MAX_TOKEN_LEN, "   ", true);
+		tokenWidth = font->getStringWidth(token);
+
+		w += tokenWidth;
+
+		if (!scumm_stricmp(token, "%p")) {
+			lines++;
+		} else {
+			if (w > maxwidth) {
+				w -= tokenWidth;
+				lines++;
+				if (w > *width)
+					*width = w;
+
+				w = tokenWidth;
+			}
+		}
+
+		w += blankWidth;
+		text = Common::ltrim(text);
+	}
+
+	if (*width < w) *width = w;
+	*width += 10;
+
+	*height = lines * 10 + 20;
+
+	return;
+}
+
+
+
+
+
 class BalloonManager_br : public BalloonManager {
 
 	struct Balloon {
@@ -265,12 +365,30 @@
 	Gfx *_gfx;
 
 	void cacheAnims();
+	void getStringExtent(Font *font, const char *text, uint16 maxwidth, int16* width, int16* height);
 	void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth);
 	int createBalloon(int16 w, int16 h, int16 winding, uint16 borderThickness);
 	Balloon *getBalloon(uint id);
 	Graphics::Surface *expandBalloon(Frames *data, int frameNum);
 
+	void textSetupRendering(const Common::String &text, Graphics::Surface *dest, Font *font, byte color);
+	void textEmitCenteredLine();
+	void textAccum(const Common::String &token, uint16 width);
+	void textNewLine();
 
+	Common::String _textLine;
+	Graphics::Surface *_textSurf;
+	Font *_textFont;
+	uint16 _textX, _textY;
+	byte _textColor;
+	uint16 _textLines, _textWidth;
+
+	void extentSetup(Font *font, int16 *width, int16 *height);
+	void extentAction();
+
+	int16 *_extentWidth, *_extentHeight;
+
+
 public:
 	BalloonManager_br(Disk *disk, Gfx *gfx);
 	~BalloonManager_br();
@@ -328,7 +446,7 @@
 	balloon->surface = expandBalloon(src, srcFrame);
 	src->getRect(srcFrame, balloon->box);
 
-//	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
 
 	// TODO: extract some text to make a name for obj
 	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
@@ -366,7 +484,7 @@
 	balloon->surface = expandBalloon(src, srcFrame);
 	src->getRect(srcFrame, balloon->box);
 
-//	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
+	drawWrappedText(_vm->_dialogueFont, balloon->surface, text, textColor, MAX_BALLOON_WIDTH);
 
 	// TODO: extract some text to make a name for obj
 	balloon->obj = _gfx->registerBalloon(new SurfaceToFrames(balloon->surface), 0);
@@ -436,6 +554,155 @@
 	}
 }
 
+
+void BalloonManager_br::extentSetup(Font *font, int16 *width, int16 *height) {
+	_extentWidth = width;
+	_extentHeight = height;
+
+	_textLine.clear();
+	_textLines = 0;
+	_textWidth = 0;
+	_textFont = font;
+}
+
+void BalloonManager_br::extentAction() {
+	if (_textWidth > *_extentWidth) {
+		*_extentWidth = _textWidth;
+	}
+	*_extentHeight = _textLines * _textFont->height();
+}
+
+void BalloonManager_br::textSetupRendering(const Common::String &text, Graphics::Surface *dest, Font *font, byte color) {
+	uint16 maxWidth = 216;
+
+	int16 w, h;
+	getStringExtent(font, text.c_str(), maxWidth, &w, &h);
+
+	w += 10;
+	h += 12;
+
+	_textLine.clear();
+	_textSurf = dest;
+	_textFont = font;
+	_textX = 0;
+	_textY = (_textSurf->h - h) / 2;
+	_textColor = color;
+	_textLines = 0;
+	_textWidth = 0;
+}
+
+void BalloonManager_br::textEmitCenteredLine() {
+	if (_textLine.empty()) {
+		return;
+	}
+	uint16 rx = _textX + (_textSurf->w - _textWidth) / 2;
+	uint16 ry = _textY + _textLines * _textFont->height();	// y
+	_gfx->drawText(_textFont, _textSurf, rx, ry, _textLine.c_str(), _textColor);
+}
+
+void BalloonManager_br::textAccum(const Common::String &token, uint16 width) {
+	if (token.empty()) {
+		return;
+	}
+
+	_textWidth += width;
+	_textLine += token;
+}
+
+void BalloonManager_br::textNewLine() {
+	_textLines++;
+	_textWidth = 0;
+	_textLine.clear();
+}
+
+
+// TODO: really, base this and getStringExtent on some kind of LineTokenizer, instead of
+// repeating the algorithm and changing a couple of lines.
+void BalloonManager_br::drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapWidth) {
+	textSetupRendering(text, surf, font, color);
+
+	wrapWidth = 216;
+
+	Common::StringTokenizer	tokenizer(text, " ");
+	Common::String token;
+	Common::String blank(" ");
+
+	uint16 blankWidth = font->getStringWidth(" ");
+	uint16 tokenWidth = 0;
+
+	while (!tokenizer.empty()) {
+		token = tokenizer.nextToken();
+
+		if (token == '/') {
+			tokenWidth = 0;
+			textEmitCenteredLine();
+			textNewLine();
+		} else {
+			// todo: expand '%'
+			tokenWidth = font->getStringWidth(token.c_str());
+
+			if (_textWidth == 0) {
+				textAccum(token, tokenWidth);
+			} else {
+				if (_textWidth + blankWidth + tokenWidth <= wrapWidth) {
+					textAccum(blank, blankWidth);
+					textAccum(token, tokenWidth);
+				} else {
+					textEmitCenteredLine();
+					textNewLine();
+					textAccum(token, tokenWidth);
+				}
+			}
+		}
+	}
+
+	textEmitCenteredLine();
+}
+
+
+
+void BalloonManager_br::getStringExtent(Font *font, const char *text, uint16 maxwidth, int16* width, int16* height) {
+	extentSetup(font, width, height);
+
+	Common::StringTokenizer	tokenizer(text, " ");
+	Common::String token;
+	Common::String blank(" ");
+
+	uint16 blankWidth = font->getStringWidth(" ");
+	uint16 tokenWidth = 0;
+
+	while (!tokenizer.empty()) {
+		token = tokenizer.nextToken();
+
+		if (token == '/') {
+			tokenWidth = 0;
+			extentAction();
+			textNewLine();
+		} else {
+			// todo: expand '%'
+			tokenWidth = font->getStringWidth(token.c_str());
+
+			if (_textWidth == 0) {
+				textAccum(token, tokenWidth);
+			} else {
+				if (_textWidth + blankWidth + tokenWidth <= maxwidth) {
+					textAccum(blank, blankWidth);
+					textAccum(token, tokenWidth);
+				} else {
+					extentAction();
+					textNewLine();
+					textAccum(token, tokenWidth);
+				}
+			}
+		}
+	}
+
+	extentAction();
+}
+
+
+
+
 BalloonManager_br::BalloonManager_br(Disk *disk, Gfx *gfx) : _numBalloons(0), _disk(disk), _gfx(gfx), _leftBalloon(0), _rightBalloon(0) {
 }
 
@@ -455,4 +722,6 @@
 	}
 }
 
+
+
 } // namespace Parallaction

Modified: scummvm/trunk/engines/parallaction/gfxbase.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gfxbase.cpp	2008-07-29 09:23:54 UTC (rev 33401)
+++ scummvm/trunk/engines/parallaction/gfxbase.cpp	2008-07-29 09:44:05 UTC (rev 33402)
@@ -209,64 +209,7 @@
 	font->drawString(dst, surf->w, text);
 }
 
-void Gfx::drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth) {
 
-	uint16 lines = 0;
-	uint16 linewidth = 0;
-
-	uint16 rx = 10;
-	uint16 ry = 4;
-
-	uint16 blankWidth = font->getStringWidth(" ");
-	uint16 tokenWidth = 0;
-
-	char token[MAX_TOKEN_LEN];
-
-	if (wrapwidth == -1)
-		wrapwidth = _vm->_screenWidth;
-
-	while (strlen(text) > 0) {
-
-		text = parseNextToken(text, token, MAX_TOKEN_LEN, "   ", true);
-
-		if (!scumm_stricmp(token, "%p")) {
-			lines++;
-			rx = 10;
-			ry = 4 + lines*10;	// y
-
-			strcpy(token, "> .......");
-			strncpy(token+2, _password, strlen(_password));
-			tokenWidth = font->getStringWidth(token);
-		} else {
-			tokenWidth = font->getStringWidth(token);
-
-			linewidth += tokenWidth;
-
-			if (linewidth > wrapwidth) {
-				// wrap line
-				lines++;
-				rx = 10;			// x
-				ry = 4 + lines*10;	// y
-				linewidth = tokenWidth;
-			}
-
-			if (!scumm_stricmp(token, "%s")) {
-				sprintf(token, "%d", _score);
-			}
-
-		}
-
-		drawText(font, surf, rx, ry, token, color);
-
-		rx += tokenWidth + blankWidth;
-		linewidth += blankWidth;
-
-		text = Common::ltrim(text);
-	}
-
-}
-
-
 #if 0
 void Gfx::unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, byte transparentColor) {
 

Modified: scummvm/trunk/engines/parallaction/graphics.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.cpp	2008-07-29 09:23:54 UTC (rev 33401)
+++ scummvm/trunk/engines/parallaction/graphics.cpp	2008-07-29 09:44:05 UTC (rev 33402)
@@ -707,50 +707,7 @@
 }
 
 
-void Gfx::getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height) {
 
-	uint16 lines = 0;
-	uint16 w = 0;
-	*width = 0;
-
-	uint16 blankWidth = font->getStringWidth(" ");
-	uint16 tokenWidth = 0;
-
-	char token[MAX_TOKEN_LEN];
-
-	while (strlen(text) != 0) {
-
-		text = parseNextToken(text, token, MAX_TOKEN_LEN, "   ", true);
-		tokenWidth = font->getStringWidth(token);
-
-		w += tokenWidth;
-
-		if (!scumm_stricmp(token, "%p")) {
-			lines++;
-		} else {
-			if (w > maxwidth) {
-				w -= tokenWidth;
-				lines++;
-				if (w > *width)
-					*width = w;
-
-				w = tokenWidth;
-			}
-		}
-
-		w += blankWidth;
-		text = Common::ltrim(text);
-	}
-
-	if (*width < w) *width = w;
-	*width += 10;
-
-	*height = lines * 10 + 20;
-
-	return;
-}
-
-
 void Gfx::copyRect(const Common::Rect &r, Graphics::Surface &src, Graphics::Surface &dst) {
 
 	byte *s = (byte*)src.getBasePtr(r.left, r.top);

Modified: scummvm/trunk/engines/parallaction/graphics.h
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.h	2008-07-29 09:23:54 UTC (rev 33401)
+++ scummvm/trunk/engines/parallaction/graphics.h	2008-07-29 09:44:05 UTC (rev 33402)
@@ -497,7 +497,6 @@
 	void freeLabels();
 
 	// dialogue balloons
-	void getStringExtent(Font *font, char *text, uint16 maxwidth, int16* width, int16* height);
 	GfxObj* registerBalloon(Frames *frames, const char *text);
 	void destroyBalloons();
 
@@ -599,7 +598,6 @@
 
 	// low level text and patches
 	void drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color);
-	void drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth);
 
 	void drawGfxObject(GfxObj *obj, Graphics::Surface &surf, bool scene);
     void blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, byte transparentColor);


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