diff options
author | Filippos Karapetis | 2011-01-09 13:28:34 +0000 |
---|---|---|
committer | Filippos Karapetis | 2011-01-09 13:28:34 +0000 |
commit | db11b626c7314db14a4db89158b3b9d31fc16120 (patch) | |
tree | 2aa5f1b05cd1a0871e604eead37140d9f882a0ff /engines/sci | |
parent | 6b6e7fcfb3891b343285ec2a90daaf810ca63367 (diff) | |
download | scummvm-rg350-db11b626c7314db14a4db89158b3b9d31fc16120.tar.gz scummvm-rg350-db11b626c7314db14a4db89158b3b9d31fc16120.tar.bz2 scummvm-rg350-db11b626c7314db14a4db89158b3b9d31fc16120.zip |
SCI2: Implemented proper text splitting
svn-id: r55184
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/graphics/frameout.cpp | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp index e51bfbaf13..01b17ae4f8 100644 --- a/engines/sci/graphics/frameout.cpp +++ b/engines/sci/graphics/frameout.cpp @@ -301,6 +301,42 @@ void GfxFrameout::sortPlanes() { Common::sort(_planes.begin(), _planes.end(), planeSortHelper); } +static int16 GetLongest(const char *text, int16 maxWidth, GfxFont *font) { + uint16 curChar = 0; + int16 maxChars = 0, curCharCount = 0; + uint16 width = 0; + + while (width <= maxWidth) { + curChar = (*(const byte *)text++); + + switch (curChar) { + // We need to add 0xD, 0xA and 0xD 0xA to curCharCount and then exit + // which means, we split text like + // 'Mature, experienced software analyst available.' 0xD 0xA + // 'Bug installation a proven speciality. "No version too clean."' (normal game text, this is from lsl2) + // and 0xA '-------' 0xA (which is the official sierra subtitle separator) + // Sierra did it the same way. + case 0xD: + // Check, if 0xA is following, if so include it as well + if ((*(const unsigned char *)text) == 0xA) + curCharCount++; + // it's meant to pass through here + case 0xA: + curCharCount++; + // and it's also meant to pass through here + case 0: + return curCharCount; + case ' ': + maxChars = curCharCount; // return count up to (but not including) breaking space + break; + } + width += font->getCharWidth(curChar); + curCharCount++; + } + + return maxChars; +} + void GfxFrameout::kernelFrameout() { _palette->palVaryUpdate(); @@ -523,17 +559,28 @@ void GfxFrameout::kernelFrameout() { uint16 curX = itemEntry->x + it->planeRect.left; uint16 curY = itemEntry->y + it->planeRect.top; - for (uint32 i = 0; i < text.size(); i++) { - unsigned char curChar = text[i]; - // TODO: proper text splitting... this is a hack - if ((curChar == ' ' && i > 0 && text[i - i] == ' ') || curChar == '\n' || - (curX + font->getCharWidth(curChar) > _screen->getWidth())) { - curY += font->getHeight(); - curX = itemEntry->x; + const char *txt = text.c_str(); + uint16 w = it->planeRect.width() >= 20 ? it->planeRect.width() : _screen->getWidth() - 10; + int16 charCount; + + while (*txt) { + charCount = GetLongest(txt, w, font); + if (charCount == 0) + break; + + for (int i = 0; i < charCount; i++) { + unsigned char curChar = txt[i]; + font->draw(curChar, curY, curX, foreColor, dimmed); + curX += font->getCharWidth(curChar); } - font->draw(curChar, curY, curX, foreColor, dimmed); - curX += font->getCharWidth(curChar); + + curX = itemEntry->x + it->planeRect.left; + curY += font->getHeight(); + txt += charCount; + while (*txt == ' ') + txt++; // skip over breaking spaces } + } } } |