2012-09-19 11:34:23 +00: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/system.h"
|
2012-10-11 11:53:59 +00:00
|
|
|
#include "common/file.h"
|
2012-09-19 11:34:23 +00:00
|
|
|
#include "common/textconsole.h"
|
|
|
|
#include "hopkins/font.h"
|
2012-09-26 12:13:15 +00:00
|
|
|
#include "hopkins/files.h"
|
|
|
|
#include "hopkins/globals.h"
|
|
|
|
#include "hopkins/graphics.h"
|
|
|
|
#include "hopkins/hopkins.h"
|
|
|
|
#include "hopkins/objects.h"
|
2012-09-19 11:34:23 +00:00
|
|
|
|
|
|
|
namespace Hopkins {
|
|
|
|
|
2012-11-25 09:18:38 +00:00
|
|
|
FontManager::FontManager() {
|
|
|
|
clearAll();
|
|
|
|
}
|
|
|
|
|
2012-09-19 11:34:23 +00:00
|
|
|
void FontManager::setParent(HopkinsEngine *vm) {
|
|
|
|
_vm = vm;
|
|
|
|
}
|
|
|
|
|
2012-09-22 09:54:30 +00:00
|
|
|
void FontManager::clearAll() {
|
2012-12-05 23:10:46 +00:00
|
|
|
for (int idx = 0; idx < 12; ++idx) {
|
2012-12-11 23:22:18 +00:00
|
|
|
Common::fill((byte *)&_text[idx], (byte *)&_text[idx] + sizeof(TxtItem), 0);
|
2012-12-05 23:10:46 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_textList[idx]._enabledFl = false;
|
|
|
|
_textList[idx]._height = 0;
|
|
|
|
_textList[idx]._width = 0;
|
|
|
|
_textList[idx]._pos.x = 0;
|
|
|
|
_textList[idx]._pos.y = 0;
|
2012-12-05 23:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 21; idx++)
|
2012-12-11 23:22:18 +00:00
|
|
|
_textSortArray[idx] = 0;
|
2012-12-05 23:10:46 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_oldName = Common::String("");
|
|
|
|
_indexName = Common::String("");
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-05 23:10:46 +00:00
|
|
|
for (int idx = 0; idx < 4048; idx++)
|
2012-12-11 23:22:18 +00:00
|
|
|
_index[idx] = 0;
|
2012-12-05 23:10:46 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_tempText = g_PTRNUL;
|
2012-09-22 09:54:30 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
/**
|
|
|
|
* Display Text
|
|
|
|
*/
|
|
|
|
void FontManager::showText(int idx) {
|
|
|
|
if ((idx - 5) > MAX_TEXT)
|
2012-09-26 12:13:15 +00:00
|
|
|
error("Attempted to display text > MAX_TEXT.");
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
TxtItem &txt = _text[idx - 5];
|
|
|
|
txt._textOnFl = true;
|
|
|
|
txt._textLoadedFl = false;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-12 07:05:04 +00:00
|
|
|
txt._textBlock = _vm->_globals.freeMemory(txt._textBlock);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
/**
|
|
|
|
* Hide text
|
|
|
|
*/
|
|
|
|
void FontManager::hideText(int idx) {
|
|
|
|
if ((idx - 5) > MAX_TEXT)
|
2012-09-26 12:13:15 +00:00
|
|
|
error("Attempted to display text > MAX_TEXT.");
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
TxtItem &txt = _text[idx - 5];
|
|
|
|
txt._textOnFl = false;
|
|
|
|
txt._textLoadedFl = false;
|
2012-12-12 07:05:04 +00:00
|
|
|
txt._textBlock = _vm->_globals.freeMemory(txt._textBlock);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
/**
|
|
|
|
* Set Text Color
|
|
|
|
*/
|
|
|
|
void FontManager::setTextColor(int idx, byte colByte) {
|
|
|
|
_text[idx - 5]._color = colByte;
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
/**
|
|
|
|
* Set Text Optimal Color
|
|
|
|
*/
|
|
|
|
void FontManager::setOptimalColor(int idx1, int idx2, int idx3, int idx4) {
|
|
|
|
setTextColor(idx1, 255);
|
|
|
|
setTextColor(idx2, 255);
|
|
|
|
setTextColor(idx3, 255);
|
|
|
|
setTextColor(idx4, 253);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
/**
|
|
|
|
* Init text structure
|
|
|
|
*/
|
2012-12-30 23:18:08 +00:00
|
|
|
void FontManager::initTextBuffers(int idx, int messageId, const Common::String &filename, int xp, int yp, int textType, int a9, int color) {
|
2013-01-20 18:12:45 +00:00
|
|
|
assert(idx - 5 >= 0 && (idx - 5) <= MAX_TEXT);
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
TxtItem &txt = _text[idx - 5];
|
|
|
|
txt._textOnFl = false;
|
|
|
|
txt._filename = filename;
|
|
|
|
txt._pos.x = xp;
|
|
|
|
txt._pos.y = yp;
|
|
|
|
txt._messageId = messageId;
|
|
|
|
txt._textType = textType;
|
2013-01-20 18:12:45 +00:00
|
|
|
txt._length = a9;
|
2012-12-11 23:22:18 +00:00
|
|
|
txt._color = color;
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-20 16:59:06 +00:00
|
|
|
// Box
|
2012-12-11 23:22:18 +00:00
|
|
|
void FontManager::box(int idx, int messageId, const Common::String &filename, int xp, int yp) {
|
2012-12-14 00:49:22 +00:00
|
|
|
byte *v9;
|
|
|
|
byte *ptre;
|
|
|
|
Common::String s;
|
|
|
|
Common::String file;
|
2012-10-11 11:53:59 +00:00
|
|
|
Common::File f;
|
2012-09-26 12:13:15 +00:00
|
|
|
|
2012-11-23 21:21:35 +00:00
|
|
|
int v73 = xp;
|
2012-09-26 12:13:15 +00:00
|
|
|
if (idx < 0)
|
|
|
|
error("Bad number for text");
|
|
|
|
_vm->_globals.police_l = 11;
|
|
|
|
|
2013-01-20 18:12:45 +00:00
|
|
|
_vm->_globals._boxWidth = 11 * _text[idx]._length;
|
2012-12-11 23:22:18 +00:00
|
|
|
if (_text[idx]._textLoadedFl) {
|
|
|
|
int textType = _text[idx]._textType;
|
|
|
|
if (textType != 6 && textType != 1 && textType != 3 && textType != 5) {
|
2012-10-15 09:49:17 +00:00
|
|
|
int yCurrent = yp + 5;
|
2012-12-22 00:28:31 +00:00
|
|
|
for (int lineNum = 0; lineNum < _text[idx]._lineCount; ++lineNum) {
|
|
|
|
displayText(xp + 5, yCurrent, _text[idx]._lines[lineNum], _text[idx]._color);
|
|
|
|
yCurrent += _vm->_globals.police_h + 1;
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-11 23:22:18 +00:00
|
|
|
int height = _text[idx]._height;
|
|
|
|
int width = _text[idx]._width;
|
2012-10-11 11:53:59 +00:00
|
|
|
_vm->_graphicsManager.Restore_Mem(
|
2012-12-19 01:15:32 +00:00
|
|
|
_vm->_graphicsManager._vesaBuffer,
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._textBlock,
|
2012-10-11 11:53:59 +00:00
|
|
|
xp,
|
|
|
|
yp,
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._width,
|
|
|
|
_text[idx]._height);
|
2013-01-01 23:57:00 +00:00
|
|
|
_vm->_graphicsManager.addVesaSegment(xp, yp, xp + width, yp + height);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-11-27 21:33:51 +00:00
|
|
|
int lineCount = 0;
|
2012-12-17 23:37:52 +00:00
|
|
|
for (int v62 = 0; v62 <= 19; v62++)
|
|
|
|
_textSortArray[v62] = 0;
|
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._textLoadedFl = true;
|
2013-01-07 22:56:39 +00:00
|
|
|
file = filename;
|
2012-12-11 23:22:18 +00:00
|
|
|
if (strncmp(file.c_str(), _oldName.c_str(), strlen(file.c_str())) != 0) {
|
2012-10-14 02:00:21 +00:00
|
|
|
// Starting to access a new file, so read in the index file for the file
|
2012-12-11 23:22:18 +00:00
|
|
|
_oldName = file;
|
|
|
|
_indexName = Common::String(file.c_str(), file.size() - 3);
|
|
|
|
_indexName += "IND";
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
if (!f.open(_indexName))
|
|
|
|
error("Error opening file - %s", _indexName.c_str());
|
2012-11-23 21:21:35 +00:00
|
|
|
int filesize = f.size();
|
|
|
|
for (int i = 0; i < (filesize / 4); ++i)
|
2012-12-11 23:22:18 +00:00
|
|
|
_index[i] = f.readUint32LE();
|
2012-09-26 12:13:15 +00:00
|
|
|
f.close();
|
|
|
|
}
|
2013-01-20 18:12:45 +00:00
|
|
|
int v69;
|
2012-10-11 11:53:59 +00:00
|
|
|
if (filename[0] != 'Z' || filename[1] != 'O') {
|
|
|
|
if (!f.open(file))
|
2012-12-11 23:22:18 +00:00
|
|
|
error("Error opening file - %s", _indexName.c_str());
|
2012-09-26 12:13:15 +00:00
|
|
|
|
|
|
|
v69 = 2048;
|
2012-12-11 23:22:18 +00:00
|
|
|
f.seek(_index[messageId]);
|
2012-10-11 11:53:59 +00:00
|
|
|
|
2012-12-21 07:12:02 +00:00
|
|
|
_tempText = _vm->_globals.allocMemory(2058);
|
2012-12-11 23:22:18 +00:00
|
|
|
if (_tempText == g_PTRNUL)
|
2012-10-11 11:53:59 +00:00
|
|
|
error("Error allocating text");
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-21 07:12:02 +00:00
|
|
|
Common::fill(&_tempText[0], &_tempText[2058], 0);
|
|
|
|
f.read(_tempText, 2048);
|
2012-09-26 12:13:15 +00:00
|
|
|
f.close();
|
|
|
|
} else {
|
|
|
|
v69 = 100;
|
2012-12-21 07:12:02 +00:00
|
|
|
v9 = _vm->_globals.allocMemory(110);
|
|
|
|
Common::fill(&v9[0], &v9[110], 0);
|
2012-10-24 12:40:16 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_tempText = v9;
|
|
|
|
const byte *v10 = _vm->_globals.BUF_ZONE + _index[messageId];
|
2012-12-21 07:12:02 +00:00
|
|
|
memcpy(v9, v10, 96);
|
2012-10-11 11:58:04 +00:00
|
|
|
WRITE_LE_UINT16((uint16 *)v9 + 48, (int16)READ_LE_UINT16(v10 + 96));
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
2012-12-11 23:22:18 +00:00
|
|
|
byte *v59 = _tempText;
|
2012-09-26 12:13:15 +00:00
|
|
|
if (!v69)
|
|
|
|
goto LABEL_43;
|
2012-11-27 21:33:51 +00:00
|
|
|
for (int v63 = 0; v63 < v69; v63++) {
|
2012-11-23 21:21:35 +00:00
|
|
|
byte v13 = *v59;
|
2012-12-21 07:12:02 +00:00
|
|
|
if ((byte)(*v59 + 46) > 27) {
|
|
|
|
if ((byte)(v13 + 80) > 27) {
|
|
|
|
if ((byte)(v13 - 65) <= 25 || (byte)(v13 - 97) <= 25)
|
2012-09-26 12:13:15 +00:00
|
|
|
v13 = 32;
|
|
|
|
} else {
|
|
|
|
v13 -= 79;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
v13 += 111;
|
|
|
|
}
|
|
|
|
*v59 = v13;
|
2012-11-27 21:33:51 +00:00
|
|
|
v59++;
|
|
|
|
};
|
2012-10-23 11:20:52 +00:00
|
|
|
|
2012-09-26 12:13:15 +00:00
|
|
|
if (v69) {
|
2013-01-20 18:12:45 +00:00
|
|
|
int textLength = 0;
|
2012-12-04 20:36:53 +00:00
|
|
|
for (;;) {
|
2013-01-20 18:12:45 +00:00
|
|
|
byte curChar = _tempText[textLength];
|
|
|
|
if (curChar == '\r' || curChar == '\n') {
|
|
|
|
_tempText[textLength] = 0;
|
|
|
|
if (!_text[idx]._length)
|
2012-09-26 12:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-01-20 18:12:45 +00:00
|
|
|
++textLength;
|
|
|
|
if (v69 <= textLength)
|
2012-09-26 12:13:15 +00:00
|
|
|
goto LABEL_43;
|
|
|
|
}
|
2013-01-20 18:12:45 +00:00
|
|
|
_text[idx]._length = textLength;
|
2012-12-25 21:48:11 +00:00
|
|
|
_vm->_globals._boxWidth = 0;
|
2012-10-11 11:53:59 +00:00
|
|
|
|
2013-01-20 18:12:45 +00:00
|
|
|
for (int v15 = 0; v15 < textLength + 1; v15++) {
|
|
|
|
byte v16 = _tempText[v15];
|
2012-12-22 00:28:31 +00:00
|
|
|
if (v16 <= 31)
|
2012-12-30 23:18:08 +00:00
|
|
|
v16 = ' ';
|
2012-12-25 21:48:11 +00:00
|
|
|
_vm->_globals._boxWidth += _vm->_objectsManager.getWidth(_vm->_globals.police, v16 - 32);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
2012-12-22 00:28:31 +00:00
|
|
|
|
2012-12-25 21:48:11 +00:00
|
|
|
_vm->_globals._boxWidth += 2;
|
|
|
|
int v17 = _vm->_globals._boxWidth / 2;
|
2012-09-26 12:13:15 +00:00
|
|
|
if (v17 < 0)
|
|
|
|
v17 = -v17;
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._pos.x = 320 - v17;
|
2012-12-11 00:53:50 +00:00
|
|
|
v73 = _vm->_eventsManager._startPos.x + 320 - v17;
|
2012-10-14 11:58:26 +00:00
|
|
|
lineCount = 1;
|
2013-01-20 18:12:45 +00:00
|
|
|
// CHECKME: textLength should be always positive...
|
|
|
|
if (textLength + 1 > 0) {
|
|
|
|
_text[idx]._lines[0] = Common::String((const char *)_tempText, textLength);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LABEL_43:
|
2012-12-25 21:48:11 +00:00
|
|
|
if (!_vm->_globals._boxWidth)
|
|
|
|
_vm->_globals._boxWidth = 240;
|
2012-11-23 21:21:35 +00:00
|
|
|
int v65 = 0;
|
|
|
|
int lineSize;
|
2013-01-20 18:12:45 +00:00
|
|
|
byte curChar;
|
2012-09-26 12:13:15 +00:00
|
|
|
do {
|
2012-11-23 21:21:35 +00:00
|
|
|
int v19 = 0;
|
2012-12-25 21:48:11 +00:00
|
|
|
int ptrb = _vm->_globals._boxWidth - 4;
|
2012-12-04 20:36:53 +00:00
|
|
|
for (;;) {
|
2012-10-14 11:58:26 +00:00
|
|
|
lineSize = v19;
|
2012-10-11 11:53:59 +00:00
|
|
|
do
|
2013-01-20 18:12:45 +00:00
|
|
|
curChar = _tempText[v65 + v19++];
|
|
|
|
while (curChar != ' ' && curChar != '%');
|
2012-10-11 11:53:59 +00:00
|
|
|
if (v19 >= ptrb / _vm->_globals.police_l)
|
2012-09-26 12:13:15 +00:00
|
|
|
break;
|
2013-01-20 18:12:45 +00:00
|
|
|
if (curChar == '%') {
|
2012-10-11 11:53:59 +00:00
|
|
|
if (v19 < ptrb / _vm->_globals.police_l)
|
2012-09-26 12:13:15 +00:00
|
|
|
goto LABEL_55;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-20 18:12:45 +00:00
|
|
|
if (curChar != '%')
|
2012-09-26 12:13:15 +00:00
|
|
|
goto LABEL_57;
|
2013-01-20 18:12:45 +00:00
|
|
|
curChar = ' ';
|
2012-09-26 12:13:15 +00:00
|
|
|
LABEL_55:
|
2013-01-20 18:12:45 +00:00
|
|
|
if (curChar == '%')
|
2012-10-14 11:58:26 +00:00
|
|
|
lineSize = v19;
|
2012-09-26 12:13:15 +00:00
|
|
|
LABEL_57:
|
2012-11-23 21:21:35 +00:00
|
|
|
int v20 = lineCount;
|
2012-10-23 11:20:52 +00:00
|
|
|
|
|
|
|
// WORKAROUND: Perhaps due to the usage of ScummVM strings here, recalculate what the
|
|
|
|
// actual length of the line to be copied will be. Otherwise, you can see artifacts,
|
|
|
|
// such as a single character beyond the end of string NULL.
|
|
|
|
int actualSize = 0;
|
2013-01-20 18:12:45 +00:00
|
|
|
while (actualSize < lineSize && _tempText[v65 + actualSize])
|
2012-10-23 11:20:52 +00:00
|
|
|
++actualSize;
|
|
|
|
|
2013-01-20 18:12:45 +00:00
|
|
|
_text[idx]._lines[v20] = Common::String((const char *)_tempText + v65, actualSize);
|
2012-12-11 23:22:18 +00:00
|
|
|
_textSortArray[lineCount++] = lineSize;
|
2012-10-11 11:53:59 +00:00
|
|
|
|
2012-10-14 11:58:26 +00:00
|
|
|
v65 += lineSize;
|
2013-01-20 18:12:45 +00:00
|
|
|
} while (curChar != '%');
|
2012-11-23 21:21:35 +00:00
|
|
|
|
|
|
|
for (int i = 0; i <= 19; i++) {
|
2012-12-22 00:28:31 +00:00
|
|
|
if (_textSortArray[i] <= 0) {
|
2012-12-11 23:22:18 +00:00
|
|
|
_textSortArray[i] = 0;
|
2012-09-26 12:13:15 +00:00
|
|
|
} else {
|
2012-11-23 21:21:35 +00:00
|
|
|
int ptrc = 0;
|
2012-12-22 00:28:31 +00:00
|
|
|
for (int v23 = 0; v23 < _textSortArray[i] - 1; v23++) {
|
|
|
|
Common::String &line = _text[idx]._lines[i];
|
|
|
|
byte v24 = (v23 >= (int)line.size()) ? '\0' : line.c_str()[v23];
|
|
|
|
if (v24 <= 32)
|
|
|
|
v24 = ' ';
|
|
|
|
ptrc += _vm->_objectsManager.getWidth(_vm->_globals.police, (byte)v24 - 32);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
2012-12-11 23:22:18 +00:00
|
|
|
_textSortArray[i] = ptrc;
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
2012-11-23 21:21:35 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i <= 19; i++) {
|
2012-12-22 00:28:31 +00:00
|
|
|
for (int v25 = i + 1; v25 != i; v25 = (v25 + 1) % 20) {
|
2012-12-11 23:22:18 +00:00
|
|
|
if (_textSortArray[i] < _textSortArray[v25])
|
|
|
|
_textSortArray[i] = 0;
|
2012-12-22 00:28:31 +00:00
|
|
|
}
|
2012-11-23 21:21:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i <= 19; i++) {
|
2012-12-11 23:22:18 +00:00
|
|
|
if (_textSortArray[i])
|
2012-12-25 21:48:11 +00:00
|
|
|
_vm->_globals._boxWidth = _textSortArray[i];
|
2012-11-23 21:21:35 +00:00
|
|
|
}
|
2012-10-11 11:53:59 +00:00
|
|
|
|
2012-12-12 22:16:07 +00:00
|
|
|
if ((_text[idx]._textType < 2) || (_text[idx]._textType > 3)) {
|
2012-11-23 21:21:35 +00:00
|
|
|
int i;
|
2012-12-25 21:48:11 +00:00
|
|
|
for (i = xp - _vm->_eventsManager._startPos.x; _vm->_globals._boxWidth + i > 638 && i > -2 && _text[idx]._textType; i -= 2)
|
2012-09-26 12:13:15 +00:00
|
|
|
;
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._pos.x = i;
|
2012-12-11 00:53:50 +00:00
|
|
|
v73 = _vm->_eventsManager._startPos.x + i;
|
2012-09-26 12:13:15 +00:00
|
|
|
} else {
|
2012-10-11 11:53:59 +00:00
|
|
|
if (_vm->_globals.nbrligne == (SCREEN_WIDTH - 1)) {
|
2012-12-25 21:48:11 +00:00
|
|
|
while (_vm->_globals._boxWidth + v73 > 638 && v73 > -2)
|
2012-09-26 12:13:15 +00:00
|
|
|
v73 -= 2;
|
|
|
|
}
|
2012-10-11 11:53:59 +00:00
|
|
|
if (_vm->_globals.nbrligne == (SCREEN_WIDTH * 2)) {
|
2012-12-25 21:48:11 +00:00
|
|
|
while (_vm->_globals._boxWidth + v73 > 1278 && v73 > -2)
|
2012-09-26 12:13:15 +00:00
|
|
|
v73 -= 2;
|
|
|
|
}
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._pos.x = v73;
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-01 20:03:24 +00:00
|
|
|
int posX = v73;
|
|
|
|
int posY = yp;
|
|
|
|
int saveWidth = _vm->_globals._boxWidth + 10;
|
|
|
|
int saveHeight = (_vm->_globals.police_h + 1) * lineCount + 12;
|
2012-12-11 23:22:18 +00:00
|
|
|
if (_text[idx]._textType == 6) {
|
2013-01-01 20:03:24 +00:00
|
|
|
int v27 = saveWidth / 2;
|
2012-09-26 12:13:15 +00:00
|
|
|
if (v27 < 0)
|
|
|
|
v27 = -v27;
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._pos.x = 315 - v27;
|
2012-12-11 00:53:50 +00:00
|
|
|
int v28 = _vm->_eventsManager._startPos.x + 315 - v27;
|
|
|
|
v73 = _vm->_eventsManager._startPos.x + 315 - v27;
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._pos.y = 50;
|
2013-01-01 20:03:24 +00:00
|
|
|
posY = 50;
|
|
|
|
posX = v28;
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
2012-12-11 23:22:18 +00:00
|
|
|
int textType = _text[idx]._textType;
|
|
|
|
if (textType == 1 || textType == 3 || textType == 5 || textType == 6) {
|
2013-01-01 20:03:24 +00:00
|
|
|
int size = saveHeight * saveWidth;
|
|
|
|
byte *ptrd = _vm->_globals.allocMemory(size);
|
|
|
|
if (ptrd == g_PTRNUL)
|
|
|
|
error("Cutting a block for text box (%d)", size);
|
|
|
|
|
|
|
|
_vm->_graphicsManager.Capture_Mem(_vm->_graphicsManager._vesaBuffer, ptrd, posX, posY, saveWidth, saveHeight);
|
|
|
|
_vm->_graphicsManager.Trans_bloc2(ptrd, _vm->_graphicsManager._colorTable, size);
|
|
|
|
_vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager._vesaBuffer, ptrd, posX, posY, saveWidth, saveHeight);
|
2012-12-12 07:05:04 +00:00
|
|
|
_vm->_globals.freeMemory(ptrd);
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2013-01-01 20:03:24 +00:00
|
|
|
_vm->_graphicsManager.drawHorizontalLine(_vm->_graphicsManager._vesaBuffer, posX, posY, saveWidth, (byte)-2);
|
|
|
|
_vm->_graphicsManager.drawHorizontalLine(_vm->_graphicsManager._vesaBuffer, posX, saveHeight + posY, saveWidth, (byte)-2);
|
|
|
|
_vm->_graphicsManager.drawVerticalLine(_vm->_graphicsManager._vesaBuffer, posX, posY, saveHeight, (byte)-2);
|
|
|
|
_vm->_graphicsManager.drawVerticalLine(_vm->_graphicsManager._vesaBuffer, saveWidth + posX, posY, saveHeight, (byte)-2);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._lineCount = lineCount;
|
2013-01-01 20:03:24 +00:00
|
|
|
int v71 = posY + 5;
|
2012-10-14 11:58:26 +00:00
|
|
|
|
2012-12-22 00:28:31 +00:00
|
|
|
for (int lineNum = 0; lineNum < lineCount; ++lineNum) {
|
2013-01-01 20:03:24 +00:00
|
|
|
displayText(v73 + 5, v71, _text[idx]._lines[lineNum], _text[idx]._color);
|
2012-12-22 00:28:31 +00:00
|
|
|
v71 += _vm->_globals.police_h + 1;
|
2012-10-11 11:53:59 +00:00
|
|
|
}
|
2012-10-15 09:49:17 +00:00
|
|
|
|
2013-01-01 20:03:24 +00:00
|
|
|
int blockWidth = saveWidth + 1;
|
|
|
|
int blockHeight = saveHeight + 1;
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._width = blockWidth;
|
|
|
|
_text[idx]._height = blockHeight;
|
|
|
|
textType = _text[idx]._textType;
|
|
|
|
if (textType == 6 || textType == 1 || textType == 3 || textType == 5) {
|
2012-12-12 07:05:04 +00:00
|
|
|
_text[idx]._textBlock = _vm->_globals.freeMemory(_text[idx]._textBlock);
|
2012-11-23 21:21:35 +00:00
|
|
|
int blockSize = blockHeight * blockWidth;
|
2012-12-12 07:05:04 +00:00
|
|
|
ptre = _vm->_globals.allocMemory(blockSize + 20);
|
2012-10-11 11:53:59 +00:00
|
|
|
if (ptre == g_PTRNUL)
|
2012-10-15 09:49:17 +00:00
|
|
|
error("Cutting a block for text box (%d)", blockSize);
|
2012-10-11 11:53:59 +00:00
|
|
|
|
2012-12-11 23:22:18 +00:00
|
|
|
_text[idx]._textBlock = ptre;
|
|
|
|
_text[idx]._width = blockWidth;
|
|
|
|
_text[idx]._height = blockHeight;
|
2013-01-01 20:03:24 +00:00
|
|
|
_vm->_graphicsManager.Capture_Mem(_vm->_graphicsManager._vesaBuffer, _text[idx]._textBlock, posX, posY, _text[idx]._width, blockHeight);
|
2012-10-11 11:53:59 +00:00
|
|
|
}
|
2012-12-12 07:05:04 +00:00
|
|
|
_tempText = _vm->_globals.freeMemory(_tempText);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-12 07:05:04 +00:00
|
|
|
|
2012-12-14 00:49:22 +00:00
|
|
|
/**
|
2012-12-12 07:05:04 +00:00
|
|
|
* Directly display text (using a VESA segment)
|
2012-12-11 23:22:18 +00:00
|
|
|
*/
|
|
|
|
void FontManager::displayTextVesa(int xp, int yp, const Common::String &message, int col) {
|
2012-12-14 00:49:22 +00:00
|
|
|
char currChar;
|
|
|
|
int charIndex;
|
2012-11-18 08:31:43 +00:00
|
|
|
int currentX = xp;
|
2012-11-17 09:49:07 +00:00
|
|
|
|
2013-01-01 20:03:24 +00:00
|
|
|
const char *srcP = message.c_str();
|
2012-11-17 09:49:07 +00:00
|
|
|
for (;;) {
|
|
|
|
currChar = *srcP++;
|
|
|
|
if (!currChar)
|
|
|
|
break;
|
|
|
|
if (currChar >= 32) {
|
|
|
|
charIndex = currChar - 32;
|
2012-12-24 00:43:37 +00:00
|
|
|
_vm->_graphicsManager.displayFont(_vm->_graphicsManager._vesaBuffer, _vm->_globals.police,
|
2012-11-18 08:31:43 +00:00
|
|
|
currentX, yp, currChar - 32, col);
|
2012-12-10 06:54:03 +00:00
|
|
|
currentX += _vm->_objectsManager.getWidth(_vm->_globals.police, charIndex);
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-18 08:31:43 +00:00
|
|
|
|
2013-01-01 23:57:00 +00:00
|
|
|
_vm->_graphicsManager.addVesaSegment(xp, yp, currentX, yp + 12);
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-12-14 00:49:22 +00:00
|
|
|
/**
|
2012-12-12 07:05:04 +00:00
|
|
|
* Directly display text
|
|
|
|
*/
|
2012-12-11 23:22:18 +00:00
|
|
|
void FontManager::displayText(int xp, int yp, const Common::String &message, int col) {
|
2012-09-26 12:13:15 +00:00
|
|
|
for (uint idx = 0; idx < message.size(); ++idx) {
|
|
|
|
char currentChar = message[idx];
|
|
|
|
|
|
|
|
if (currentChar > 31) {
|
|
|
|
int characterIndex = currentChar - 32;
|
2013-01-07 07:02:19 +00:00
|
|
|
_vm->_graphicsManager.displayFont(_vm->_graphicsManager._vesaBuffer, _vm->_globals.police, xp, yp, characterIndex, col);
|
2012-12-10 06:54:03 +00:00
|
|
|
xp += _vm->_objectsManager.getWidth(_vm->_globals.police, characterIndex);
|
2012-09-26 12:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-19 11:34:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:27:04 +00:00
|
|
|
/**
|
|
|
|
* Compute character width and render text using variable width fonts
|
|
|
|
*/
|
|
|
|
void FontManager::renderTextDisplay(int xp, int yp, const Common::String &msg, int col) {
|
|
|
|
const char *srcP = msg.c_str();
|
|
|
|
int charEndPosX = xp;
|
|
|
|
int fontCol = col;
|
|
|
|
byte curChar = *srcP++;
|
|
|
|
while (curChar) {
|
|
|
|
if (curChar == '&') {
|
2012-11-18 05:05:38 +00:00
|
|
|
fontCol = 2;
|
2013-01-11 20:27:04 +00:00
|
|
|
curChar = *srcP++;
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
2013-01-11 20:27:04 +00:00
|
|
|
if (curChar == '$') {
|
2012-11-18 05:05:38 +00:00
|
|
|
fontCol = 4;
|
2013-01-11 20:27:04 +00:00
|
|
|
curChar = *srcP++;
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
2013-01-11 20:27:04 +00:00
|
|
|
if (!curChar)
|
2012-11-17 09:49:07 +00:00
|
|
|
break;
|
2013-01-11 20:27:04 +00:00
|
|
|
if (curChar >= 32) {
|
|
|
|
byte printChar = curChar - 32;
|
|
|
|
_vm->_graphicsManager.displayFont(_vm->_graphicsManager._vesaBuffer, _vm->_globals.police, charEndPosX, yp, printChar, fontCol);
|
|
|
|
charEndPosX += _vm->_objectsManager.getWidth(_vm->_globals.police, printChar);
|
|
|
|
int charWidth = _vm->_objectsManager.getWidth(_vm->_globals.police, printChar);
|
|
|
|
_vm->_graphicsManager.addVesaSegment(charEndPosX - charWidth, yp, charEndPosX, yp + 12);
|
2012-12-11 00:53:50 +00:00
|
|
|
if (_vm->_eventsManager._escKeyFl) {
|
2012-11-17 09:49:07 +00:00
|
|
|
_vm->_globals.iRegul = 1;
|
|
|
|
_vm->_eventsManager.VBL();
|
|
|
|
} else {
|
|
|
|
_vm->_globals.iRegul = 4;
|
|
|
|
_vm->_eventsManager.VBL();
|
|
|
|
_vm->_globals.iRegul = 1;
|
|
|
|
}
|
|
|
|
}
|
2013-01-11 20:27:04 +00:00
|
|
|
curChar = *srcP++;
|
|
|
|
}
|
2012-11-17 09:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-19 11:34:23 +00:00
|
|
|
} // End of namespace Hopkins
|