aboutsummaryrefslogtreecommitdiff
path: root/engines/dm/text.cpp
blob: 116058de358ab6007c5329d8cc6587ae720039bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "text.h"


namespace DM {

TextMan::TextMan(DMEngine* vm) : _vm(vm) {}

#define kLetterWidth 5
#define kLetterHeight 6

void TextMan::printTextToBitmap(byte* destBitmap, uint16 destPixelWidth, uint16 destX, uint16 destY, Color textColor, Color bgColor, char* text, uint16 destHeight, Viewport &viewport) {
	uint16 textLength = strlen(text);
	uint16 nextX = destX;
	uint16 nextY = destY;
	byte *srcBitmap = _vm->_displayMan->getBitmap(kFontGraphicIndice);


	for (char *begin = text, *end = text + textLength; begin != end; ++begin) {
		// Note: this does no wraps in the middle of words
		if (nextX + kLetterWidth + 1 > destPixelWidth || (*begin == '\n')) {
			nextX = destX;
			nextY += kLetterHeight + 1;
		}
		if (nextY + kLetterHeight + 1 > destHeight)
			break;
		uint16 srcX = (1 + 5) * toupper(*begin); // 1 + 5 is not the letter width, arbitrary choice of the unpacking code
		_vm->_displayMan->blitToBitmap(srcBitmap, 6 * 128, srcX, 0, destBitmap, destPixelWidth,
									   nextX, nextX + kLetterWidth + 1, nextY, nextY + kLetterHeight + 1, kColorNoTransparency, viewport);
		nextX += kLetterWidth + 1;
	}
}

void TextMan::printTextToScreen(uint16 destX, uint16 destY, Color textColor, Color bgColor, char* text, Viewport &viewport) {
	printTextToBitmap(_vm->_displayMan->_vgaBuffer, _vm->_displayMan->_screenWidth, destX, destY, textColor, bgColor, text, _vm->_displayMan->_screenHeight, viewport);
}

}