diff options
author | Paul Gilbert | 2016-05-01 13:56:42 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-10 16:38:00 -0400 |
commit | f01b8e9c45e3349c84346f270c17610b0e5350b0 (patch) | |
tree | f6169ad8205219c3d451c6a81b91b64333525b91 /engines | |
parent | 21f98fff46e48e79d3e977d4f20edf90022a825a (diff) | |
download | scummvm-rg350-f01b8e9c45e3349c84346f270c17610b0e5350b0.tar.gz scummvm-rg350-f01b8e9c45e3349c84346f270c17610b0e5350b0.tar.bz2 scummvm-rg350-f01b8e9c45e3349c84346f270c17610b0e5350b0.zip |
TITANIC: Fix multi-line text writing
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/pet_control/pet_text.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/support/font.cpp | 28 | ||||
-rw-r--r-- | engines/titanic/support/font.h | 11 |
3 files changed, 26 insertions, 19 deletions
diff --git a/engines/titanic/pet_control/pet_text.cpp b/engines/titanic/pet_control/pet_text.cpp index 1d2740249f..a4e00424fe 100644 --- a/engines/titanic/pet_control/pet_text.cpp +++ b/engines/titanic/pet_control/pet_text.cpp @@ -267,7 +267,7 @@ void CPetText::setMaxCharsPerLine(int maxChars) { void CPetText::updateStr3(int lineNum) { if (_field64 > 0 && _field68 > 0) { char line[5]; - line[0] = line[3] = TEXTCMD_26; + line[0] = line[3] = TEXTCMD_NPC; line[1] = _field64; line[2] = _field68; line[4] = '\0'; @@ -333,7 +333,7 @@ void CPetText::scrollToTop(CScreenManager *screenManager) { void CPetText::scrollToBottom(CScreenManager *screenManager) { int oldFontNumber = screenManager->setFontNumber(_fontNumber); - _scrollTop = _bounds.height(); + _scrollTop = getTextHeight(screenManager); constrainScrollDown(screenManager); screenManager->setFontNumber(oldFontNumber); } @@ -345,7 +345,7 @@ void CPetText::constrainScrollUp(CScreenManager *screenManager) { void CPetText::constrainScrollDown(CScreenManager *screenManager) { // Figure out the maximum scroll amount allowed - int maxScroll = _bounds.height() - getTextHeight(screenManager) - 4; + int maxScroll = getTextHeight(screenManager) - _bounds.height() - 4; if (maxScroll < 0) maxScroll = 0; diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp index 3d5705ac5a..cc93bbb3c2 100644 --- a/engines/titanic/support/font.cpp +++ b/engines/titanic/support/font.cpp @@ -84,7 +84,7 @@ int STFont::getTextBounds(const CString &str, int maxWidth, Point *sizeOut) cons // Loop through the characters of the string if (!str.empty()) { for (const char *strP = str.c_str(); *strP; ++strP) { - if (*strP == TEXTCMD_26) { + if (*strP == TEXTCMD_NPC) { strP += 3; } else if (*strP == TEXTCMD_SET_COLOR) { strP += 4; @@ -141,7 +141,7 @@ int STFont::writeString(CVideoSurface *surface, const Rect &rect1, const Rect &d const char *endP = nullptr; const char *strEndP = str.c_str() + str.size() - 1; for (const char *srcP = str.c_str(); *srcP; ++srcP) { - if (*srcP == TEXTCMD_26) { + if (*srcP == TEXTCMD_NPC) { srcP += 3; } else if (*srcP == TEXTCMD_SET_COLOR) { // Change the color used for characters @@ -159,10 +159,10 @@ int STFont::writeString(CVideoSurface *surface, const Rect &rect1, const Rect &d } if (*srcP != '\n') { - int result = writeChar(surface, *srcP, textSize, rect1, &destBounds); - if (result == -2) + WriteCharacterResult result = writeChar(surface, *srcP, textSize, rect1, &destBounds); + if (result == WC_OUTSIDE_BOTTOM) return endP - str.c_str(); - else if (!result) + else if (result == WC_IN_BOUNDS) endP = srcP; } @@ -176,10 +176,10 @@ int STFont::writeString(CVideoSurface *surface, const Rect &rect1, const Rect &d textCursor->setPos(cursorPos); } - return endP - str.c_str(); + return endP ? endP - str.c_str() : 0; } -int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, +WriteCharacterResult STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, const Rect &destRect, const Rect *srcRect) { if (c == 233) c = '$'; @@ -194,7 +194,7 @@ int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, if (srcRect->isEmpty()) srcRect = &destRect; if (destPos.y > srcRect->bottom) - return -2; + return WC_OUTSIDE_BOTTOM; if ((destPos.y + tempRect.height()) > srcRect->bottom) { tempRect.bottom += tempRect.top - destPos.y; @@ -202,7 +202,7 @@ int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, if (destPos.y < srcRect->top) { if ((tempRect.height() + destPos.y) < srcRect->top) - return -1; + return WC_OUTSIDE_TOP; tempRect.top += srcRect->top - destPos.y; destPos.y = srcRect->top; @@ -210,21 +210,21 @@ int STFont::writeChar(CVideoSurface *surface, unsigned char c, const Point &pt, if (destPos.x < srcRect->left) { if ((tempRect.width() + destPos.x) < srcRect->left) - return -3; + return WC_OUTSIDE_LEFT; tempRect.left += srcRect->left - destPos.x; destPos.x = srcRect->left; } else { if ((tempRect.width() + destPos.x) > srcRect->right) { if (destPos.x > srcRect->right) - return -4; + return WC_OUTSIDE_RIGHT; tempRect.right += srcRect->left - destPos.x; } } copyRect(surface, destPos, tempRect); - return 0; + return WC_IN_BOUNDS; } void STFont::copyRect(CVideoSurface *surface, const Point &pt, Rect &rect) { @@ -247,7 +247,7 @@ void STFont::copyRect(CVideoSurface *surface, const Point &pt, Rect &rect) { void STFont::extendBounds(Point &textSize, byte c, int maxWidth) const { textSize.x += _chars[c]._width; - if (textSize.x == '\n' || textSize.x > maxWidth) { + if (c == '\n' || textSize.x > maxWidth) { textSize.x = 0; textSize.y += _fontHeight; } @@ -260,7 +260,7 @@ void STFont::checkLineWrap(Point &textSize, int maxWidth, const char *&str) cons if (*srcPtr == ' ' && flag) break; - if (*srcPtr == TEXTCMD_26) + if (*srcPtr == TEXTCMD_NPC) srcPtr += 3; else if (*srcPtr == TEXTCMD_SET_COLOR) srcPtr += 4; diff --git a/engines/titanic/support/font.h b/engines/titanic/support/font.h index 75c91f3d36..591fb4661c 100644 --- a/engines/titanic/support/font.h +++ b/engines/titanic/support/font.h @@ -31,7 +31,12 @@ namespace Titanic { -enum TextCommand { TEXTCMD_26 = 26, TEXTCMD_SET_COLOR = 27 }; +enum TextCommand { TEXTCMD_NPC = 26, TEXTCMD_SET_COLOR = 27 }; + +enum WriteCharacterResult { + WC_IN_BOUNDS = 0, WC_OUTSIDE_TOP = -1, WC_OUTSIDE_BOTTOM = -2, + WC_OUTSIDE_LEFT = -3, WC_OUTSIDE_RIGHT = -4 +}; class CVideoSurface; @@ -51,7 +56,7 @@ private: /** * Write a character */ - int writeChar(CVideoSurface *surface, unsigned char c, + WriteCharacterResult writeChar(CVideoSurface *surface, unsigned char c, const Common::Point &pt, const Rect &destRect, const Rect *srcRect); /** @@ -87,6 +92,8 @@ public: /** * Write a string to the specified surface + * @returns The index of the last character that was visible + * with the drawing area */ int writeString(CVideoSurface *surface, const Rect &rect1, const Rect &destRect, int yOffset, const CString &str, CTextCursor *textCursor); |