aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-24 17:16:32 -0400
committerPaul Gilbert2016-07-10 16:12:00 -0400
commitc75de59a28c94e364a38af39057af720ba8465d4 (patch)
tree0fbd1ac099d39b31f2791193c26f172bfc23b178 /engines/titanic
parenta88c0b09994562d4576e7dd08db8ad2fe3326f53 (diff)
downloadscummvm-rg350-c75de59a28c94e364a38af39057af720ba8465d4.tar.gz
scummvm-rg350-c75de59a28c94e364a38af39057af720ba8465d4.tar.bz2
scummvm-rg350-c75de59a28c94e364a38af39057af720ba8465d4.zip
TITANIC: Implementing font text bounds calculations
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/support/font.cpp67
-rw-r--r--engines/titanic/support/font.h20
-rw-r--r--engines/titanic/support/screen_manager.cpp14
-rw-r--r--engines/titanic/support/screen_manager.h39
4 files changed, 123 insertions, 17 deletions
diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp
index 55865e792c..f5d28ea9ca 100644
--- a/engines/titanic/support/font.cpp
+++ b/engines/titanic/support/font.cpp
@@ -70,8 +70,39 @@ uint16 STFont::getColor() const {
return g_system->getScreenFormat().RGBToColor(_fontR, _fontG, _fontB);
}
-void STFont::writeString(int maxWidth, const CString &text, int *v1, int *v2) {
- warning("TODO: STFont::writeString");
+int STFont::getTextBounds(const CString &str, int maxWidth, Point *sizeOut) const {
+ Point textSize;
+
+ // Reset output dimensions if provided
+ if (sizeOut)
+ *sizeOut = Point(0, 0);
+
+ if (_fontHeight == 0 || !_dataPtr)
+ // No font, so return immediately
+ return 0;
+
+ // Loop through the characters of the string
+ if (!str.empty()) {
+ for (const char *strP = str.c_str(); *strP; ++strP) {
+ if (*strP == 26) {
+ strP += 3;
+ } else if (*strP == 27) {
+ strP += 4;
+ } else {
+ if (*strP == ' ') {
+ // Check fo rline wrapping
+ checkLineWrap(textSize, maxWidth, strP);
+ }
+
+ extendBounds(textSize, *strP, maxWidth);
+ }
+ }
+ }
+
+ if (sizeOut)
+ *sizeOut = textSize;
+
+ return textSize.y + _fontHeight;
}
int STFont::stringWidth(const CString &text) const {
@@ -160,4 +191,36 @@ void STFont::copyRect(CVideoSurface *surface, const Common::Point &pt, Rect &rec
}
}
+void STFont::extendBounds(Point &textSize, byte c, int maxWidth) const {
+ textSize.x += _chars[c]._width;
+
+ if (textSize.x == '\n' || textSize.x > maxWidth) {
+ textSize.x = 0;
+ textSize.y += _fontHeight;
+ }
+}
+
+void STFont::checkLineWrap(Point &textSize, int maxWidth, const char *&str) const {
+ bool flag = false;
+ int totalWidth = 0;
+ for (const char *srcPtr = str; *srcPtr; ++srcPtr) {
+ if (*srcPtr == ' ' && flag)
+ break;
+
+ if (*srcPtr == 26)
+ srcPtr += 3;
+ else if (*srcPtr == 27)
+ srcPtr += 4;
+ else
+ totalWidth += _chars[*srcPtr]._width;
+ }
+
+ if ((textSize.x + totalWidth) >= maxWidth && totalWidth < maxWidth) {
+ // Word wrap
+ textSize.x = 0;
+ textSize.y += _fontHeight;
+ ++str;
+ }
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/support/font.h b/engines/titanic/support/font.h
index 5ed0b5b7b4..e1c63e6544 100644
--- a/engines/titanic/support/font.h
+++ b/engines/titanic/support/font.h
@@ -50,6 +50,17 @@ private:
*/
int writeChar(CVideoSurface *surface, unsigned char c,
const Common::Point &pt, Rect *destRect, Rect *srcRect);
+
+ /**
+ * Extends a passed text area by the space required for
+ * the given character
+ */
+ void extendBounds(Point &textSize, byte c, int maxWidth) const;
+
+ /**
+ * Called at spacing between words, checks for line wrapping
+ */
+ void checkLineWrap(Point &textSize, int maxWidth, const char *&str) const;
public:
byte *_dataPtr;
size_t _dataSize;
@@ -72,10 +83,13 @@ public:
int stringWidth(const CString &text) const;
/**
- * Write out a string
- * TODO: Verify this
+ * Get the text area a string will fit into
+ * @param str String
+ * @param maxWidth Maximum width in pixels
+ * @param sizeOut Optional pointer to output size (width, height)
+ * @returns Required height
*/
- void writeString(int maxWidth, const CString &text, int *v1, int *v2);
+ int getTextBounds(const CString &str, int maxWidth, Point *sizeOut) const;
/**
* Sets the font color
diff --git a/engines/titanic/support/screen_manager.cpp b/engines/titanic/support/screen_manager.cpp
index d2f2468c89..f772bc6f7e 100644
--- a/engines/titanic/support/screen_manager.cpp
+++ b/engines/titanic/support/screen_manager.cpp
@@ -199,12 +199,18 @@ void OSScreenManager::proc13() {}
void OSScreenManager::proc14() {}
void OSScreenManager::proc15() {}
-void OSScreenManager::writeString(int maxWidth, const CString &text, int *v1, int *v2) {
- _fonts[_fontNumber].writeString(maxWidth, text, v1, v2);
+int OSScreenManager::getTextBounds(const CString &str, int maxWidth, Point *sizeOut) const {
+ return _fonts[_fontNumber].getTextBounds(str, maxWidth, sizeOut);
+}
+
+int OSScreenManager::getFontHeight() const {
+ return _fonts[_fontNumber]._fontHeight;
+}
+
+int OSScreenManager::stringWidth(const CString &str) {
+ return _fonts[_fontNumber].stringWidth(str);
}
-void OSScreenManager::getFont() {}
-void OSScreenManager::proc18() {}
void OSScreenManager::proc19() {}
void OSScreenManager::clearSurface(SurfaceNum surfaceNum, Rect *bounds) {
diff --git a/engines/titanic/support/screen_manager.h b/engines/titanic/support/screen_manager.h
index d0580d4957..baba662564 100644
--- a/engines/titanic/support/screen_manager.h
+++ b/engines/titanic/support/screen_manager.h
@@ -110,14 +110,25 @@ public:
virtual void proc14() = 0;
virtual void proc15() = 0;
+ /**
+ * Get the text area a string will fit into
+ * @param str String
+ * @param maxWidth Maximum width in pixels
+ * @param sizeOut Optional pointer to output size
+ * @returns Required height
+ */
+ virtual int getTextBounds(const CString &str, int maxWidth, Point *sizeOut = nullptr) const = 0;
+
+ /**
+ * Get the current font height
+ */
+ virtual int getFontHeight() const = 0;
/**
- * Write out a string
+ * Returns the width of a given string in pixels
*/
- virtual void writeString(int maxWidth, const CString &text, int *v1, int *v2) = 0;
+ virtual int stringWidth(const CString &str) = 0;
- virtual void getFont() = 0;
- virtual void proc18() = 0;
virtual void proc19() = 0;
/**
@@ -216,12 +227,24 @@ public:
virtual void proc15();
/**
- * Write out a string
+ * Get the text area a string will fit into
+ * @param str String
+ * @param maxWidth Maximum width in pixels
+ * @param sizeOut Optional pointer to output size
+ * @returns Required height
+ */
+ virtual int getTextBounds(const CString &str, int maxWidth, Point *sizeOut = nullptr) const;
+
+ /**
+ * Get the current font height
+ */
+ virtual int getFontHeight() const;
+
+ /**
+ * Returns the width of a given string in pixels
*/
- virtual void writeString(int maxWidth, const CString &text, int *v1, int *v2);
+ virtual int stringWidth(const CString &str);
- virtual void getFont();
- virtual void proc18();
virtual void proc19();
/**