[Scummvm-cvs-logs] SF.net SVN: scummvm:[43053] scummvm/branches/gsoc2009-draci/engines/draci
dkasak13 at users.sourceforge.net
dkasak13 at users.sourceforge.net
Tue Aug 4 21:23:59 CEST 2009
Revision: 43053
http://scummvm.svn.sourceforge.net/scummvm/?rev=43053&view=rev
Author: dkasak13
Date: 2009-08-04 19:23:59 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
* Added Font::getLineWidth()
* Changed Font::getStringWidth() and Font::getStringHeight() to return uint instead of int.
* Made the Font::drawString() overload which accepts a Common::String the "default" one. The overload accepting a (byte *) now calls that one (it was the other way around before).
* Added proper line centering to the Font::drawString() routine.
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-08-04 19:09:41 UTC (rev 43052)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.cpp 2009-08-04 19:23:59 UTC (rev 43053)
@@ -209,20 +209,37 @@
void Font::drawString(Surface *dst, const byte *str, uint len,
int x, int y, int spacing, bool markDirty) const {
+ drawString(dst, Common::String((const char *)str, len), x, y, spacing, markDirty);
+}
+
+/**
+ * @brief Draw a string to a Draci::Surface
+ *
+ * @param dst Pointer to the destination surface
+ * @param str String to draw
+ * @param x Horizontal offset on the surface
+ * @param y Vertical offset on the surface
+ * @param spacing Space to leave between individual characters. Defaults to 0.
+ */
+
+void Font::drawString(Surface *dst, const Common::String &str,
+ int x, int y, int spacing, bool markDirty) const {
assert(dst != NULL);
assert(x >= 0);
assert(y >= 0);
- int curx = x;
+ uint widest = getStringWidth(str, spacing);
+
+ int curx = x + (widest - getLineWidth(str, 0, spacing)) / 2;
int cury = y;
+
+ for (uint i = 0; i < str.size(); ++i) {
- for (unsigned int i = 0; i < len; ++i) {
-
// 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();
- curx = x;
+ curx = x + (widest - getLineWidth(str, i+1, spacing) - 1) / 2;
continue;
}
@@ -237,22 +254,6 @@
}
/**
- * @brief Draw a string to a Draci::Surface
- *
- * @param dst Pointer to the destination surface
- * @param str String to draw
- * @param x Horizontal offset on the surface
- * @param y Vertical offset on the surface
- * @param spacing Space to leave between individual characters. Defaults to 0.
- */
-
-void Font::drawString(Surface *dst, const Common::String &str,
- int x, int y, int spacing, bool markDirty) const {
-
- drawString(dst, (byte *) str.c_str(), str.size(), x, y, spacing, markDirty);
-}
-
-/**
* @brief Calculate the width of a string when drawn in the current font
*
* @param str String to draw
@@ -261,7 +262,7 @@
* @return The calculated width of the string
*/
-int Font::getStringWidth(const Common::String &str, int spacing) const {
+uint Font::getStringWidth(const Common::String &str, int spacing) const {
unsigned int width = 0;
// Real length, including '|' separators
@@ -290,6 +291,30 @@
return width + 1;
}
+uint Font::getLineWidth(const Common::String &str, uint startIndex, int spacing) const {
+
+ uint width = 0;
+
+ // If the index is greater or equal to the string size,
+ // the width of the line is 0
+ if (startIndex >= str.size())
+ return 0;
+
+ for (uint i = startIndex; i < str.size(); ++i) {
+
+ // EOL encountered
+ if (str[i] == '|')
+ break;
+
+ // Add width of the current char
+ uint8 charIndex = str[i] - kCharIndexOffset;
+ width += _charWidths[charIndex];
+ width += spacing;
+ }
+
+ 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)
@@ -301,7 +326,7 @@
*/
-int Font::getStringHeight(const Common::String &str) const {
+uint Font::getStringHeight(const Common::String &str) const {
uint len = str.size();
int separators = 0;
@@ -314,6 +339,6 @@
}
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-08-04 19:09:41 UTC (rev 43052)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.h 2009-08-04 19:23:59 UTC (rev 43053)
@@ -67,8 +67,9 @@
void drawString(Surface *dst, const Common::String &str,
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;
+ uint getStringWidth(const Common::String &str, int spacing = 0) const;
+ uint getStringHeight(const Common::String &str) const;
+ uint getLineWidth(const Common::String &str, uint startIndex, int spacing = 0) const;
void setColour(uint8 colour);
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