aboutsummaryrefslogtreecommitdiff
path: root/engines/dm/text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/dm/text.cpp')
-rw-r--r--engines/dm/text.cpp102
1 files changed, 45 insertions, 57 deletions
diff --git a/engines/dm/text.cpp b/engines/dm/text.cpp
index 52e83d1db2..00049bb878 100644
--- a/engines/dm/text.cpp
+++ b/engines/dm/text.cpp
@@ -31,11 +31,12 @@
namespace DM {
-TextMan::TextMan(DMEngine* vm) : _vm(vm) {
+TextMan::TextMan(DMEngine *vm) : _vm(vm) {
_messageAreaCursorColumn = 0;
_messageAreaCursorRow = 0;
for (uint16 i = 0; i < 4; ++i)
_messageAreaRowExpirationTime[i] = 0;
+
_bitmapMessageAreaNewRow = new byte[320 * 7];
_isScrolling = false;
_startedScrollingAt = -1;
@@ -47,11 +48,8 @@ TextMan::~TextMan() {
delete[] _messageAreaCopy;
}
-#define k5_LetterWidth 5
-#define k6_LetterHeight 6
-
-void TextMan::printTextToBitmap(byte* destBitmap, uint16 destByteWidth, int16 destX, int16 destY,
- Color textColor, Color bgColor, const char* text, uint16 destHeight) {
+void TextMan::printTextToBitmap(byte *destBitmap, uint16 destByteWidth, int16 destX, int16 destY,
+ Color textColor, Color bgColor, const char *text, uint16 destHeight) {
if ((destX -= 1) < 0) // fixes missalignment, to be checked
destX = 0;
if ((destY -= 4) < 0) // fixes missalignment, to be checked
@@ -65,9 +63,9 @@ void TextMan::printTextToBitmap(byte* destBitmap, uint16 destByteWidth, int16 de
byte *srcBitmap = _vm->_displayMan->getNativeBitmapOrGraphic(k557_FontGraphicIndice);
byte *tmp = _vm->_displayMan->_tmpBitmap;
- for (uint16 i = 0; i < (k5_LetterWidth + 1) * k6_LetterHeight * 128; ++i) {
+ for (uint16 i = 0; i < (k5_LetterWidth + 1) * k6_LetterHeight * 128; ++i)
tmp[i] = srcBitmap[i] ? textColor : bgColor;
- }
+
srcBitmap = tmp;
for (const char *begin = text, *end = text + textLength; begin != end; ++begin) {
@@ -77,6 +75,7 @@ void TextMan::printTextToBitmap(byte* destBitmap, uint16 destByteWidth, int16 de
}
if (nextY + k6_LetterHeight >= destHeight)
break;
+
uint16 srcX = (1 + 5) * *begin; // 1 + 5 is not the letter width, arbitrary choice of the unpacking code
Box box((nextX == destX) ? (nextX + 1) : nextX, nextX + k5_LetterWidth + 1, nextY, nextY + k6_LetterHeight - 1);
@@ -87,16 +86,16 @@ void TextMan::printTextToBitmap(byte* destBitmap, uint16 destByteWidth, int16 de
}
}
-void TextMan::printToLogicalScreen(uint16 destX, uint16 destY, Color textColor, Color bgColor, const char* text) {
+void TextMan::printToLogicalScreen(uint16 destX, uint16 destY, Color textColor, Color bgColor, const char *text) {
printTextToBitmap(_vm->_displayMan->_bitmapScreen, _vm->_displayMan->_screenWidth / 2, destX, destY, textColor, bgColor, text, _vm->_displayMan->_screenHeight);
}
-void TextMan::printToViewport(int16 posX, int16 posY, Color textColor, const char* text, Color bgColor) {
+void TextMan::printToViewport(int16 posX, int16 posY, Color textColor, const char *text, Color bgColor) {
printTextToBitmap(_vm->_displayMan->_bitmapViewport, k112_byteWidthViewport, posX, posY, textColor, bgColor, text, k136_heightViewport);
}
-void TextMan::printWithTrailingSpaces(byte* destBitmap, int16 destByteWidth, int16 destX, int16 destY, Color textColor,
- Color bgColor, const char* text, int16 requiredTextLength, int16 destHeight) {
+void TextMan::printWithTrailingSpaces(byte *destBitmap, int16 destByteWidth, int16 destX, int16 destY, Color textColor,
+ Color bgColor, const char *text, int16 requiredTextLength, int16 destHeight) {
Common::String str = text;
for (int16 i = str.size(); i < requiredTextLength; ++i)
str += ' ';
@@ -107,10 +106,9 @@ void TextMan::printLineFeed() {
printMessage(k0_ColorBlack, "\n");
}
-void TextMan::printMessage(Color color, const char* string, bool printWithScroll) {
- uint16 L0031_ui_CharacterIndex;
- char L0033_ac_String[54];
-
+void TextMan::printMessage(Color color, const char *string, bool printWithScroll) {
+ uint16 characterIndex;
+ Common::String wrkString;
while (*string) {
if (*string == '\n') { /* New line */
@@ -119,59 +117,53 @@ void TextMan::printMessage(Color color, const char* string, bool printWithScroll
_messageAreaCursorColumn = 0;
createNewRow();
}
+ } else if (*string == ' ') {
+ string++;
+ if (_messageAreaCursorColumn != 53) {
+ printString(color, " "); // I'm not sure if this is like the original
+ }
} else {
- if (*string == ' ') {
- string++;
- if (_messageAreaCursorColumn != 53) {
- printString(color, " "); // I'm not sure if this is like the original
- }
- } else {
- L0031_ui_CharacterIndex = 0;
- do {
- L0033_ac_String[L0031_ui_CharacterIndex++] = *string++;
- } while (*string && (*string != ' ') && (*string != '\n')); /* End of string, space or New line */
- L0033_ac_String[L0031_ui_CharacterIndex] = '\0';
- if (_messageAreaCursorColumn + L0031_ui_CharacterIndex > 53) {
- _messageAreaCursorColumn = 2;
- createNewRow();
- }
- printString(color, L0033_ac_String);
+ characterIndex = 0;
+ do {
+ wrkString += *string++;
+ characterIndex++;
+ } while (*string && (*string != ' ') && (*string != '\n')); /* End of string, space or New line */
+ wrkString += '\0';
+ if (_messageAreaCursorColumn + characterIndex > 53) {
+ _messageAreaCursorColumn = 2;
+ createNewRow();
}
+ printString(color, wrkString.c_str());
}
}
}
void TextMan::createNewRow() {
- uint16 L0029_ui_RowIndex;
-
if (_messageAreaCursorRow == 3) {
isTextScrolling(&_textScroller, true);
memset(_bitmapMessageAreaNewRow, k0_ColorBlack, 320 * 7);
_isScrolling = true;
setScrollerCommand(&_textScroller, 1);
- for (L0029_ui_RowIndex = 0; L0029_ui_RowIndex < 3; L0029_ui_RowIndex++) {
- _messageAreaRowExpirationTime[L0029_ui_RowIndex] = _messageAreaRowExpirationTime[L0029_ui_RowIndex + 1];
- }
+ for (uint16 rowIndex = 0; rowIndex < 3; rowIndex++)
+ _messageAreaRowExpirationTime[rowIndex] = _messageAreaRowExpirationTime[rowIndex + 1];
+
_messageAreaRowExpirationTime[3] = -1;
- } else {
+ } else
_messageAreaCursorRow++;
- }
}
void TextMan::printString(Color color, const char* string) {
- int16 L0030_i_StringLength;
-
- L0030_i_StringLength = strlen(string);
- if (isTextScrolling(&_textScroller, false)) {
+ int16 stringLength = strlen(string);
+ if (isTextScrolling(&_textScroller, false))
printToLogicalScreen(_messageAreaCursorColumn * 6, (_messageAreaCursorRow * 7 - 1) + 177, color, k0_ColorBlack, string);
- } else {
+ else {
printTextToBitmap(_bitmapMessageAreaNewRow, k160_byteWidthScreen, _messageAreaCursorColumn * 6, 0, color, k0_ColorBlack, string, 7);
_isScrolling = true;
if (isTextScrolling(&_textScroller, false))
setScrollerCommand(&_textScroller, 1);
}
- _messageAreaCursorColumn += L0030_i_StringLength;
+ _messageAreaCursorColumn += stringLength;
_messageAreaRowExpirationTime[_messageAreaCursorRow] = _vm->_gameTime + 200;
}
@@ -183,21 +175,17 @@ void TextMan::initialize() {
}
void TextMan::moveCursor(int16 column, int16 row) {
- if (column < 0) {
+ if (column < 0)
column = 0;
- } else {
- if (column >= 53) {
- column = 52;
- }
- }
+ else if (column >= 53)
+ column = 52;
+
_messageAreaCursorColumn = column;
- if (row < 0) {
+ if (row < 0)
row = 0;
- } else {
- if (row >= 4) {
- row = 3;
- }
- }
+ else if (row >= 4)
+ row = 3;
+
_messageAreaCursorRow = row;
}