From b9326e3850c96539243763d7b5b67f9d94a4a397 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 20 Dec 2015 01:21:06 +0100 Subject: LAB: Refactor some DispMan functions to use Common::String --- engines/lab/dispman.cpp | 58 ++++++++++++++++++++------------------------- engines/lab/dispman.h | 10 ++++---- engines/lab/intro.cpp | 2 +- engines/lab/processroom.cpp | 13 ++++++---- 4 files changed, 40 insertions(+), 43 deletions(-) (limited to 'engines') diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp index 49ea40a4e9..42021e32f1 100644 --- a/engines/lab/dispman.cpp +++ b/engines/lab/dispman.cpp @@ -122,16 +122,12 @@ void DisplayMan::freePict() { /** * Extracts the first word from a string. */ -Common::String DisplayMan::getWord(const char *mainBuffer, uint16 *wordWidth) { - uint16 width = 0; +Common::String DisplayMan::getWord(const char *mainBuffer) { Common::String result; - while ((mainBuffer[width] != ' ') && mainBuffer[width] && (mainBuffer[width] != '\n')) { - result += mainBuffer[width]; - width++; - } + for (int i = 0; mainBuffer[i] && (mainBuffer[i] != ' ') && (mainBuffer[i] != '\n'); i++) + result += mainBuffer[i]; - *wordWidth = width; return result; } @@ -140,20 +136,18 @@ Common::String DisplayMan::getWord(const char *mainBuffer, uint16 *wordWidth) { * or equal to the maximum width. */ Common::String DisplayMan::getLine(TextFont *tf, const char **mainBuffer, uint16 lineWidth) { - uint16 curWidth = 0, wordWidth; - char wordBuffer[100]; + uint16 curWidth = 0; Common::String result; bool doit = true; - lineWidth += textLength(tf, " ", 1); + lineWidth += textLength(tf, " "); while ((*mainBuffer)[0] && doit) { - Common::String wordBuffer = getWord(*mainBuffer, &wordWidth); - wordBuffer += " "; + Common::String wordBuffer = getWord(*mainBuffer) + " "; - if ((curWidth + textLength(tf, wordBuffer.c_str(), wordWidth + 1)) <= lineWidth) { + if ((curWidth + textLength(tf, wordBuffer)) <= lineWidth) { result += wordBuffer; - (*mainBuffer) += wordWidth; + (*mainBuffer) += wordBuffer.size() - 1; if ((*mainBuffer)[0] == '\n') doit = false; @@ -161,7 +155,7 @@ Common::String DisplayMan::getLine(TextFont *tf, const char **mainBuffer, uint16 if ((*mainBuffer)[0]) (*mainBuffer)++; - curWidth = textLength(tf, result.c_str(), result.size()); + curWidth = textLength(tf, result); } else doit = false; } @@ -225,10 +219,10 @@ int DisplayMan::flowText( len += lineBuffer.size(); if (centerh) - x += (width - textLength(msgFont, lineBuffer.c_str(), lineBuffer.size())) / 2; + x += (width - textLength(msgFont, lineBuffer)) / 2; if (output) - drawText(msgFont, x, y, penColor, lineBuffer.c_str(), lineBuffer.size()); + drawText(msgFont, x, y, penColor, lineBuffer); numLines--; y += fontHeight; @@ -282,8 +276,8 @@ void DisplayMan::createBox(uint16 y2) { drawVLine(_vm->_utils->vgaScaleX(2), _vm->_utils->vgaScaleY(152), _vm->_utils->vgaScaleY(y2)); } -int DisplayMan::longDrawMessage(const char *str) { - if (!str) +int DisplayMan::longDrawMessage(Common::String str) { + if (!str.size()) return 0; _vm->_event->attachButtonList(nullptr); @@ -299,20 +293,20 @@ int DisplayMan::longDrawMessage(const char *str) { createBox(198); _vm->_event->mouseShow(); - return flowText(_vm->_msgFont, 0, 1, 7, false, true, true, true, _vm->_utils->vgaRectScale(6, 155, 313, 195), str); + return flowText(_vm->_msgFont, 0, 1, 7, false, true, true, true, _vm->_utils->vgaRectScale(6, 155, 313, 195), str.c_str()); } /** * Draws a message to the message box. */ -void DisplayMan::drawMessage(const char *str) { +void DisplayMan::drawMessage(Common::String str) { if (_doNotDrawMessage) { _doNotDrawMessage = false; return; } - if (str) { - if ((textLength(_vm->_msgFont, str, strlen(str)) > _vm->_utils->vgaScaleX(306))) { + if (str.size()) { + if ((textLength(_vm->_msgFont, str) > _vm->_utils->vgaScaleX(306))) { longDrawMessage(str); _lastMessageLong = true; } else { @@ -323,7 +317,7 @@ void DisplayMan::drawMessage(const char *str) { _vm->_event->mouseHide(); createBox(168); - drawText(_vm->_msgFont, _vm->_utils->vgaScaleX(7), _vm->_utils->vgaScaleY(155) + _vm->_utils->svgaCord(2), 1, str, strlen(str)); + drawText(_vm->_msgFont, _vm->_utils->vgaScaleX(7), _vm->_utils->vgaScaleY(155) + _vm->_utils->svgaCord(2), 1, str); _vm->_event->mouseShow(); _lastMessageLong = false; } @@ -644,13 +638,13 @@ void DisplayMan::closeFont(TextFont **font) { /** * Returns the length of a text in the specified font. */ -uint16 DisplayMan::textLength(TextFont *font, const char *text, uint16 numChars) { +uint16 DisplayMan::textLength(TextFont *font, Common::String text) { uint16 length = 0; if (font) { + int numChars = text.size(); for (uint16 i = 0; i < numChars; i++) { - length += font->_widths[(uint)*text]; - text++; + length += font->_widths[text[i]]; } } @@ -667,8 +661,9 @@ uint16 DisplayMan::textHeight(TextFont *tf) { /** * Draws the text to the screen. */ -void DisplayMan::drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numChars) { +void DisplayMan::drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, Common::String text) { byte *vgaTop = getCurrentDrawingBuffer(); + int numChars = text.size(); for (uint16 i = 0; i < numChars; i++) { uint32 realOffset = (_screenWidth * y) + x; @@ -677,8 +672,8 @@ void DisplayMan::drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const int32 leftInSegment = _screenBytesPerPage - segmentOffset; byte *vgaCur = vgaTop + segmentOffset; - if (tf->_widths[(uint)*text]) { - byte *cdata = tf->_data + tf->_offsets[(uint)*text]; + if (tf->_widths[text[i]]) { + byte *cdata = tf->_data + tf->_offsets[text[i]]; uint16 bwidth = *cdata++; byte *vgaTemp = vgaCur; byte *vgaTempLine = vgaCur; @@ -739,8 +734,7 @@ void DisplayMan::drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const } } - x += tf->_widths[(int)*text]; - text++; + x += tf->_widths[text[i]]; } } diff --git a/engines/lab/dispman.h b/engines/lab/dispman.h index 518a4f745b..e2b935927d 100644 --- a/engines/lab/dispman.h +++ b/engines/lab/dispman.h @@ -62,7 +62,7 @@ private: uint16 fadeNumIn(uint16 num, uint16 res, uint16 counter); uint16 fadeNumOut(uint16 num, uint16 res, uint16 counter); - Common::String getWord(const char *mainBuffer, uint16 *wordWidth); + Common::String getWord(const char *mainBuffer); byte _curPen; Common::File *_curBitmap; @@ -88,8 +88,8 @@ public: void createBox(uint16 y2); void drawPanel(); void setUpScreens(); - int32 longDrawMessage(const char *str); - void drawMessage(const char *str); + int32 longDrawMessage(Common::String str); + void drawMessage(Common::String str); void setPen(byte pennum); void rectFill(uint16 x1, uint16 y1, uint16 x2, uint16 y2); void rectFill(Common::Rect fillRect); @@ -131,9 +131,9 @@ public: void scrollDisplayY(int16 dy, uint16 x1, uint16 y1, uint16 x2, uint16 y2, byte *buffer); void fade(bool fadein, uint16 res); void closeFont(TextFont **font); - uint16 textLength(TextFont *font, const char *text, uint16 numChars); + uint16 textLength(TextFont *font, Common::String text); uint16 textHeight(TextFont *tf); - void drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numChars); + void drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, Common::String text); Common::String getLine(TextFont *tf, const char **mainBuffer, uint16 lineWidth); bool _longWinInFront; diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp index be52e2979d..db881611d3 100644 --- a/engines/lab/intro.cpp +++ b/engines/lab/intro.cpp @@ -105,7 +105,7 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) { charDrawn = _vm->_graphics->flowText(msgFont, (!_vm->_isHiRes) * -1, 5, 7, false, false, true, true, _vm->_utils->vgaRectScale(14, 11, 306, 189), (char *)curText); _vm->_graphics->fade(true, 0); } else - charDrawn = _vm->_graphics->longDrawMessage((char *)curText); + charDrawn = _vm->_graphics->longDrawMessage(Common::String((char *)curText)); curText += charDrawn; doneFl = (*curText == 0); diff --git a/engines/lab/processroom.cpp b/engines/lab/processroom.cpp index c7c3092067..edb3a3b6a4 100644 --- a/engines/lab/processroom.cpp +++ b/engines/lab/processroom.cpp @@ -337,21 +337,24 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) { _conditions->exclElement(actionList->_param1); break; - case SHOWMESSAGE: + case SHOWMESSAGE: { _graphics->_doNotDrawMessage = false; + Common::String text = Common::String((char *)actionList->_data); if (_graphics->_longWinInFront) - _graphics->longDrawMessage((char *)actionList->_data); + _graphics->longDrawMessage(text); else - _graphics->drawMessage((char *)actionList->_data); + _graphics->drawMessage(text); _graphics->_doNotDrawMessage = true; + } break; case CSHOWMESSAGE: if (!*closePtrList) { + Common::String text = Common::String((char *)actionList->_data); _graphics->_doNotDrawMessage = false; - _graphics->drawMessage((char *)actionList->_data); + _graphics->drawMessage(text); _graphics->_doNotDrawMessage = true; } @@ -360,7 +363,7 @@ void LabEngine::doActions(Action *actionList, CloseDataPtr *closePtrList) { case SHOWMESSAGES: { char **str = (char **)actionList->_data; _graphics->_doNotDrawMessage = false; - _graphics->drawMessage(str[_utils->getRandom(actionList->_param1)]); + _graphics->drawMessage(Common::String(str[_utils->getRandom(actionList->_param1)])); _graphics->_doNotDrawMessage = true; } break; -- cgit v1.2.3