2016-08-26 22:36:31 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on the Reverse Engineering work of Christophe Fontanel,
|
|
|
|
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
|
|
|
|
*/
|
|
|
|
|
2016-06-22 20:32:30 +02:00
|
|
|
#include "text.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
|
|
|
TextMan::TextMan(DMEngine* vm) : _vm(vm) {}
|
|
|
|
|
2016-07-02 12:57:31 +02:00
|
|
|
#define k5_LetterWidth 5
|
|
|
|
#define k6_LetterHeight 6
|
2016-06-22 20:32:30 +02:00
|
|
|
|
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;
|
2016-07-02 00:27:05 +02:00
|
|
|
byte *srcBitmap = _vm->_displayMan->getBitmap(k557_FontGraphicIndice);
|
2016-06-22 20:32:30 +02:00
|
|
|
|
2016-07-02 00:27:05 +02:00
|
|
|
byte *tmp = _vm->_displayMan->_g74_tmpBitmap;
|
2016-07-02 12:57:31 +02:00
|
|
|
for (uint16 i = 0; i < (k5_LetterWidth + 1) * k6_LetterHeight * 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) {
|
2016-07-02 12:57:31 +02:00
|
|
|
if (nextX + k5_LetterWidth + 1 >= (viewport._posX + viewport._width) || (*begin == '\n')) {
|
2016-06-22 20:32:30 +02:00
|
|
|
nextX = destX;
|
2016-07-02 12:57:31 +02:00
|
|
|
nextY += k6_LetterHeight + 1;
|
2016-06-22 20:32:30 +02:00
|
|
|
}
|
2016-07-02 12:57:31 +02:00
|
|
|
if (nextY + k6_LetterHeight >= (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,
|
2016-07-02 12:57:31 +02:00
|
|
|
(nextX == destX) ? (nextX + 1) : nextX, nextX + k5_LetterWidth + 1, nextY, nextY + k6_LetterHeight, k255_ColorNoTransparency, viewport);
|
|
|
|
nextX += k5_LetterWidth + 1;
|
2016-06-22 20:32:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-07-02 19:24:13 +02:00
|
|
|
printTextToBitmap(_vm->_displayMan->_g348_bitmapScreen, _vm->_displayMan->_screenWidth, destX, destY, textColor, bgColor, text, _vm->_displayMan->_screenHeight, viewport);
|
2016-06-22 20:32:30 +02:00
|
|
|
}
|
|
|
|
|
2016-06-27 23:38:37 +02:00
|
|
|
void TextMan::printToViewport(int16 posX, int16 posY, Color textColor, const char* text, Color bgColor) {
|
2016-07-02 01:19:53 +02:00
|
|
|
printTextToScreen(posX, posY, textColor, bgColor, text, g296_DungeonViewport);
|
2016-08-26 22:35:29 +02:00
|
|
|
}
|
|
|
|
|
2016-06-25 16:27:31 +02:00
|
|
|
void TextMan::printWithTrailingSpaces(byte* destBitmap, int16 destPixelWidth, int16 destX, int16 destY, Color textColor,
|
|
|
|
Color bgColor, const char* text, int16 requiredTextLength, int16 destHeight, Viewport& viewport) {
|
|
|
|
Common::String str = text;
|
|
|
|
for (int16 i = str.size(); i < requiredTextLength; ++i)
|
|
|
|
str += ' ';
|
|
|
|
printTextToBitmap(destBitmap, destPixelWidth, destX, destY, textColor, bgColor, str.c_str(), destHeight, viewport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextMan::printWithTrailingSpacesToScreen(int16 destX, int16 destY, Color textColor, Color bgColor, const char* text, int16 strLenght, Viewport& viewport) {
|
2016-07-02 19:24:13 +02:00
|
|
|
printWithTrailingSpaces(_vm->_displayMan->_g348_bitmapScreen, _vm->_displayMan->_screenWidth, destX, destY,
|
2016-06-25 16:27:31 +02:00
|
|
|
textColor, bgColor, text, strLenght, _vm->_displayMan->_screenHeight, viewport);
|
|
|
|
}
|
|
|
|
|
2016-06-22 20:32:30 +02:00
|
|
|
}
|