2016-06-22 20:32:30 +02:00
|
|
|
#include "text.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
|
|
|
TextMan::TextMan(DMEngine* vm) : _vm(vm) {}
|
|
|
|
|
|
|
|
#define kLetterWidth 5
|
|
|
|
#define kLetterHeight 6
|
|
|
|
|
2016-08-26 22:35:29 +02:00
|
|
|
void TextMan::printTextToBitmap(byte* destBitmap, uint16 destPixelWidth, uint16 destX, uint16 destY,
|
|
|
|
Color textColor, Color bgColor, const char* text, uint16 destHeight, Viewport &viewport) {
|
|
|
|
destX -= 1; // fixes missalignment, to be checked
|
|
|
|
destY -= 4; // fixes missalignment, to be checked
|
|
|
|
|
2016-06-22 20:32:30 +02:00
|
|
|
uint16 textLength = strlen(text);
|
|
|
|
uint16 nextX = destX;
|
|
|
|
uint16 nextY = destY;
|
|
|
|
byte *srcBitmap = _vm->_displayMan->getBitmap(kFontGraphicIndice);
|
|
|
|
|
2016-06-22 20:49:19 +02:00
|
|
|
byte *tmp = _vm->_displayMan->_tmpBitmap;
|
2016-08-26 22:35:29 +02:00
|
|
|
for (uint16 i = 0; i < (kLetterWidth + 1) * kLetterHeight * 128; ++i) {
|
2016-06-22 20:49:19 +02:00
|
|
|
tmp[i] = srcBitmap[i] ? textColor : bgColor;
|
|
|
|
}
|
|
|
|
srcBitmap = tmp;
|
|
|
|
|
2016-08-26 22:35:29 +02:00
|
|
|
for (const char *begin = text, *end = text + textLength; begin != end; ++begin) {
|
|
|
|
if (nextX + kLetterWidth + 1 >= (viewport._posX + viewport._width) || (*begin == '\n')) {
|
2016-06-22 20:32:30 +02:00
|
|
|
nextX = destX;
|
|
|
|
nextY += kLetterHeight + 1;
|
|
|
|
}
|
2016-08-26 22:35:29 +02:00
|
|
|
if (nextY + kLetterHeight >= (viewport._posY + viewport._height))
|
2016-06-22 20:32:30 +02:00
|
|
|
break;
|
|
|
|
uint16 srcX = (1 + 5) * toupper(*begin); // 1 + 5 is not the letter width, arbitrary choice of the unpacking code
|
2016-08-26 22:35:29 +02:00
|
|
|
_vm->_displayMan->blitToBitmap(srcBitmap, 6 * 128, (nextX == destX) ? (srcX + 1) : srcX, 0, destBitmap, destPixelWidth,
|
|
|
|
(nextX == destX) ? (nextX + 1) : nextX, nextX + kLetterWidth + 1, nextY, nextY + kLetterHeight, kColorNoTransparency, viewport);
|
2016-06-22 20:32:30 +02:00
|
|
|
nextX += kLetterWidth + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 22:35:29 +02:00
|
|
|
void TextMan::printTextToScreen(uint16 destX, uint16 destY, Color textColor, Color bgColor, const char* text, Viewport &viewport) {
|
2016-06-22 20:32:30 +02:00
|
|
|
printTextToBitmap(_vm->_displayMan->_vgaBuffer, _vm->_displayMan->_screenWidth, destX, destY, textColor, bgColor, text, _vm->_displayMan->_screenHeight, viewport);
|
|
|
|
}
|
|
|
|
|
2016-08-26 22:35:29 +02:00
|
|
|
void TextMan::printToViewport(int16 posX, int16 posY, Color textColor, const char* text) {
|
|
|
|
printTextToScreen(posX, posY, textColor, kColorDarkestGray, text, gDungeonViewport);
|
|
|
|
}
|
|
|
|
|
2016-06-22 20:32:30 +02:00
|
|
|
}
|