diff options
author | David Eriksson | 2003-10-18 12:18:43 +0000 |
---|---|---|
committer | David Eriksson | 2003-10-18 12:18:43 +0000 |
commit | 935a476a29a8f045e54e1556e1c25ff76d9b942b (patch) | |
tree | d3805951fac43d5c958353be52a54eb84d9d38f3 /queen | |
parent | de37ee0c3e064b61b26207b9da3175a477399013 (diff) | |
download | scummvm-rg350-935a476a29a8f045e54e1556e1c25ff76d9b942b.tar.gz scummvm-rg350-935a476a29a8f045e54e1556e1c25ff76d9b942b.tar.bz2 scummvm-rg350-935a476a29a8f045e54e1556e1c25ff76d9b942b.zip |
Moved function from Talk to Graphics because Cutaway need it too.
svn-id: r10891
Diffstat (limited to 'queen')
-rw-r--r-- | queen/graphics.cpp | 114 | ||||
-rw-r--r-- | queen/graphics.h | 10 | ||||
-rw-r--r-- | queen/talk.cpp | 120 | ||||
-rw-r--r-- | queen/talk.h | 6 | ||||
-rw-r--r-- | queen/xref.txt | 2 |
5 files changed, 126 insertions, 126 deletions
diff --git a/queen/graphics.cpp b/queen/graphics.cpp index 9c844e611a..fb9d8d0288 100644 --- a/queen/graphics.cpp +++ b/queen/graphics.cpp @@ -794,6 +794,120 @@ void Graphics::update() { _display->update(_bobs[0].active, _bobs[0].x, _bobs[0].y); } +void Graphics::bobSetText( + BobSlot *pbs, + const char *text, + int textX, int textY, + int color, int flags) { + // function MAKE_SPEAK_BOB, lines 335-457 in talk.c + if (text[0] == '\0') + return; + + // debug(0, "makeSpeakBob('%s', (%i,%i), %i, %i, %i, %i);", + // text, bob->x, bob->y, textX, textY, color, flags); + + // Duplicate string and append zero if needed + + char textCopy[MAX_STRING_SIZE]; + + int length = strlen(text); + memcpy(textCopy, text, length); + + if (textCopy[length - 1] >= 'A') + textCopy[length++] = '.'; + + textCopy[length] = '\0'; + + // Split text into lines + + char lines[8][MAX_STRING_SIZE]; + int lineCount = 0; + int wordCount = 0; + int lineLength = 0; + int i; + + for (i = 0; i < length; i++) { + if (textCopy[i] == ' ') + wordCount++; + + lineLength++; + + if ((lineLength > 20 && textCopy[i] == ' ') || i == (length-1)) { + memcpy(lines[lineCount], textCopy + i + 1 - lineLength, lineLength); + lines[lineCount][lineLength] = '\0'; + lineCount++; + lineLength = 0; + } + } + + + // Plan: write each line to Screen 2, put black outline around lines and + // pick them up as a BOB. + + + // Find width of widest line + + int maxLineWidth = 0; + + for (i = 0; i < lineCount; i++) { + int width = textWidth(lines[i]); + if (maxLineWidth < width) + maxLineWidth = width; + } + + // Calc text position + + short x, y, width, height; + + if (flags) { + if (flags == 2) + x = 160 - maxLineWidth / 2; + else + x = textX; + + y = textY; + + width = 0; + } + else { + x = pbs->x; + y = pbs->y; + + BobFrame *pbf = frame(pbs->frameNum); + + width = (pbf->width * pbs->scale) / 100; + height = (pbf->height * pbs->scale) / 100; + + y = y - height - 16 - lineCount * 9; + } + + // XXX x -= scrollx; + + if (y < 0) { + y = 0; + + if (x < 160) + x += width / 2; + else + x -= width / 2 + maxLineWidth; + } + else if (!flags) + x -= maxLineWidth / 2; + + if (x < 0) + x = 4; + else if ((x + maxLineWidth) > 320) + x = 320 - maxLineWidth - 4; + + textCurrentColor(color); + + for (i = 0; i < lineCount; i++) { + int lineX = x + (maxLineWidth - textWidth(lines[i])) / 2; + + //debug(0, "Setting text '%s' at (%i, %i)", lines[i], lineX, y + 9 * i); + textSet(lineX, y + 9 * i, lines[i]); + } +} } // End of namespace Queen diff --git a/queen/graphics.h b/queen/graphics.h index f6580096ea..6fe656e3cc 100644 --- a/queen/graphics.h +++ b/queen/graphics.h @@ -137,6 +137,12 @@ public: BobSlot *bob(int index); void bobCustomParallax(uint16 roomNum); + void bobSetText( + BobSlot *bob, + const char *text, + int textX, int textY, + int color, int flags); // MAKE_SPEAK_BOB + void textCurrentColor(uint8 color); // ink() void textSet(uint16 x, uint16 y, const char *text, bool outlined = true); // text() void textSetCentered(uint16 y, const char *text, bool outlined = true); @@ -163,9 +169,11 @@ public: private: enum { + MAX_STRING_LENGTH = 255, + MAX_STRING_SIZE = (MAX_STRING_LENGTH + 1), BOB_SHRINK_BUF_SIZE = 60000 }; - + struct PackedBank { uint32 indexes[MAX_BANK_SIZE]; uint8 *data; diff --git a/queen/talk.cpp b/queen/talk.cpp index eaa36338b0..dfc0103403 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -704,7 +704,7 @@ void Talk::speakSegment( int startFrame = 0; if (_talkHead && isJoe) { - makeSpeakBob(segment, bob, textX, textY, color, (_talkHead == 1)); + _graphics->bobSetText(bob, segment, textX, textY, color, (_talkHead == 1)); } else { if (SPEAK_UNKNOWN_6 == command) @@ -758,7 +758,7 @@ void Talk::speakSegment( warning("Talking heads not yet handled"); } - makeSpeakBob(segment, bob, textX, textY, color, (_talkHead == 1)); + _graphics->bobSetText(bob, segment, textX, textY, color, (_talkHead == 1)); if (parameters->animation[0] != '\0') { // talk.c lines 1639-1690 @@ -1177,122 +1177,6 @@ int16 Talk::selectSentence() { return selectedSentence; } -void Talk::makeSpeakBob( - const char *text, - BobSlot *bob, - int textX, int textY, - int color, int flags) { - // function MAKE_SPEAK_BOB, lines 335-457 in talk.c - - if (text[0] == '\0') - return; - - // debug(0, "makeSpeakBob('%s', (%i,%i), %i, %i, %i, %i);", - // text, bob->x, bob->y, textX, textY, color, flags); - - // Duplicate string and append zero if needed - - char textCopy[MAX_STRING_SIZE]; - - int length = strlen(text); - memcpy(textCopy, text, length); - - if (textCopy[length - 1] >= 'A') - textCopy[length++] = '.'; - - textCopy[length] = '\0'; - - // Split text into lines - - char lines[8][MAX_STRING_SIZE]; - int line_count = 0; - int word_count = 0; - int line_length = 0; - int i; - - for (i = 0; i < length; i++) { - if (textCopy[i] == ' ') - word_count++; - - line_length++; - - if ((line_length > 20 && textCopy[i] == ' ') || i == (length-1)) { - memcpy(lines[line_count], textCopy + i + 1 - line_length, line_length); - lines[line_count][line_length] = '\0'; - line_count++; - line_length = 0; - } - } - - - // Plan: write each line to Screen 2, put black outline around lines and - // pick them up as a BOB. - - - // Find width of widest line - - int max_line_width = 0; - - for (i = 0; i < line_count; i++) { - int width = _graphics->textWidth(lines[i]); - if (max_line_width < width) - max_line_width = width; - } - - // Calc text position - - short x, y, width, height; - - if (flags) { - if (flags == 2) - x = 160 - max_line_width / 2; - else - x = textX; - - y = textY; - - width = 0; - } - else { - x = bob->x; - y = bob->y; - - BobFrame *frame = _graphics->frame(bob->frameNum); - - width = (frame->width * bob->scale) / 100; - height = (frame->height * bob->scale) / 100; - - y = y - height - 16 - line_count * 9; - } - - // XXX x -= scrollx; - - if (y < 0) { - y = 0; - - if (x < 160) - x += width / 2; - else - x -= width / 2 + max_line_width; - } - else if (!flags) - x -= max_line_width / 2; - - if (x < 0) - x = 4; - else if ((x + max_line_width) > 320) - x = 320 - max_line_width - 4; - - _graphics->textCurrentColor(color); - - for (i = 0; i < line_count; i++) { - int lineX = x + (max_line_width - _graphics->textWidth(lines[i])) / 2; - - //debug(0, "Setting text '%s' at (%i, %i)", lines[i], lineX, y + 9 * i); - _graphics->textSet(lineX, y + 9 * i, lines[i]); - } -} - const Talk::SpeechParameters Talk::_speechParameters[] = { { "JOE",0,1,1,10,2,3,"",0}, { "JOE",0,3,3,28,2,3,"",0}, diff --git a/queen/talk.h b/queen/talk.h index 1be454584e..26b6226112 100644 --- a/queen/talk.h +++ b/queen/talk.h @@ -202,12 +202,6 @@ class Talk { int state, int faceDirection); // FIND_SACTION - void makeSpeakBob( - const char *text, - BobSlot *bob, - int textX, int textY, - int color, int flags); // MAKE_SPEAK_BOB - static int splitOption(const char *str, char optionText[5][MAX_STRING_SIZE]); diff --git a/queen/xref.txt b/queen/xref.txt index c2d961a591..3f205d03cf 100644 --- a/queen/xref.txt +++ b/queen/xref.txt @@ -85,6 +85,7 @@ invbob() Graphics::bobDrawInventoryItem loadbackdrop() Graphics::loadBackdrop loadfont() *not needed* loadpanel() Graphics::loadPanel +MAKE_SPEAK_BOB Graphics::bobSetText makeanim() Graphics::bobAnimNormal movebob() Graphics::bobMove pastebob() Graphics::bobPaste @@ -295,7 +296,6 @@ FIND_STATE() Logic::findState* TALK ==== FIND_SACTION() Talk::findSpeechParameters -MAKE_SPEAK_BOB Talk::makeSpeakBob MOVE_SPEAK SPEAK Talk::speak SPEAK_SUB Talk::speakSegment |