aboutsummaryrefslogtreecommitdiff
path: root/scumm/smush
diff options
context:
space:
mode:
authorTorbjörn Andersson2003-06-09 12:24:05 +0000
committerTorbjörn Andersson2003-06-09 12:24:05 +0000
commit5813724a33ab4228530d8cd9c34b52673bb03b53 (patch)
treea155786ab89020015dd01ee9d7d0dfd11b620dc9 /scumm/smush
parent5ab796c4de25da84b564bd9a486cfeb5f8c5cbb3 (diff)
downloadscummvm-rg350-5813724a33ab4228530d8cd9c34b52673bb03b53.tar.gz
scummvm-rg350-5813724a33ab4228530d8cd9c34b52673bb03b53.tar.bz2
scummvm-rg350-5813724a33ab4228530d8cd9c34b52673bb03b53.zip
Fixed text-positioning regressions in the Full Throttle intro and in The
Dig's "Spacetime Six" movie. Also rewrote drawStringCentered() to be more like drawStringAbsolute(). It makes sense to me, but let me know if it causes any new regressions. svn-id: r8415
Diffstat (limited to 'scumm/smush')
-rw-r--r--scumm/smush/smush_font.cpp80
-rw-r--r--scumm/smush/smush_font.h2
-rw-r--r--scumm/smush/smush_player.cpp16
3 files changed, 35 insertions, 63 deletions
diff --git a/scumm/smush/smush_font.cpp b/scumm/smush/smush_font.cpp
index 38d6ffaa6b..d983a7d6a9 100644
--- a/scumm/smush/smush_font.cpp
+++ b/scumm/smush/smush_font.cpp
@@ -137,6 +137,12 @@ int SmushFont::draw2byte(byte *buffer, int dst_width, int x, int y, int idx) {
}
void SmushFont::drawSubstring(const char *str, byte *buffer, int dst_width, int x, int y) {
+ // This happens in the Full Throttle intro. I don't know if our
+ // text-drawing functions are buggy, or if this function is supposed
+ // to have to check for it.
+ if (x < 0)
+ x = 0;
+
for (int i = 0; str[i] != 0; i++) {
if ((byte)str[i] >= 0x80 && _vm->_CJKMode) {
x += draw2byte(buffer, dst_width, x, y, (byte)str[i] + 256 * (byte)str[i+1]);
@@ -168,69 +174,23 @@ void SmushFont::drawStringAbsolute(const char *str, byte *buffer, int dst_width,
}
}
-void SmushFont::drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
- debug(9, "SmushFont::drawStringCentered(%s, %d, %d, %d, %d)", str, x, y, left, right);
-
- const int width = right - left;
- char *s = strdup(str);
- char *words[MAX_WORDS];
- int word_count = 0;
-
- char *tmp = s;
- while (tmp) {
- assert(word_count < MAX_WORDS);
- words[word_count++] = tmp;
- tmp = strpbrk(tmp, " \t\r\n");
- if (tmp == 0)
- break;
- *tmp++ = 0;
- }
-
- int i = 0, max_width = 0, height = 0, line_count = 0;
+void SmushFont::drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y) {
+ debug(9, "SmushFont::drawStringCentered(%s, %d, %d)", str, x, y);
- char *substrings[MAX_WORDS];
- int substr_widths[MAX_WORDS];
- const int space_width = getCharWidth(' ');
-
- i = 0;
- while (i < word_count) {
- char *substr = words[i++];
- int substr_width = getStringWidth(substr);
-
- while (i < word_count) {
- int word_width = getStringWidth(words[i]);
- if ((substr_width + space_width + word_width) >= width)
- break;
- substr_width += word_width + space_width;
- *(words[i]-1) = ' '; // Convert 0 byte back to space
- i++;
+ while (str) {
+ char line[256];
+ char *pos = strchr(str, '\n');
+ if (pos) {
+ memcpy(line, str, pos - str - 1);
+ line[pos - str - 1] = 0;
+ str = pos + 1;
+ } else {
+ strcpy(line, str);
+ str = 0;
}
-
- substrings[line_count] = substr;
- substr_widths[line_count++] = substr_width;
- if (max_width < substr_width)
- max_width = substr_width;
- height += getStringHeight(substr);
- }
-
- if (y > dst_height - height) {
- y = dst_height - height;
- }
-
- max_width = (max_width + 1) >> 1;
- x = left + width / 2;
-
- if (x < left + max_width)
- x = left + max_width;
- if (x > right - max_width)
- x = right - max_width;
-
- for (i = 0; i < line_count; i++) {
- drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y);
- y += getStringHeight(substrings[i]);
+ drawSubstring(line, buffer, dst_width, x - getStringWidth(line) / 2, y);
+ y += getStringHeight(line);
}
-
- free(s);
}
void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
diff --git a/scumm/smush/smush_font.h b/scumm/smush/smush_font.h
index ae5932693a..3b0925361a 100644
--- a/scumm/smush/smush_font.h
+++ b/scumm/smush/smush_font.h
@@ -44,7 +44,7 @@ public:
void setColor(byte c) { _color = c; }
void drawStringAbsolute (const char *str, byte *buffer, int dst_width, int x, int y);
- void drawStringCentered (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
+ void drawStringCentered (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y);
void drawStringWrap (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
void drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
};
diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp
index 5cac54780e..37d8c4ea46 100644
--- a/scumm/smush/smush_player.cpp
+++ b/scumm/smush/smush_player.cpp
@@ -561,13 +561,25 @@ void SmushPlayer::handleTextResource(Chunk &b) {
sf->drawStringAbsolute(str, _data, _width, pos_x, pos_y);
break;
case 1:
- sf->drawStringCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, right);
+ sf->drawStringCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top));
break;
case 8:
+ // FIXME: Is 'right' the maximum line width here, just
+ // as it is in the next case? It's used several times
+ // in The Dig's intro, where 'left' and 'right' are
+ // always 0 and 321 respectively. Someone will have to
+ // compare it to the original to see if we draw them
+ // correctly.
sf->drawStringWrap(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, right);
break;
case 9:
- sf->drawStringWrapCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, right);
+ // In this case, the 'right' parameter is actually the
+ // maximum line width. This explains why it's sometimes
+ // smaller than 'left'.
+ //
+ // Note that in The Dig's "Spacetime Six" movie it's
+ // 621. I have no idea what that means.
+ sf->drawStringWrapCentered(str, _data, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width));
break;
default:
warning("SmushPlayer::handleTextResource. Not handled flags: %d", flags);