aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Montoir2004-01-10 21:56:47 +0000
committerGregory Montoir2004-01-10 21:56:47 +0000
commit5616955701657cd71462ae880bd25e1b4f3e31c1 (patch)
tree2fdb233bf9cad242bbf3c8cc86182dbed2c3d9df
parent1db3b65825a1d6efa333edb59cdc7c54d0f9b953 (diff)
downloadscummvm-rg350-5616955701657cd71462ae880bd25e1b4f3e31c1.tar.gz
scummvm-rg350-5616955701657cd71462ae880bd25e1b4f3e31c1.tar.bz2
scummvm-rg350-5616955701657cd71462ae880bd25e1b4f3e31c1.zip
new Talk::splitOption() code (same value for text margins, word width is computed without the ending space char)
svn-id: r12310
-rw-r--r--queen/talk.cpp35
-rw-r--r--queen/talk.h3
2 files changed, 23 insertions, 15 deletions
diff --git a/queen/talk.cpp b/queen/talk.cpp
index 393899688a..0bb9c56a47 100644
--- a/queen/talk.cpp
+++ b/queen/talk.cpp
@@ -1230,6 +1230,7 @@ TalkSelected *Talk::talkSelected() {
}
int Talk::splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]) {
+ debug(6, "Talk::splitOption(%s)", str);
// Check to see if option fits on one line, and exit early
if (_vm->resource()->getLanguage() == ENGLISH ||
_vm->display()->textWidth(str) <= MAX_TEXT_WIDTH) {
@@ -1239,6 +1240,7 @@ int Talk::splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]) {
// Split up multiple line option at closest space character
memset(optionText, 0, 5 * MAX_STRING_SIZE);
+ uint16 spaceCharWidth = _vm->display()->textWidth(" ");
uint16 width = 0;
uint16 optionLines = 0;
uint16 maxTextLen = MAX_TEXT_WIDTH;
@@ -1246,25 +1248,30 @@ int Talk::splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]) {
while (p) {
p = strchr(str, ' ');
if (p) {
- uint16 len = p - str + 1;
- width += _vm->display()->textWidth(str, len);
- if (width > maxTextLen) {
- strncat(optionText[optionLines], str, len - 1);
+ uint16 len = p - str;
+ uint16 wordWidth = _vm->display()->textWidth(str, len);
+ width += wordWidth;
+ if (width> maxTextLen) {
++optionLines;
- width = 0;
- maxTextLen = MAX_TEXT_WIDTH - 16; // compensate left margin
+ strncpy(optionText[optionLines], str, len + 1);
+ width = wordWidth;
+ maxTextLen = MAX_TEXT_WIDTH - OPTION_TEXT_MARGIN;
} else {
- strncat(optionText[optionLines], str, len);
+ strncat(optionText[optionLines], str, len + 1);
}
+ width += spaceCharWidth;
str = p + 1;
+ } else {
+ if (str[0]) {
+ if (width + _vm->display()->textWidth(str) > maxTextLen) {
+ ++optionLines;
+ }
+ strcat(optionText[optionLines], str);
+ }
+ ++optionLines;
}
}
- width += _vm->display()->textWidth(str);
- if (width > maxTextLen) {
- ++optionLines;
- }
- strcat(optionText[optionLines], str);
- return optionLines + 1;
+ return optionLines;
}
static char *removeStar(char *str) {
@@ -1356,7 +1363,7 @@ int16 Talk::selectSentence() {
if (yOffset < 5) {
//debug(6, "Draw text '%s'", optionText[j]);
_vm->display()->setText(
- (j == 0) ? 0 : 24,
+ (j == 0) ? 0 : OPTION_TEXT_MARGIN,
150 - PUSHUP + yOffset * LINE_HEIGHT,
optionText[j]);
}
diff --git a/queen/talk.h b/queen/talk.h
index 1036e99bc1..beaaa05cbc 100644
--- a/queen/talk.h
+++ b/queen/talk.h
@@ -61,7 +61,8 @@ private:
ARROW_BOB_DOWN = 63,
ARROW_ZONE_UP = 5,
ARROW_ZONE_DOWN = 6,
- DOG_HEADER_SIZE = 20
+ DOG_HEADER_SIZE = 20,
+ OPTION_TEXT_MARGIN = 24
};
//! Special commands for speech