aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/draci/font.cpp71
-rw-r--r--engines/draci/font.h5
2 files changed, 51 insertions, 25 deletions
diff --git a/engines/draci/font.cpp b/engines/draci/font.cpp
index 4902965aa3..2a9185e725 100644
--- a/engines/draci/font.cpp
+++ b/engines/draci/font.cpp
@@ -209,20 +209,37 @@ void Font::drawChar(Surface *dst, uint8 chr, int tx, int ty, bool markDirty) con
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;
- int cury = y;
+ uint widest = getStringWidth(str, spacing);
- for (unsigned int i = 0; i < len; ++i) {
+ int curx = x + (widest - getLineWidth(str, 0, spacing)) / 2;
+ int cury = y;
+
+ for (uint i = 0; i < str.size(); ++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 @@ void Font::drawString(Surface *dst, const byte *str, uint len,
}
/**
- * @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 @@ void Font::drawString(Surface *dst, const Common::String &str,
* @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 @@ int Font::getStringWidth(const Common::String &str, int spacing) const {
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::getStringWidth(const Common::String &str, int spacing) const {
*/
-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 @@ int Font::getStringHeight(const Common::String &str) const {
}
return separators * getFontHeight();
-}
+}
} // End of namespace Draci
diff --git a/engines/draci/font.h b/engines/draci/font.h
index 67c32aa791..5ccf1f1cf8 100644
--- a/engines/draci/font.h
+++ b/engines/draci/font.h
@@ -67,8 +67,9 @@ public:
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);