diff options
author | Paweł Kołodziejski | 2002-09-20 05:46:03 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2002-09-20 05:46:03 +0000 |
commit | a4fc2c4174e189372fa31bddfbca32299f6bed7a (patch) | |
tree | 8f1775de772e9f095e5be64c592dd19ac8eba645 /scumm/smush | |
parent | e0f11edf45361eb79ee281254602edc1748007e0 (diff) | |
download | scummvm-rg350-a4fc2c4174e189372fa31bddfbca32299f6bed7a.tar.gz scummvm-rg350-a4fc2c4174e189372fa31bddfbca32299f6bed7a.tar.bz2 scummvm-rg350-a4fc2c4174e189372fa31bddfbca32299f6bed7a.zip |
fixed placement subtitles in smush(the dig)
svn-id: r4980
Diffstat (limited to 'scumm/smush')
-rw-r--r-- | scumm/smush/frenderer.cpp | 74 | ||||
-rw-r--r-- | scumm/smush/frenderer.h | 1 | ||||
-rw-r--r-- | scumm/smush/player.cpp | 28 |
3 files changed, 101 insertions, 2 deletions
diff --git a/scumm/smush/frenderer.cpp b/scumm/smush/frenderer.cpp index eb75a2bde4..93534d7c02 100644 --- a/scumm/smush/frenderer.cpp +++ b/scumm/smush/frenderer.cpp @@ -232,3 +232,77 @@ bool FontRenderer::drawStringCentered(const char * str, char * buffer, const Poi delete []substrings; return true; } + +bool FontRenderer::drawStringWrap(const char * str, char * buffer, const Point & size, int32 x, int32 y, int32 width) const { + debug(9, "FontRenderer::drawStringWrap(%s, %d, %d)", str, x, y); + assert(strchr(str, '\n') == 0); + char * * words = split(str, ' '); + int32 nb_sub = 0; + + while(words[nb_sub]) nb_sub++; + + int32 * sizes = new int32[nb_sub]; + int32 i = 0, max_width = 0, height = 0, nb_subs = 0, left_x; + + for(i = 0; i < nb_sub; i++) + sizes[i] = stringWidth(words[i]); + + char * * substrings = new char *[nb_sub]; + int32 * substr_widths = new int32[nb_sub]; + int32 space_width = charWidth(' '); + + i = 0; + while(i < nb_sub) { + int32 substr_width = sizes[i]; + char * substr = new char[1000]; + strcpy(substr, words[i]); + int32 j = i + 1; + + while(j < nb_sub && (substr_width + space_width + sizes[j]) < width) { + substr_width += sizes[j++] + space_width; + } + + for(int32 k = i + 1; k < j; k++) { + strcat(substr, " "); + strcat(substr, words[k]); + } + + substrings[nb_subs] = substr; + substr_widths[nb_subs++] = substr_width; + i = j; + height += stringHeight(substr); + } + + delete []sizes; + for(i = 0; i < nb_sub; i++) { + delete []words[i]; + } + delete []words; + + if(y + height > size.getY()) { + y = size.getY() - height; + } + + for(i = 0; i < nb_subs; i++) + max_width = MAX(max_width, substr_widths[i]); + + if(max_width + x > size.getX()) + left_x = size.getX() - max_width + charWidth(' '); + else + left_x = x; + + if(max_width + left_x > size.getX()) + left_x = size.getX() - max_width; + + for(i = 0; i < nb_subs; i++) { + int32 substr_width = substr_widths[i]; + drawSubstring((const byte *)substrings[i], buffer, size, left_x, y); + y += stringHeight(substrings[i]); + delete []substrings[i]; + } + + delete []substr_widths; + delete []substrings; + return true; +} + diff --git a/scumm/smush/frenderer.h b/scumm/smush/frenderer.h index c0210ab4d7..e3d6c236f2 100644 --- a/scumm/smush/frenderer.h +++ b/scumm/smush/frenderer.h @@ -148,6 +148,7 @@ public: @return \c true if everything went fine, \c false otherwise */ bool drawStringCentered(const char * str, char * buffer, const Point & size, int32 y, int32 xmin, int32 width, int32 offset) const; + bool drawStringWrap(const char * str, char * buffer, const Point & size, int32 x, int32 y, int32 width) const; /*! @brief draw a string at an absolute position. @param str the string to draw. diff --git a/scumm/smush/player.cpp b/scumm/smush/player.cpp index b61a746e40..7154b4b38e 100644 --- a/scumm/smush/player.cpp +++ b/scumm/smush/player.cpp @@ -380,11 +380,35 @@ void SmushPlayer::handleTextResource(Chunk & b) { assert(fr != 0); fr->setColor(color); if(!_curBuffer) { _curBuffer = _renderer->lockFrame(_frame); } - if(flags == 0 || flags == 4) { + + // flags: + // bit 0 - center 1 + // bit 1 - not used 2 + // bit 2 - ??? 4 + // bit 3 - wrap around 8 + if(flags == 0) { fr->drawStringAbsolute(str, _curBuffer, _frameSize, pos_x, pos_y); - } else { + } + else if(flags == 1) { + fr->drawStringCentered(str, _curBuffer, _frameSize, MAX(pos_y, top), left, width, pos_x); + } + else if(flags == 4) { + fr->drawStringAbsolute(str, _curBuffer, _frameSize, pos_x, pos_y); + } + else if(flags == 5) { + fr->drawStringCentered(str, _curBuffer, _frameSize, MAX(pos_y, top), left, width, pos_x); + } + else if(flags == 8) { + fr->drawStringWrap(str, _curBuffer, _frameSize, pos_x, MAX(pos_y, top), width); + } + else if(flags == 12) { + fr->drawStringWrap(str, _curBuffer, _frameSize, pos_x, MAX(pos_y, top), width); + } + else if(flags == 13) { fr->drawStringCentered(str, _curBuffer, _frameSize, MAX(pos_y, top), left, width, pos_x); } + else + warning("SmushPlayer::handleTextResource. Not handled flags: %d\n", flags); } void SmushPlayer::readPalette(Palette & out, Chunk & in) { |