[Scummvm-cvs-logs] SF.net SVN: scummvm:[42832] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Mon Jul 27 05:08:19 CEST 2009


Revision: 42832
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42832&view=rev
Author:   dkasak13
Date:     2009-07-27 03:08:19 +0000 (Mon, 27 Jul 2009)

Log Message:
-----------
* Added Font::getStringHeight()
* Made Font::getStringWidth() calculate the width of the string properly now that handling of multi-row strings is in
* Fixed bug which caused the last column of pixels in the last letter of a string to linger on the screen

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/font.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/font.h

Modified: scummvm/branches/gsoc2009-draci/engines/draci/font.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/font.cpp	2009-07-27 03:01:06 UTC (rev 42831)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.cpp	2009-07-27 03:08:19 UTC (rev 42832)
@@ -29,7 +29,7 @@
 #include "draci/font.h"
 
 namespace Draci {
-
+de
 const Common::String kFontSmall("Small.fon");
 const Common::String kFontBig("Big.fon"); 
 
@@ -188,7 +188,7 @@
 	}
 
 	if (markDirty) {
-		Common::Rect r(tx, ty, tx + xPixelsToDraw, ty + yPixelsToDraw);
+		Common::Rect r(tx, ty, tx + xPixelsToDraw + 1, ty + yPixelsToDraw);
 		dst->markDirtyRect(r);
 	}
 }
@@ -218,14 +218,14 @@
 		// If we encounter the '|' char (newline and end of string marker),
 		// skip it and go to the start of the next line
 		if (str[i] == '|') {
-			cury += getFontHeight() + 1;
+			cury += getFontHeight();
 			curx = x;
 			continue;
 		}
 		
-		// Return early if there's no more space on the screen	
-		if (curx >= dst->w || cury >= dst->h) {
-			return;
+		// Break early if there's no more space on the screen	
+		if (curx >= dst->w - 1 || cury >= dst->h - 1) {
+			break;
 		}		
 		
 		drawChar(dst, str[i], curx, cury, markDirty);
@@ -260,16 +260,53 @@
 
 int Font::getStringWidth(const Common::String &str, int spacing) const {
 	int width = 0;	
+
+	// Real length, including '|' separators
 	uint len = str.size();
-	for (unsigned int i = 0; i < len; ++i) {
+
+	// Here we will store the in-game length of the longest line
+	uint lineLength = 0;
+
+	for (unsigned int i = 0, tmp = 0; i < len; ++i) {
+
+		// Newline char encountered, skip it and store the new length if it is greater
+		if (str[i] == '|') {
+			if (tmp > width) {
+				width = tmp;
+			}
+			continue;
+		}
+
 		uint8 charIndex = str[i] - kCharIndexOffset;
-		width += _charWidths[charIndex];
+		tmp += _charWidths[charIndex];
+		tmp += spacing;
 	}
 
-	// Add width of spaces, if any
-	width += (len - 1) * spacing;
+	return width + 1;
+}
 
-	return width;
+/**
+ * @brief Calculate the height of a string by counting the number of '|' chars (which
+ * 		  are used as newline characters and end-of-string markers)
+ *
+ * @param str 		String to draw
+ * @param spacing	Space to leave between individual characters. Defaults to 0. 
+ *
+ * @return The calculated height of the string 
+ */
+
+
+int Font::getStringHeight(const Common::String &str) const {
+	uint len = str.size();
+	int separators = 0;
+
+	for (unsigned int i = 0; i < len; ++i) {
+		if (str[i] == '|') {
+			++separators;
+		}
+	}
+	
+	return separators * getFontHeight();
 }
 
 } // End of namespace Draci

Modified: scummvm/branches/gsoc2009-draci/engines/draci/font.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/font.h	2009-07-27 03:01:06 UTC (rev 42831)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.h	2009-07-27 03:08:19 UTC (rev 42832)
@@ -68,6 +68,8 @@
 					int x, int y, int spacing, bool markDirty = true) const;
 	
 	int getStringWidth(const Common::String &str, int spacing = 0) const;
+	int getStringHeight(const Common::String &str) const;
+
 	void setColour(uint8 colour);
 
 private:


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