aboutsummaryrefslogtreecommitdiff
path: root/scumm/smush
diff options
context:
space:
mode:
authorPaweł Kołodziejski2002-11-16 09:08:48 +0000
committerPaweł Kołodziejski2002-11-16 09:08:48 +0000
commit34782f17abfd86e40be5f1ea474372e22d49b12a (patch)
tree7fff9000df215071718cacd5bea82c9cfb88ad41 /scumm/smush
parentcec1a5a2cd33121c6ace00a2d068d37628ba852e (diff)
downloadscummvm-rg350-34782f17abfd86e40be5f1ea474372e22d49b12a.tar.gz
scummvm-rg350-34782f17abfd86e40be5f1ea474372e22d49b12a.tar.bz2
scummvm-rg350-34782f17abfd86e40be5f1ea474372e22d49b12a.zip
DIG: fixed subtitles in Space Time Six smush movie
svn-id: r5580
Diffstat (limited to 'scumm/smush')
-rw-r--r--scumm/smush/frenderer.cpp62
-rw-r--r--scumm/smush/frenderer.h1
-rw-r--r--scumm/smush/player.cpp2
3 files changed, 63 insertions, 2 deletions
diff --git a/scumm/smush/frenderer.cpp b/scumm/smush/frenderer.cpp
index 008655fdcd..d8923f4722 100644
--- a/scumm/smush/frenderer.cpp
+++ b/scumm/smush/frenderer.cpp
@@ -295,7 +295,6 @@ bool FontRenderer::drawStringWrap(const char * str, char * buffer, const Point &
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];
@@ -306,3 +305,64 @@ bool FontRenderer::drawStringWrap(const char * str, char * buffer, const Point &
return true;
}
+bool FontRenderer::drawStringWrapCentered(const char * str, char * buffer, const Point & size, int32 x, int32 y, int32 width) const {
+ debug(9, "FontRenderer::drawStringWrapCentered(%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;
+
+ 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]) < size.getX()) {
+ 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++) {
+ int32 substr_width = substr_widths[i];
+ drawSubstring((const byte *)substrings[i], buffer, size, x - substr_width / 2, 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 e3d6c236f2..cd1e74fed0 100644
--- a/scumm/smush/frenderer.h
+++ b/scumm/smush/frenderer.h
@@ -149,6 +149,7 @@ public:
*/
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;
+ bool drawStringWrapCentered(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 5b3913f039..3ec5e94cff 100644
--- a/scumm/smush/player.cpp
+++ b/scumm/smush/player.cpp
@@ -411,7 +411,7 @@ void SmushPlayer::handleTextResource(Chunk & b) {
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);
+ fr->drawStringWrapCentered(str, _curBuffer, _frameSize, pos_x, MAX(pos_y, top), width);
}
else
warning("SmushPlayer::handleTextResource. Not handled flags: %d\n", flags);