SCI2: Implemented proper text splitting

svn-id: r55184
This commit is contained in:
Filippos Karapetis 2011-01-09 13:28:34 +00:00
parent 6b6e7fcfb3
commit db11b626c7

View File

@ -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
}
}
}
}