[Scummvm-git-logs] scummvm master -> d391932ac4cc231723b935a295c8f176cd089bac

stevenhoefel stevenhoefel at hotmail.com
Tue Jan 17 12:16:33 CET 2017


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

Summary:
feab260c98 GRAPHICS: Fix oversight on length value to return.
837b3b22e5 GRAPHICS: MacText calculate longest string inside maxWidth and add alignment.
d391932ac4 DIRECTOR: Refactor Text Rendering. Use alignment of MacText. Render to temporary surface to allow ink blitting.


Commit: feab260c98b621a13043cd84193928b8f92797d3
    https://github.com/scummvm/scummvm/commit/feab260c98b621a13043cd84193928b8f92797d3
Author: stevenhoefel (stevenhoefel at hotmail.com)
Date: 2017-01-17T22:14:58+11:00

Commit Message:
GRAPHICS: Fix oversight on length value to return.

Changed paths:
    graphics/font.cpp


diff --git a/graphics/font.cpp b/graphics/font.cpp
index 4f53dfe..7768b73 100644
--- a/graphics/font.cpp
+++ b/graphics/font.cpp
@@ -227,7 +227,7 @@ int wordWrapTextImpl(const Font &font, const StringType &str, int maxWidth, Comm
 	if (lineWidth > 0) {
 		wrapper.add(line, lineWidth);
 	}
-	return MAX(wrapper.actualMaxLineWidth, maxWidth);
+	return wrapper.actualMaxLineWidth;
 }
 
 } // End of anonymous namespace


Commit: 837b3b22e59cdda0d82e53bb58206162e595d9bc
    https://github.com/scummvm/scummvm/commit/837b3b22e59cdda0d82e53bb58206162e595d9bc
Author: stevenhoefel (stevenhoefel at hotmail.com)
Date: 2017-01-17T22:15:43+11:00

Commit Message:
GRAPHICS: MacText calculate longest string inside maxWidth and add alignment.

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 4d671e8..7a23b01 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -24,20 +24,17 @@
 
 namespace Graphics {
 
-MacText::MacText(Common::String s, const Graphics::Font *font, int fgcolor, int bgcolor, int maxWidth) {
+MacText::MacText(Common::String s, const Graphics::Font *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) {
 	_str = s;
 	_font = font;
 	_fgcolor = fgcolor;
 	_bgcolor = bgcolor;
 	_maxWidth = maxWidth;
+	_textMaxWidth = 0;
 	_surface = nullptr;
+	_textAlignment = textAlignment;
 
-	_interLinear = 0; // 0 pixels between the lines by default
-
-	if (_maxWidth == -1)
-		_textMaxWidth = 1000000; // Some big value
-	else
-		_textMaxWidth = -1;
+	_interLinear = 0; // 0 pixels between the lines by default	
 
 	splitString(_str);
 
@@ -62,7 +59,7 @@ void MacText::splitString(Common::String &str) {
 			prevCR = true;
 
 		if (*s == '\r' || *s == '\n') {
-			_maxWidth = MIN(_font->wordWrapText(tmp, _maxWidth, _text), _maxWidth);
+			_textMaxWidth = MAX(_font->wordWrapText(tmp, _maxWidth, _text), _textMaxWidth);
 
 			tmp.clear();
 
@@ -75,7 +72,7 @@ void MacText::splitString(Common::String &str) {
 	}
 
 	if (tmp.size())
-		_maxWidth = MIN(_font->wordWrapText(tmp, _maxWidth, _text), _maxWidth);
+		_textMaxWidth = MAX(_font->wordWrapText(tmp, _maxWidth, _text), _textMaxWidth);
 }
 
 void MacText::reallocSurface() {
@@ -84,7 +81,7 @@ void MacText::reallocSurface() {
 	//TODO: work out why this rounding doesn't correctly fill the entire width
 	//int requiredH = (_text.size() + (_text.size() * 10 + 9) / 10) * lineH
 	int requiredH = _text.size() * lineH;
-	int surfW = _maxWidth == -1 ? _textMaxWidth : _maxWidth;
+	int surfW = _textMaxWidth;
 
 	if (!_surface) {
 		_surface = new ManagedSurface(surfW, requiredH);
@@ -123,8 +120,12 @@ void MacText::render(int from, int to) {
 	_surface->fillRect(Common::Rect(0, y, _surface->w, to * lineH), _bgcolor);
 
 	for (int i = from; i < to; i++) {
+		int xOffset = 0;
+		if (_textAlignment == kTextAlignRight) xOffset = _textMaxWidth - _font->getStringWidth(_text[i]);
+		else if (_textAlignment == kTextAlignCenter) xOffset = (_textMaxWidth / 2) - (_font->getStringWidth(_text[i]) / 2);
+
 		//TODO: _textMaxWidth, when -1, was not rendering ANY text.
-		_font->drawString(_surface, _text[i], 0, y, _maxWidth, _fgcolor);
+		_font->drawString(_surface, _text[i], xOffset, y, _maxWidth, _fgcolor);
 
 		y += _font->getFontHeight() + _interLinear;
 	}
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 21c063f..28f0e50 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -25,12 +25,13 @@
 
 #include "graphics/fontman.h"
 #include "graphics/managed_surface.h"
+#include "graphics/font.h"
 
 namespace Graphics {
 
 class MacText {
 public:
-	MacText(Common::String s, const Graphics::Font *font, int fgcolor, int bgcolor, int maxWidth = -1);
+	MacText(Common::String s, const Graphics::Font *font, int fgcolor, int bgcolor, int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft);
 
 	void setInterLinear(int interLinear) { _interLinear = interLinear; }
 
@@ -61,6 +62,8 @@ private:
 
 	Graphics::ManagedSurface *_surface;
 	bool _fullRefresh;
+
+	TextAlign _textAlignment;
 };
 
 } // End of namespace Graphics


Commit: d391932ac4cc231723b935a295c8f176cd089bac
    https://github.com/scummvm/scummvm/commit/d391932ac4cc231723b935a295c8f176cd089bac
Author: stevenhoefel (stevenhoefel at hotmail.com)
Date: 2017-01-17T22:16:27+11:00

Commit Message:
DIRECTOR: Refactor Text Rendering. Use alignment of MacText. Render to temporary surface to allow ink blitting.

Changed paths:
    engines/director/frame.cpp
    engines/director/frame.h
    engines/director/score.cpp


diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp
index 9b8f25f..265f3ef 100644
--- a/engines/director/frame.cpp
+++ b/engines/director/frame.cpp
@@ -875,8 +875,6 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteId, Commo
 
 	const Graphics::Font *font = _vm->_wm->_fontMan->getFont(macFont);
 
-	height = font->getFontHeight();
-
 	debugC(3, kDebugText, "renderText: x: %d y: %d w: %d h: %d font: '%s'", x, y, width, height, _vm->_wm->_fontMan->getFontName(macFont));
 
 	int alignment = (int)textCast->textAlign;
@@ -885,7 +883,15 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteId, Commo
 	else
 		alignment++;
 
-	uint16 textX = x, textY = y;
+	Graphics::MacText mt(text, font, 0x00, 0xff, width, (Graphics::TextAlign)alignment);
+	mt.setInterLinear(1);
+	mt.render();
+	const Graphics::ManagedSurface *textSurface = mt.getSurface();
+
+	height = textSurface->h;
+
+	uint16 textX = 0, textY = 0;
+
 	if (!isButtonLabel) {
 		if (borderSize > 0) {
 			if (_vm->getVersion() <= 3)
@@ -895,71 +901,55 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteId, Commo
 
 			textX += (borderSize + 1);
 			textY += borderSize;
-		} else
-			textX += 1;
+		} else {
+			x += 1;
+		}
 
 		if (padding > 0) {
 			width += padding * 2;
 			height += padding;
-
-			if (textCast->textAlign == kTextAlignLeft)
-				textX += padding;
-			else if (textCast->textAlign == kTextAlignRight)
-				textX -= padding;
-			//TODO: alignment issue with odd-size-width center-aligned text
-			//else if (textCast->textAlign == kTextAlignCenter && ((borderSize + padding) % 2 == 1))
-			//	textX--;
-
 			textY += padding / 2;
 		}
 
-		if (textCast->textAlign == kTextAlignRight) textX -= 1;
+		if (textCast->textAlign == kTextAlignRight) 
+			textX -= 1;
 
-		if (textShadow > 0) {
-			if (borderSize == 0 && _vm->getVersion() > 3)
-				textX += 1;
-			if (_vm->getVersion() > 3)
-				height -= (textShadow - 1);
-		}
+		if (textShadow > 0)
+			textX--;
 	} else {
-		textY += 2;
+		y += 2;
 	}
 
-	Graphics::MacText mt(text, font, 0x00, 0xff, width);
-	mt.render();
-	Graphics::ManagedSurface *textSurface = mt.getSurface();
-
-	if (isButtonLabel) {
-		uint16 borderX = x + borderSize - 1, borderY = y + borderSize - 1, borderHeight = height, borderWidth = width;
-		if (borderSize != kSizeNone) {
-			while (borderSize) {
-				borderWidth += 2;
-				borderHeight += 2;
-				textSurface->frameRect(Common::Rect(borderX, borderY, borderX + borderWidth, borderY + borderHeight), 0);
-				borderSize--;
-				borderX--;
-				borderY--;
-			}
-		}
+	switch (textCast->textAlign) {
+	case kTextAlignCenter:
+		textX = (width / 2) - (textSurface->w / 2) + (padding / 2) + borderSize;
+		break;
+	case kTextAlignRight:
+		textX = width - (textSurface->w + 1) + (borderSize * 2) - (textShadow * 2) - (padding);
+		break;
+	}
 
-		if (boxShadow > 0) {
-			borderSize = (uint16)textCast->borderSize;
-			uint baseOffsetX = x + boxShadow;
-			uint baseOffsetY = y + height + (borderSize * 2);
-			uint sideOffsetX = x + borderWidth;
-			uint sideOffsetY = y + boxShadow;
-			while (boxShadow) {
-				textSurface->drawLine(baseOffsetX, baseOffsetY + (boxShadow - 1), baseOffsetX + borderWidth - 1, baseOffsetY + (boxShadow - 1), 0);
-				textSurface->drawLine(sideOffsetX + (boxShadow - 1), sideOffsetY, sideOffsetX + (boxShadow - 1), sideOffsetY + borderHeight - 1, 0);
-				boxShadow--;
-			}
+	Graphics::ManagedSurface textWithFeatures(width + (borderSize * 2) + boxShadow + textShadow, height + borderSize + boxShadow + textShadow);
+	textWithFeatures.fillRect(Common::Rect(textWithFeatures.w, textWithFeatures.h), 0xff);
+
+	if (!isButtonLabel && boxShadow > 0) {
+		textWithFeatures.fillRect(Common::Rect(boxShadow, boxShadow, textWithFeatures.w + boxShadow, textWithFeatures.h), 0);
+	}
+
+	if (!isButtonLabel && borderSize != kSizeNone) {
+		for (int bb = 0; bb < borderSize; bb++) {
+			Common::Rect borderRect(bb, bb, textWithFeatures.w - bb - boxShadow - textShadow, textWithFeatures.h - bb - boxShadow - textShadow);
+			textWithFeatures.fillRect(borderRect, 0xff);
+			textWithFeatures.frameRect(borderRect, 0);
 		}
 	}
 
 	if (textShadow > 0)
-		inkBasedBlit(surface, *textSurface, spriteId, Common::Rect(textX + textShadow, textY + textShadow, textX + textShadow + width, textY + textShadow + height));
+		textWithFeatures.transBlitFrom(textSurface->rawSurface(), Common::Point(textX + textShadow, textY + textShadow), 0xff);
 
-	inkBasedBlit(surface, *textSurface, spriteId, Common::Rect(textX, textY, textX + width, textY + height));
+	textWithFeatures.transBlitFrom(textSurface->rawSurface(), Common::Point(textX, textY), 0xff);
+	
+	inkBasedBlit(surface, textWithFeatures, spriteId, Common::Rect(x, y, x + width, y + height));
 }
 
 void Frame::drawBackgndTransSprite(Graphics::ManagedSurface &target, const Graphics::Surface &sprite, Common::Rect &drawRect) {
diff --git a/engines/director/frame.h b/engines/director/frame.h
index b41ee83..f822a83 100644
--- a/engines/director/frame.h
+++ b/engines/director/frame.h
@@ -33,7 +33,7 @@ namespace Director {
 
 class Sprite;
 
-#define CHANNEL_COUNT 24
+#define CHANNEL_COUNT 30
 
 enum {
 	kChannelDataSize = (25 * 50)
diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index 18cfd53..e5e137c 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -406,7 +406,9 @@ void Score::loadCastData(Common::SeekableSubReadStreamEndian &stream, uint16 id,
 	if (stream.size() == 0)
 		return;
 
-	if (stream.size() < 26) {
+	//TODO: Determine if there really is a minimum size.
+	//This value was too small for Shape Casts.
+	if (stream.size() < 10) {
 		warning("CAST data id %d is too small", id);
 		return;
 	}





More information about the Scummvm-git-logs mailing list