aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStrangerke2015-12-14 21:44:06 +0100
committerWillem Jan Palenstijn2015-12-23 21:34:05 +0100
commite0de03463e0c8145bd7700cd2f4955dfc0676967 (patch)
treef54f2d07c62dd19e28d7cbe6a98e241d4953e914
parent52d0243eff241d59397fe6237c1959e24d51dbb8 (diff)
downloadscummvm-rg350-e0de03463e0c8145bd7700cd2f4955dfc0676967.tar.gz
scummvm-rg350-e0de03463e0c8145bd7700cd2f4955dfc0676967.tar.bz2
scummvm-rg350-e0de03463e0c8145bd7700cd2f4955dfc0676967.zip
LAB: Use strlen to compute text length instead of a difference between start and end address. Some refactoring.
-rw-r--r--engines/lab/dispman.cpp37
-rw-r--r--engines/lab/dispman.h6
-rw-r--r--engines/lab/intro.cpp42
-rw-r--r--engines/lab/special.cpp43
4 files changed, 63 insertions, 65 deletions
diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp
index 9a3d6869c6..cef02eab29 100644
--- a/engines/lab/dispman.cpp
+++ b/engines/lab/dispman.cpp
@@ -178,10 +178,10 @@ void DisplayMan::getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer
* Note: Every individual word MUST be int16 enough to fit on a line, and
* each line less than 255 characters.
*/
-uint32 DisplayMan::flowText(
+int DisplayMan::flowText(
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
- byte pencolor, // pen number to use for text
+ byte penColor, // pen number to use for text
byte backpen, // the background color
bool fillback, // Whether to fill the background
bool centerh, // Whether to center the text horizontally
@@ -195,17 +195,17 @@ uint32 DisplayMan::flowText(
rectFill(x1, y1, x2, y2);
}
- if (str == NULL)
- return 0L;
+ if (!str)
+ return 0;
- setAPen(pencolor);
+ setAPen(penColor);
TextFont *msgFont = font;
uint16 fontheight = textHeight(msgFont) + spacing;
uint16 numlines = (y2 - y1 + 1) / fontheight;
uint16 width = x2 - x1 + 1;
uint16 y = y1;
- char linebuffer[256];
+ char lineBuffer[256];
const char *temp;
if (centerv && output) {
@@ -213,7 +213,7 @@ uint32 DisplayMan::flowText(
uint16 actlines = 0;
while (temp[0]) {
- getLine(msgFont, linebuffer, &temp, width);
+ getLine(msgFont, lineBuffer, &temp, width);
actlines++;
}
@@ -222,26 +222,29 @@ uint32 DisplayMan::flowText(
}
temp = str;
-
+ int len = 0;
while (numlines && str[0]) {
- getLine(msgFont, linebuffer, &str, width);
+ getLine(msgFont, lineBuffer, &str, width);
uint16 x = x1;
+ len += strlen(lineBuffer);
if (centerh)
- x += (width - textLength(msgFont, linebuffer, strlen(linebuffer))) / 2;
+ x += (width - textLength(msgFont, lineBuffer, strlen(lineBuffer))) / 2;
if (output)
- text(msgFont, x, y, pencolor, linebuffer, strlen(linebuffer));
+ text(msgFont, x, y, penColor, lineBuffer, strlen(lineBuffer));
numlines--;
y += fontheight;
}
- return (str - temp);
+ len--;
+
+ return len;
}
-uint32 DisplayMan::flowTextScaled(
+int DisplayMan::flowTextScaled(
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte penColor, // pen number to use for text
@@ -261,7 +264,7 @@ uint32 DisplayMan::flowTextScaled(
/**
* Calls flowText, but flows it to memory. Same restrictions as flowText.
*/
-uint32 DisplayMan::flowTextToMem(Image *destIm,
+int DisplayMan::flowTextToMem(Image *destIm,
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
@@ -279,7 +282,7 @@ uint32 DisplayMan::flowTextToMem(Image *destIm,
_currentDisplayBuffer = destIm->_imageData;
_screenBytesPerPage = (uint32)destIm->_width * (int32)destIm->_height;
- uint32 res = flowText(font, spacing, pencolor, backpen, fillback, centerh, centerv, output, x1, y1, x2, y2, str);
+ int res = flowText(font, spacing, pencolor, backpen, fillback, centerh, centerv, output, x1, y1, x2, y2, str);
_screenBytesPerPage = vgabyte;
_currentDisplayBuffer = tmp;
@@ -302,8 +305,8 @@ void DisplayMan::createBox(uint16 y2) {
drawVLine(_vm->_utils->vgaScaleX(2), _vm->_utils->vgaScaleY(152), _vm->_utils->vgaScaleY(y2));
}
-int32 DisplayMan::longDrawMessage(const char *str) {
- if (str == NULL)
+int DisplayMan::longDrawMessage(const char *str) {
+ if (!str)
return 0;
_vm->_event->attachButtonList(NULL);
diff --git a/engines/lab/dispman.h b/engines/lab/dispman.h
index 7ed2e67687..fe2aa517fd 100644
--- a/engines/lab/dispman.h
+++ b/engines/lab/dispman.h
@@ -94,7 +94,7 @@ public:
void rectFill(uint16 x1, uint16 y1, uint16 x2, uint16 y2);
void rectFillScaled(uint16 x1, uint16 y1, uint16 x2, uint16 y2);
// Window text stuff
- uint32 flowText(TextFont *font, // the TextAttr pointer
+ int flowText(TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
byte backpen, // the background color
@@ -106,7 +106,7 @@ public:
uint16 x2, uint16 y2,
const char *text); // The text itself
- uint32 flowTextScaled(
+ int flowTextScaled(
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
@@ -119,7 +119,7 @@ public:
uint16 x2, uint16 y2,
const char *text); // The text itself
- uint32 flowTextToMem(Image *destIm,
+ int flowTextToMem(Image *destIm,
TextFont *font, // the TextAttr pointer
int16 spacing, // How much vertical spacing between the lines
byte pencolor, // pen number to use for text
diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp
index 5c1c837da5..c739389425 100644
--- a/engines/lab/intro.cpp
+++ b/engines/lab/intro.cpp
@@ -80,11 +80,9 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
return;
uint32 lastMillis = 0;
- IntuiMessage *msg;
- bool drawNextText = true, end = false, begin = true;
-
- int32 cls, code, Drawn;
- int16 qualifier;
+ bool drawNextText = true;
+ bool doneFl = false;
+ bool begin = true;
Common::File *textFile = _vm->_resource->openDataFile(path);
byte *textBuffer = new byte[textFile->size()];
@@ -99,19 +97,18 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
else if (isScreen)
_vm->_graphics->fade(false, 0);
+ int charDrawn = 0;
if (isScreen) {
_vm->_graphics->setAPen(7);
_vm->_graphics->rectFillScaled(10, 10, 310, 190);
- Drawn = _vm->_graphics->flowTextScaled(msgFont, (!_vm->_isHiRes) * -1, 5, 7, false, false, true, true, 14, 11, 306, 189, (char *)curText);
+ charDrawn = _vm->_graphics->flowTextScaled(msgFont, (!_vm->_isHiRes) * -1, 5, 7, false, false, true, true, 14, 11, 306, 189, (char *)curText);
_vm->_graphics->fade(true, 0);
- } else {
- Drawn = _vm->_graphics->longDrawMessage((char *)curText);
- }
-
- curText += Drawn;
+ } else
+ charDrawn = _vm->_graphics->longDrawMessage((char *)curText);
- end = (*curText == 0);
+ curText += charDrawn;
+ doneFl = (*curText == 0);
drawNextText = false;
introEatMessages();
@@ -127,7 +124,7 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
lastMillis = g_system->getMillis();
}
- msg = _vm->_event->getMsg();
+ IntuiMessage *msg = _vm->_event->getMsg();
if (msg == NULL) {
_vm->_music->updateMusic();
@@ -136,7 +133,7 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
uint32 elapsedSeconds = (g_system->getMillis() - lastMillis) / 1000;
if (elapsedSeconds > timeDelay) {
- if (end) {
+ if (doneFl) {
if (isScreen)
_vm->_graphics->fade(false, 0);
@@ -146,15 +143,14 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
drawNextText = true;
}
}
-
_vm->waitTOF();
} else {
- cls = msg->_msgClass;
- qualifier = msg->_qualifier;
- code = msg->_code;
+ uint32 msgClass = msg->_msgClass;
+ uint16 qualifier = msg->_qualifier;
+ uint16 code = msg->_code;
- if (((cls == MOUSEBUTTONS) && (IEQUALIFIER_RIGHTBUTTON & qualifier)) ||
- ((cls == RAWKEY) && (code == 27))) {
+ if (((msgClass == MOUSEBUTTONS) && (IEQUALIFIER_RIGHTBUTTON & qualifier)) ||
+ ((msgClass == RAWKEY) && (code == 27))) {
_quitIntro = true;
if (isScreen)
@@ -162,9 +158,9 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
delete[] textBuffer;
return;
- } else if (cls == MOUSEBUTTONS) {
+ } else if (msgClass == MOUSEBUTTONS) {
if (IEQUALIFIER_LEFTBUTTON & qualifier) {
- if (end) {
+ if (doneFl) {
if (isScreen)
_vm->_graphics->fade(false, 0);
@@ -185,7 +181,7 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) {
}
}
- if (end) {
+ if (doneFl) {
if (isScreen)
_vm->_graphics->fade(false, 0);
diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp
index 6fc8636037..c2c52b2c4f 100644
--- a/engines/lab/special.cpp
+++ b/engines/lab/special.cpp
@@ -52,13 +52,12 @@ namespace Lab {
*/
void LabEngine::doNotes() {
TextFont *noteFont = _resource->getFont("P:Note.fon");
- char *ntext = _resource->getText("Lab:Rooms/Notes");
+ char *noteText = _resource->getText("Lab:Rooms/Notes");
- _graphics->flowText(noteFont, -2 + _utils->svgaCord(1), 0, 0, false, false, true, true, _utils->vgaScaleX(25) + _utils->svgaCord(15), _utils->vgaScaleY(50), _utils->vgaScaleX(295) - _utils->svgaCord(15), _utils->vgaScaleY(148), ntext);
+ _graphics->flowText(noteFont, -2 + _utils->svgaCord(1), 0, 0, false, false, true, true, _utils->vgaScaleX(25) + _utils->svgaCord(15), _utils->vgaScaleY(50), _utils->vgaScaleX(295) - _utils->svgaCord(15), _utils->vgaScaleY(148), noteText);
_graphics->setPalette(_anim->_diffPalette, 256);
-
_graphics->closeFont(noteFont);
- delete[] ntext;
+ delete[] noteText;
}
/**
@@ -67,35 +66,35 @@ void LabEngine::doNotes() {
*/
void LabEngine::doWestPaper() {
TextFont *paperFont = _resource->getFont("P:News22.fon");
- char *ntext = _resource->getText("Lab:Rooms/Date");
- _graphics->flowText(paperFont, 0, 0, 0, false, true, false, true, _utils->vgaScaleX(57), _utils->vgaScaleY(77) + _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(91), ntext);
+ char *paperText = _resource->getText("Lab:Rooms/Date");
+ _graphics->flowText(paperFont, 0, 0, 0, false, true, false, true, _utils->vgaScaleX(57), _utils->vgaScaleY(77) + _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(91), paperText);
_graphics->closeFont(paperFont);
- delete[] ntext;
+ delete[] paperText;
paperFont = _resource->getFont("P:News32.fon");
- ntext = _resource->getText("Lab:Rooms/Headline");
+ paperText = _resource->getText("Lab:Rooms/Headline");
- int fileLen = strlen(ntext) - 1;
- int charsPrinted = _graphics->flowText(paperFont, -8, 0, 0, false, true, false, true, _utils->vgaScaleX(57), _utils->vgaScaleY(86) - _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(118), ntext);
+ int fileLen = strlen(paperText) - 1;
+ int charsPrinted = _graphics->flowText(paperFont, -8, 0, 0, false, true, false, true, _utils->vgaScaleX(57), _utils->vgaScaleY(86) - _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(118), paperText);
uint16 y;
if (charsPrinted < fileLen) {
y = 130 - _utils->svgaCord(5);
- _graphics->flowText(paperFont, -8 - _utils->svgaCord(1), 0, 0, false, true, false, true, _utils->vgaScaleX(57), _utils->vgaScaleY(86) - _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(132), ntext);
+ _graphics->flowText(paperFont, -8 - _utils->svgaCord(1), 0, 0, false, true, false, true, _utils->vgaScaleX(57), _utils->vgaScaleY(86) - _utils->svgaCord(2), _utils->vgaScaleX(262), _utils->vgaScaleY(132), paperText);
} else
y = 115 - _utils->svgaCord(5);
_graphics->closeFont(paperFont);
- delete[] ntext;
+ delete[] paperText;
paperFont = _resource->getFont("P:Note.fon");
- ntext = _resource->getText("Lab:Rooms/Col1");
- charsPrinted = _graphics->flowTextScaled(paperFont, -4, 0, 0, false, false, false, true, 45, y, 158, 148, ntext);
- delete[] ntext;
- ntext = _resource->getText("Lab:Rooms/Col2");
- charsPrinted = _graphics->flowTextScaled(paperFont, -4, 0, 0, false, false, false, true, 162, y, 275, 148, ntext);
- delete[] ntext;
+ paperText = _resource->getText("Lab:Rooms/Col1");
+ charsPrinted = _graphics->flowTextScaled(paperFont, -4, 0, 0, false, false, false, true, 45, y, 158, 148, paperText);
+ delete[] paperText;
+ paperText = _resource->getText("Lab:Rooms/Col2");
+ charsPrinted = _graphics->flowTextScaled(paperFont, -4, 0, 0, false, false, false, true, 162, y, 275, 148, paperText);
+ delete[] paperText;
_graphics->closeFont(paperFont);
_graphics->setPalette(_anim->_diffPalette, 256);
@@ -162,7 +161,7 @@ void LabEngine::loadJournalData() {
*/
void LabEngine::drawJournalText() {
uint16 drawingToPage = 1;
- int32 charsDrawn = 0;
+ int charsDrawn = 0;
char *curText = _journalText;
while (drawingToPage < _journalPage) {
@@ -192,7 +191,7 @@ void LabEngine::drawJournalText() {
_graphics->flowTextToMem(_journalBackImage, _journalFont, -2, 2, 0, false, false, false, true, _utils->vgaScaleX(171), _utils->vgaScaleY(32), _utils->vgaScaleX(271), _utils->vgaScaleY(148), curText);
curText = (char *)(_journalText + charsDrawn);
- _lastPage = _lastPage || (*curText == 0);
+ _lastPage |= (*curText == 0);
}
/**
@@ -330,7 +329,7 @@ void LabEngine::doJournal() {
*/
void LabEngine::drawMonText(char *text, TextFont *monitorFont, uint16 x1, uint16 y1, uint16 x2, uint16 y2, bool isinteractive) {
uint16 drawingToPage = 0, yspacing = 0;
- int32 charsDrawn = 0L;
+ int charsDrawn = 0;
char *curText = text;
_event->mouseHide();
@@ -380,7 +379,7 @@ void LabEngine::drawMonText(char *text, TextFont *monitorFont, uint16 x1, uint16
_lastPage = (*curText == 0);
charsDrawn = _graphics->flowText(monitorFont, yspacing, 2, 0, false, false, false, true, x1, y1, x2, y2, curText);
curText += charsDrawn;
- _lastPage = _lastPage || (*curText == 0);
+ _lastPage |= (*curText == 0);
_event->mouseShow();
}