diff options
author | Max Horn | 2004-04-16 20:49:14 +0000 |
---|---|---|
committer | Max Horn | 2004-04-16 20:49:14 +0000 |
commit | bcb7878f10d9ca2f48dfb6ed4074415181c8af81 (patch) | |
tree | 8b582647a43bdf95a2bec39509d059aac0e8d816 /scumm | |
parent | 5af7979f0bf497fc1c93fdb581a5b90c2eb5857f (diff) | |
download | scummvm-rg350-bcb7878f10d9ca2f48dfb6ed4074415181c8af81.tar.gz scummvm-rg350-bcb7878f10d9ca2f48dfb6ed4074415181c8af81.tar.bz2 scummvm-rg350-bcb7878f10d9ca2f48dfb6ed4074415181c8af81.zip |
Unify some code
svn-id: r13589
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/insane/insane.cpp | 6 | ||||
-rw-r--r-- | scumm/smush/smush_font.cpp | 128 | ||||
-rw-r--r-- | scumm/smush/smush_font.h | 6 | ||||
-rw-r--r-- | scumm/smush/smush_player.cpp | 8 |
4 files changed, 51 insertions, 97 deletions
diff --git a/scumm/insane/insane.cpp b/scumm/insane/insane.cpp index 7914433f11..48ff0b2964 100644 --- a/scumm/insane/insane.cpp +++ b/scumm/insane/insane.cpp @@ -1276,13 +1276,13 @@ void Insane::smlayer_showStatusMsg(int32 arg_0, byte *renderBitmap, int32 codecp // bit 3 - wrap around 8 switch (flags) { case 0: - sf->drawStringAbsolute(str, renderBitmap, _player->_width, pos_x, pos_y); + sf->drawString(str, renderBitmap, _player->_width, _player->_height, pos_x, pos_y, false); break; case 1: - sf->drawStringCentered(str, renderBitmap, _player->_width, _player->_height, pos_x, MAX(pos_y, top)); + sf->drawString(str, renderBitmap, _player->_width, _player->_height, pos_x, MAX(pos_y, top), true); break; case 5: - sf->drawStringWrapCentered(str, renderBitmap, _player->_width, _player->_height, pos_x, pos_y, 10, 300); + sf->drawStringWrap(str, renderBitmap, _player->_width, _player->_height, pos_x, pos_y, 10, 300, true); break; default: warning("Insane::smlayer_showStatusMsg. Not handled flags: %d", flags); diff --git a/scumm/smush/smush_font.cpp b/scumm/smush/smush_font.cpp index f810a7895d..6945f37c5e 100644 --- a/scumm/smush/smush_font.cpp +++ b/scumm/smush/smush_font.cpp @@ -157,8 +157,8 @@ void SmushFont::drawSubstring(const char *str, byte *buffer, int dst_width, int #define MAX_WORDS 60 -void SmushFont::drawStringAbsolute(const char *str, byte *buffer, int dst_width, int x, int y) { - debug(9, "SmushFont::drawStringAbsolute(%s, %d, %d)", str, x, y); +void SmushFont::drawString(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center) { + debug(0, "SmushFont::drawString(%s, %d, %d, %d)", str, x, y, center); while (str) { char line[256]; @@ -171,32 +171,13 @@ void SmushFont::drawStringAbsolute(const char *str, byte *buffer, int dst_width, strcpy(line, str); str = 0; } - drawSubstring(line, buffer, dst_width, x, y); + drawSubstring(line, buffer, dst_width, center ? (x - getStringWidth(line) / 2) : x, y); y += getStringHeight(line); } } -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); - - 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; - } - drawSubstring(line, buffer, dst_width, x - getStringWidth(line) / 2, y); - y += getStringHeight(line); - } -} - -void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) { - debug(9, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d)", str, x, y, left, right); +void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center) { + debug(0, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d, %d)", str, x, y, left, right, center); const int width = right - left; char *s = strdup(str); @@ -243,81 +224,56 @@ void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int if (y > dst_height - height) { y = dst_height - height; } - - if (x > dst_width - max_width) - x = dst_width - max_width; - - for (i = 0; i < line_count; i++) { - drawSubstring(substrings[i], buffer, dst_width, x, y); - y += getStringHeight(substrings[i]); + + if (center) { + max_width = (max_width + 1) / 2; + 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]); + } + } else { + if (x > dst_width - max_width) + x = dst_width - max_width; + + for (i = 0; i < line_count; i++) { + drawSubstring(substrings[i], buffer, dst_width, x, y); + y += getStringHeight(substrings[i]); + } } free(s); } -void SmushFont::drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) { - debug(9, "SmushFont::drawStringWrapCentered(%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; +} // End of namespace Scumm + + + + + + + + + + + + + + - 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; - 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++; - } - 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) / 2; - 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]); - } - - free(s); -} -} // End of namespace Scumm diff --git a/scumm/smush/smush_font.h b/scumm/smush/smush_font.h index 940880d6a9..b197dad9c6 100644 --- a/scumm/smush/smush_font.h +++ b/scumm/smush/smush_font.h @@ -45,10 +45,8 @@ public: SmushFont(bool use_original_colors, bool new_colors); 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); - 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); + void drawString (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center); + void drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center); }; } // End of namespace Scumm diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp index ad8042ecf6..67c6fa4dc7 100644 --- a/scumm/smush/smush_player.cpp +++ b/scumm/smush/smush_player.cpp @@ -569,10 +569,10 @@ void SmushPlayer::handleTextResource(Chunk &b) { // bit 3 - wrap around 8 switch (flags & 9) { case 0: - sf->drawStringAbsolute(str, _dst, _width, pos_x, pos_y); + sf->drawString(str, _dst, _width, _height, pos_x, pos_y, false); break; case 1: - sf->drawStringCentered(str, _dst, _width, _height, pos_x, MAX(pos_y, top)); + sf->drawString(str, _dst, _width, _height, pos_x, MAX(pos_y, top), true); break; case 8: // FIXME: Is 'right' the maximum line width here, just @@ -580,7 +580,7 @@ void SmushPlayer::handleTextResource(Chunk &b) { // in The Dig's intro, where 'left' and 'right' are // always 0 and 321 respectively, and apparently we // handle that correctly. - sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right); + sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right, false); break; case 9: // In this case, the 'right' parameter is actually the @@ -589,7 +589,7 @@ void SmushPlayer::handleTextResource(Chunk &b) { // // Note that in The Dig's "Spacetime Six" movie it's // 621. I have no idea what that means. - sf->drawStringWrapCentered(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width)); + sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width), true); break; default: warning("SmushPlayer::handleTextResource. Not handled flags: %d", flags); |