[Scummvm-cvs-logs] SF.net SVN: scummvm:[55184] scummvm/trunk/engines/sci/graphics/frameout.cpp
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Sun Jan 9 14:28:35 CET 2011
Revision: 55184
http://scummvm.svn.sourceforge.net/scummvm/?rev=55184&view=rev
Author: thebluegr
Date: 2011-01-09 13:28:34 +0000 (Sun, 09 Jan 2011)
Log Message:
-----------
SCI2: Implemented proper text splitting
Modified Paths:
--------------
scummvm/trunk/engines/sci/graphics/frameout.cpp
Modified: scummvm/trunk/engines/sci/graphics/frameout.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/frameout.cpp 2011-01-09 13:27:00 UTC (rev 55183)
+++ scummvm/trunk/engines/sci/graphics/frameout.cpp 2011-01-09 13:28:34 UTC (rev 55184)
@@ -301,6 +301,42 @@
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 @@
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
}
+
}
}
}
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