2009-10-26 19:33:07 +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.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2009-10-26 19:33:07 +00:00
|
|
|
* 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.
|
2014-02-18 02:34:24 +01:00
|
|
|
*
|
2009-10-26 19:33:07 +00:00
|
|
|
* 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/util.h"
|
|
|
|
#include "common/stack.h"
|
|
|
|
#include "graphics/primitives.h"
|
|
|
|
|
|
|
|
#include "sci/sci.h"
|
2009-10-28 12:58:13 +00:00
|
|
|
#include "sci/engine/state.h"
|
2010-01-31 17:45:22 +00:00
|
|
|
#include "sci/graphics/cache.h"
|
2010-09-09 10:52:17 +00:00
|
|
|
#include "sci/graphics/coordadjuster.h"
|
2010-01-31 12:35:15 +00:00
|
|
|
#include "sci/graphics/ports.h"
|
|
|
|
#include "sci/graphics/paint16.h"
|
2010-01-05 01:37:57 +00:00
|
|
|
#include "sci/graphics/font.h"
|
2010-04-20 16:46:26 +00:00
|
|
|
#include "sci/graphics/screen.h"
|
2010-01-31 21:54:43 +00:00
|
|
|
#include "sci/graphics/text16.h"
|
2009-10-26 19:33:07 +00:00
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2013-04-18 20:14:44 +02:00
|
|
|
GfxText16::GfxText16(GfxCache *cache, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen)
|
|
|
|
: _cache(cache), _ports(ports), _paint16(paint16), _screen(screen) {
|
2009-10-26 19:33:07 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
GfxText16::~GfxText16() {
|
2009-10-26 19:33:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::init() {
|
2009-10-28 12:58:13 +00:00
|
|
|
_font = NULL;
|
2009-10-30 22:50:21 +00:00
|
|
|
_codeFonts = NULL;
|
|
|
|
_codeFontsCount = 0;
|
|
|
|
_codeColors = NULL;
|
|
|
|
_codeColorsCount = 0;
|
2009-10-26 19:33:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
GuiResourceId GfxText16::GetFontId() {
|
2010-01-31 12:35:15 +00:00
|
|
|
return _ports->_curPort->fontId;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 12:30:41 +00:00
|
|
|
GfxFont *GfxText16::GetFont() {
|
2010-01-31 17:45:22 +00:00
|
|
|
if ((_font == NULL) || (_font->getResourceId() != _ports->_curPort->fontId))
|
|
|
|
_font = _cache->getFont(_ports->_curPort->fontId);
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
return _font;
|
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::SetFont(GuiResourceId fontId) {
|
2010-01-31 17:45:22 +00:00
|
|
|
if ((_font == NULL) || (_font->getResourceId() != fontId))
|
|
|
|
_font = _cache->getFont(fontId);
|
2009-10-28 12:58:13 +00:00
|
|
|
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->_curPort->fontId = _font->getResourceId();
|
|
|
|
_ports->_curPort->fontHeight = _font->getHeight();
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::ClearChar(int16 chr) {
|
2010-01-31 12:35:15 +00:00
|
|
|
if (_ports->_curPort->penMode != 1)
|
2009-10-28 12:58:13 +00:00
|
|
|
return;
|
|
|
|
Common::Rect rect;
|
2010-01-31 12:35:15 +00:00
|
|
|
rect.top = _ports->_curPort->curTop;
|
|
|
|
rect.bottom = rect.top + _ports->_curPort->fontHeight;
|
|
|
|
rect.left = _ports->_curPort->curLeft;
|
2009-10-28 12:58:13 +00:00
|
|
|
rect.right = rect.left + GetFont()->getCharWidth(chr);
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->eraseRect(rect);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-29 14:55:32 +00:00
|
|
|
// This internal function gets called as soon as a '|' is found in a text. It
|
|
|
|
// will process the encountered code and set new font/set color. We only support
|
|
|
|
// one-digit codes currently, don't know if multi-digit codes are possible.
|
|
|
|
// Returns textcode character count.
|
2010-09-09 10:52:17 +00:00
|
|
|
int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor, bool doingDrawing) {
|
2009-10-28 12:58:13 +00:00
|
|
|
const char *textCode = text;
|
|
|
|
int16 textCodeSize = 0;
|
|
|
|
char curCode;
|
2010-08-12 09:52:00 +00:00
|
|
|
signed char curCodeParm;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
// Find the end of the textcode
|
|
|
|
while ((++textCodeSize) && (*text != 0) && (*text++ != 0x7C)) { }
|
|
|
|
|
|
|
|
// possible TextCodes:
|
|
|
|
// c -> sets textColor to current port pen color
|
|
|
|
// cX -> sets textColor to _textColors[X-1]
|
|
|
|
curCode = textCode[0];
|
|
|
|
curCodeParm = textCode[1];
|
2012-02-20 16:03:39 +01:00
|
|
|
if (Common::isDigit(curCodeParm)) {
|
2009-10-28 12:58:13 +00:00
|
|
|
curCodeParm -= '0';
|
|
|
|
} else {
|
2010-08-12 09:52:00 +00:00
|
|
|
curCodeParm = -1;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
switch (curCode) {
|
|
|
|
case 'c': // set text color
|
2010-08-12 09:52:00 +00:00
|
|
|
if (curCodeParm == -1) {
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->_curPort->penClr = orgPenColor;
|
2009-10-28 12:58:13 +00:00
|
|
|
} else {
|
|
|
|
if (curCodeParm < _codeColorsCount) {
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->_curPort->penClr = _codeColors[curCodeParm];
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-08-12 09:52:00 +00:00
|
|
|
case 'f': // set text font
|
|
|
|
if (curCodeParm == -1) {
|
2009-10-28 12:58:13 +00:00
|
|
|
SetFont(orgFontId);
|
|
|
|
} else {
|
|
|
|
if (curCodeParm < _codeFontsCount) {
|
|
|
|
SetFont(_codeFonts[curCodeParm]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-09-09 10:52:17 +00:00
|
|
|
case 'r': // reference (used in pepper)
|
|
|
|
if (doingDrawing) {
|
|
|
|
if (_codeRefTempRect.top == -1) {
|
|
|
|
// Starting point
|
|
|
|
_codeRefTempRect.top = _ports->_curPort->curTop;
|
|
|
|
_codeRefTempRect.left = _ports->_curPort->curLeft;
|
|
|
|
} else {
|
|
|
|
// End point reached
|
|
|
|
_codeRefTempRect.bottom = _ports->_curPort->curTop + _ports->_curPort->fontHeight;
|
|
|
|
_codeRefTempRect.right = _ports->_curPort->curLeft;
|
|
|
|
_codeRefRects.push_back(_codeRefTempRect);
|
|
|
|
_codeRefTempRect.left = _codeRefTempRect.top = -1;
|
|
|
|
}
|
|
|
|
}
|
2010-08-12 09:52:00 +00:00
|
|
|
break;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
return textCodeSize;
|
|
|
|
}
|
|
|
|
|
2014-11-01 23:36:29 +01:00
|
|
|
// Has actually punctuation and characters in it, that may not be the first in a line
|
|
|
|
static const uint16 text16_shiftJIS_punctuation[] = {
|
2010-04-23 13:51:59 +00:00
|
|
|
0x9F82, 0xA182, 0xA382, 0xA582, 0xA782, 0xC182, 0xA782, 0xC182, 0xE182, 0xE382, 0xE582, 0xEC82,
|
|
|
|
0x4083, 0x4283, 0x4483, 0x4683, 0x4883, 0x6283, 0x8383, 0x8583, 0x8783, 0x8E83, 0x9583, 0x9683,
|
2010-06-29 14:55:32 +00:00
|
|
|
0x5B81, 0x4181, 0x4281, 0x7681, 0x7881, 0x4981, 0x4881, 0
|
|
|
|
};
|
2010-04-23 13:51:59 +00:00
|
|
|
|
2010-06-29 14:55:32 +00:00
|
|
|
// return max # of chars to fit maxwidth with full words, does not include
|
|
|
|
// breaking space
|
2014-11-01 23:36:29 +01:00
|
|
|
// Also adjusts text pointer to the new position for the caller
|
|
|
|
//
|
|
|
|
// Special cases in games:
|
|
|
|
// Laura Bow 2 - Credits in the game menu - all the text lines start with spaces (bug #5159)
|
|
|
|
// Act 6 Coroner questionaire - the text of all control buttons has trailing spaces
|
|
|
|
// "Detective Ryan Hanrahan O'Riley" contains even more spaces (bug #5334)
|
|
|
|
// Conquests of Camelot - talking with Cobb - one text box of the dialogue contains a longer word,
|
|
|
|
// that will be broken into 2 lines (bug #5159)
|
|
|
|
int16 GfxText16::GetLongest(const char *&textPtr, int16 maxWidth, GuiResourceId orgFontId) {
|
2010-05-14 15:21:00 +00:00
|
|
|
uint16 curChar = 0;
|
2014-11-01 23:36:29 +01:00
|
|
|
const char *textStartPtr = textPtr;
|
|
|
|
const char *lastSpacePtr = NULL;
|
|
|
|
int16 lastSpaceCharCount = 0;
|
|
|
|
int16 curCharCount = 0, resultCharCount = 0;
|
|
|
|
uint16 curWidth = 0, tempWidth = 0;
|
2010-07-30 16:55:36 +00:00
|
|
|
GuiResourceId previousFontId = GetFontId();
|
|
|
|
int16 previousPenColor = _ports->_curPort->penClr;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
GetFont();
|
|
|
|
if (!_font)
|
|
|
|
return 0;
|
|
|
|
|
2014-11-01 23:36:29 +01:00
|
|
|
while (1) {
|
|
|
|
curChar = (*(const byte *)textPtr);
|
2010-04-16 18:23:50 +00:00
|
|
|
if (_font->isDoubleByte(curChar)) {
|
2014-11-01 23:36:29 +01:00
|
|
|
curChar |= (*(const byte *)textPtr + 1) << 8;
|
2010-04-16 18:23:50 +00:00
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
switch (curChar) {
|
|
|
|
case 0x7C:
|
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1) {
|
2014-11-01 23:36:29 +01:00
|
|
|
curCharCount++; textPtr++;
|
|
|
|
curCharCount += CodeProcessing(textPtr, orgFontId, previousPenColor, false);
|
2009-10-28 12:58:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-19 11:59:46 +00:00
|
|
|
// We need to add 0xD, 0xA and 0xD 0xA to curCharCount and then exit
|
2014-11-01 23:36:29 +01:00
|
|
|
// which means, we split text like for example
|
|
|
|
// - 'Mature, experienced software analyst available.' 0xD 0xA
|
|
|
|
// 'Bug installation a proven speciality. "No version too clean."' (normal game text, this is from lsl2)
|
|
|
|
// - 0xA '-------' 0xA (which is the official sierra subtitle separator) (found in multilingual versions)
|
2010-04-19 15:30:21 +00:00
|
|
|
// Sierra did it the same way.
|
2009-10-28 12:58:13 +00:00
|
|
|
case 0xD:
|
2010-04-18 12:09:22 +00:00
|
|
|
// Check, if 0xA is following, if so include it as well
|
2014-11-01 23:36:29 +01:00
|
|
|
if ((*(const byte *)textPtr + 1) == 0xA)
|
|
|
|
curCharCount++; textPtr++;
|
2010-04-19 11:59:46 +00:00
|
|
|
// it's meant to pass through here
|
2009-10-28 12:58:13 +00:00
|
|
|
case 0xA:
|
2010-04-20 11:13:09 +00:00
|
|
|
case 0x9781: // this one is used by SQ4/japanese as line break as well
|
2014-11-01 23:36:29 +01:00
|
|
|
curCharCount++; textPtr++;
|
2010-04-19 11:59:46 +00:00
|
|
|
// and it's also meant to pass through here
|
2009-10-28 12:58:13 +00:00
|
|
|
case 0:
|
2010-07-30 16:55:36 +00:00
|
|
|
SetFont(previousFontId);
|
|
|
|
_ports->penColor(previousPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
return curCharCount;
|
|
|
|
|
|
|
|
case ' ':
|
2014-11-01 23:36:29 +01:00
|
|
|
lastSpaceCharCount = curCharCount; // return count up to (but not including) breaking space
|
|
|
|
lastSpacePtr = textPtr + 1; // remember position right after the current space
|
2009-10-28 12:58:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-01 23:36:29 +01:00
|
|
|
tempWidth += _font->getCharWidth(curChar);
|
|
|
|
|
|
|
|
// Width is too large? -> break out
|
|
|
|
if (tempWidth > maxWidth)
|
2011-03-02 20:38:21 +02:00
|
|
|
break;
|
2011-03-13 17:50:40 +02:00
|
|
|
|
2014-11-01 23:36:29 +01:00
|
|
|
// still fits, remember width
|
|
|
|
curWidth = tempWidth;
|
2010-04-23 13:51:59 +00:00
|
|
|
|
2014-11-01 23:36:29 +01:00
|
|
|
// go to next character
|
|
|
|
curCharCount++; textPtr++;
|
|
|
|
if (curChar > 0xFF) {
|
|
|
|
// Double-Byte
|
|
|
|
curCharCount++; textPtr++;
|
|
|
|
}
|
|
|
|
}
|
2010-04-23 13:51:59 +00:00
|
|
|
|
2014-11-01 23:36:29 +01:00
|
|
|
if (lastSpaceCharCount) {
|
|
|
|
// Break and at least one space was found before that
|
|
|
|
resultCharCount = lastSpaceCharCount;
|
|
|
|
|
|
|
|
// additionally skip over all spaces, that are following that space, but don't count them for displaying purposes
|
|
|
|
textPtr = lastSpacePtr;
|
|
|
|
while (*textPtr == ' ')
|
|
|
|
textPtr++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Break without spaces found, we split the very first word - may also be Kanji/Japanese
|
|
|
|
if (curChar > 0xFF) {
|
|
|
|
// current charracter is Japanese
|
|
|
|
|
|
|
|
// PC-9801 SCI actually added the last character, which shouldn't fit anymore, still onto the
|
|
|
|
// screen in case maxWidth wasn't fully reached with the last character
|
|
|
|
if (maxWidth == curWidth) {
|
|
|
|
curCharCount -= 2; textPtr -= 2;
|
|
|
|
if (textPtr < textStartPtr)
|
|
|
|
error("Seeking back went too far, data corruption?");
|
|
|
|
|
|
|
|
curChar = (*(const byte *)textPtr);
|
|
|
|
if (!_font->isDoubleByte(curChar))
|
|
|
|
error("Non double byte while seeking back");
|
|
|
|
curChar |= (*(const byte *)textPtr + 1) << 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
// But it also checked, if the current character is not inside a punctuation table and it even
|
|
|
|
// went backwards in case it found multiple ones inside that table.
|
|
|
|
uint nonBreakingPos = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// Look up if character shouldn't be the first on a new line
|
|
|
|
nonBreakingPos = 0;
|
|
|
|
while (text16_shiftJIS_punctuation[nonBreakingPos]) {
|
|
|
|
if (text16_shiftJIS_punctuation[nonBreakingPos] == curChar)
|
|
|
|
break;
|
|
|
|
nonBreakingPos++;
|
|
|
|
}
|
|
|
|
if (!text16_shiftJIS_punctuation[nonBreakingPos]) {
|
|
|
|
// character is fine
|
2010-04-23 13:51:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-01 23:36:29 +01:00
|
|
|
// Character is not acceptable, seek backward in the text
|
|
|
|
curCharCount -= 2; textPtr -= 2;
|
|
|
|
if (textPtr < textStartPtr)
|
|
|
|
error("Seeking back went too far, data corruption?");
|
|
|
|
|
|
|
|
curChar = (*(const byte *)textPtr);
|
|
|
|
if (!_font->isDoubleByte(curChar))
|
|
|
|
error("Non double byte while seeking back");
|
|
|
|
curChar |= (*(const byte *)textPtr + 1) << 8;
|
2010-04-23 13:51:59 +00:00
|
|
|
}
|
2014-11-01 23:36:29 +01:00
|
|
|
// include the current character
|
|
|
|
curCharCount += 2; textPtr += 2;
|
2010-04-23 13:51:59 +00:00
|
|
|
}
|
2014-11-01 23:36:29 +01:00
|
|
|
|
|
|
|
// We split the word in that case
|
|
|
|
resultCharCount = curCharCount;
|
2010-04-16 13:27:30 +00:00
|
|
|
}
|
2010-07-30 16:55:36 +00:00
|
|
|
SetFont(previousFontId);
|
|
|
|
_ports->penColor(previousPenColor);
|
2014-11-01 23:36:29 +01:00
|
|
|
return resultCharCount;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 16:55:36 +00:00
|
|
|
void GfxText16::Width(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight, bool restoreFont) {
|
2010-04-16 18:23:50 +00:00
|
|
|
uint16 curChar;
|
2010-07-30 16:55:36 +00:00
|
|
|
GuiResourceId previousFontId = GetFontId();
|
|
|
|
int16 previousPenColor = _ports->_curPort->penClr;
|
|
|
|
|
2009-10-28 12:58:13 +00:00
|
|
|
textWidth = 0; textHeight = 0;
|
|
|
|
|
|
|
|
GetFont();
|
|
|
|
if (_font) {
|
|
|
|
text += from;
|
|
|
|
while (len--) {
|
2010-04-17 23:54:06 +00:00
|
|
|
curChar = (*(const byte *)text++);
|
2010-04-16 18:23:50 +00:00
|
|
|
if (_font->isDoubleByte(curChar)) {
|
2010-04-17 23:54:06 +00:00
|
|
|
curChar |= (*(const byte *)text++) << 8;
|
2010-04-16 18:23:50 +00:00
|
|
|
len--;
|
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
switch (curChar) {
|
|
|
|
case 0x0A:
|
|
|
|
case 0x0D:
|
2010-04-20 11:13:09 +00:00
|
|
|
case 0x9781: // this one is used by SQ4/japanese as line break as well
|
2010-01-31 12:35:15 +00:00
|
|
|
textHeight = MAX<int16> (textHeight, _ports->_curPort->fontHeight);
|
2009-10-28 12:58:13 +00:00
|
|
|
break;
|
|
|
|
case 0x7C:
|
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1) {
|
2010-09-09 10:52:17 +00:00
|
|
|
len -= CodeProcessing(text, orgFontId, 0, false);
|
2009-10-28 12:58:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2010-01-31 12:35:15 +00:00
|
|
|
textHeight = MAX<int16> (textHeight, _ports->_curPort->fontHeight);
|
2009-10-28 12:58:13 +00:00
|
|
|
textWidth += _font->getCharWidth(curChar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-30 16:55:36 +00:00
|
|
|
// When calculating size, we do not restore font because we need the current (code modified) font active
|
|
|
|
// If we are drawing this is called inbetween, so font needs to get restored
|
|
|
|
// If we are calculating size of just one fixed string (::StringWidth), then we need to restore
|
|
|
|
if (restoreFont) {
|
|
|
|
SetFont(previousFontId);
|
|
|
|
_ports->penColor(previousPenColor);
|
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::StringWidth(const char *str, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight) {
|
2010-07-30 16:55:36 +00:00
|
|
|
Width(str, 0, (int16)strlen(str), orgFontId, textWidth, textHeight, true);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::ShowString(const char *str, GuiResourceId orgFontId, int16 orgPenColor) {
|
2009-10-28 12:58:13 +00:00
|
|
|
Show(str, 0, (int16)strlen(str), orgFontId, orgPenColor);
|
|
|
|
}
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::DrawString(const char *str, GuiResourceId orgFontId, int16 orgPenColor) {
|
2009-10-28 12:58:13 +00:00
|
|
|
Draw(str, 0, (int16)strlen(str), orgFontId, orgPenColor);
|
|
|
|
}
|
|
|
|
|
2010-04-19 20:15:31 +00:00
|
|
|
int16 GfxText16::Size(Common::Rect &rect, const char *text, GuiResourceId fontId, int16 maxWidth) {
|
2010-07-30 16:55:36 +00:00
|
|
|
GuiResourceId previousFontId = GetFontId();
|
|
|
|
int16 previousPenColor = _ports->_curPort->penClr;
|
2009-10-28 12:58:13 +00:00
|
|
|
int16 charCount;
|
|
|
|
int16 maxTextWidth = 0, textWidth;
|
|
|
|
int16 totalHeight = 0, textHeight;
|
|
|
|
|
|
|
|
if (fontId != -1)
|
|
|
|
SetFont(fontId);
|
2010-07-26 22:58:06 +00:00
|
|
|
else
|
2010-07-30 16:55:36 +00:00
|
|
|
fontId = previousFontId;
|
2010-04-19 20:15:31 +00:00
|
|
|
|
|
|
|
if (g_sci->getLanguage() == Common::JA_JPN)
|
|
|
|
SwitchToFont900OnSjis(text);
|
|
|
|
|
2009-10-28 12:58:13 +00:00
|
|
|
rect.top = rect.left = 0;
|
|
|
|
|
|
|
|
if (maxWidth < 0) { // force output as single line
|
2010-07-26 22:58:06 +00:00
|
|
|
StringWidth(text, fontId, textWidth, textHeight);
|
2009-10-28 12:58:13 +00:00
|
|
|
rect.bottom = textHeight;
|
|
|
|
rect.right = textWidth;
|
|
|
|
} else {
|
|
|
|
// rect.right=found widest line with RTextWidth and GetLongest
|
|
|
|
// rect.bottom=num. lines * GetPointSize
|
|
|
|
rect.right = (maxWidth ? maxWidth : 192);
|
2014-11-01 23:36:29 +01:00
|
|
|
const char *curTextPos = text; // in work position for GetLongest()
|
|
|
|
const char *curTextLine = text; // starting point of current line
|
|
|
|
while (*curTextPos) {
|
|
|
|
charCount = GetLongest(curTextPos, rect.right, fontId);
|
2009-10-28 12:58:13 +00:00
|
|
|
if (charCount == 0)
|
|
|
|
break;
|
2014-11-01 23:36:29 +01:00
|
|
|
Width(curTextLine, 0, charCount, fontId, textWidth, textHeight, false);
|
2009-10-28 12:58:13 +00:00
|
|
|
maxTextWidth = MAX(textWidth, maxTextWidth);
|
|
|
|
totalHeight += textHeight;
|
2014-11-01 23:36:29 +01:00
|
|
|
curTextLine = curTextPos;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
rect.bottom = totalHeight;
|
|
|
|
rect.right = maxWidth ? maxWidth : MIN(rect.right, maxTextWidth);
|
|
|
|
}
|
2010-07-30 16:55:36 +00:00
|
|
|
SetFont(previousFontId);
|
|
|
|
_ports->penColor(previousPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
return rect.right;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns maximum font height used
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 orgPenColor) {
|
2010-04-16 18:23:50 +00:00
|
|
|
uint16 curChar, charWidth;
|
2009-10-28 12:58:13 +00:00
|
|
|
Common::Rect rect;
|
|
|
|
|
|
|
|
GetFont();
|
|
|
|
if (!_font)
|
|
|
|
return;
|
|
|
|
|
2010-01-31 12:35:15 +00:00
|
|
|
rect.top = _ports->_curPort->curTop;
|
|
|
|
rect.bottom = rect.top + _ports->_curPort->fontHeight;
|
2009-10-28 12:58:13 +00:00
|
|
|
text += from;
|
|
|
|
while (len--) {
|
2010-04-17 23:54:06 +00:00
|
|
|
curChar = (*(const byte *)text++);
|
2010-04-16 18:23:50 +00:00
|
|
|
if (_font->isDoubleByte(curChar)) {
|
2010-04-17 23:54:06 +00:00
|
|
|
curChar |= (*(const byte *)text++) << 8;
|
2010-04-16 18:23:50 +00:00
|
|
|
len--;
|
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
switch (curChar) {
|
|
|
|
case 0x0A:
|
|
|
|
case 0x0D:
|
|
|
|
case 0:
|
2010-04-20 11:13:09 +00:00
|
|
|
case 0x9781: // this one is used by SQ4/japanese as line break as well
|
2009-10-28 12:58:13 +00:00
|
|
|
break;
|
|
|
|
case 0x7C:
|
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1) {
|
2010-09-09 10:52:17 +00:00
|
|
|
len -= CodeProcessing(text, orgFontId, orgPenColor, true);
|
2009-10-28 12:58:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
charWidth = _font->getCharWidth(curChar);
|
|
|
|
// clear char
|
2010-01-31 12:35:15 +00:00
|
|
|
if (_ports->_curPort->penMode == 1) {
|
|
|
|
rect.left = _ports->_curPort->curLeft;
|
2009-10-28 12:58:13 +00:00
|
|
|
rect.right = rect.left + charWidth;
|
2010-01-31 12:35:15 +00:00
|
|
|
_paint16->eraseRect(rect);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
// CharStd
|
2010-01-31 16:49:22 +00:00
|
|
|
_font->draw(curChar, _ports->_curPort->top + _ports->_curPort->curTop, _ports->_curPort->left + _ports->_curPort->curLeft, _ports->_curPort->penClr, _ports->_curPort->greyedOutput);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->_curPort->curLeft += charWidth;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns maximum font height used
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::Show(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 orgPenColor) {
|
2009-10-28 12:58:13 +00:00
|
|
|
Common::Rect rect;
|
|
|
|
|
2010-01-31 12:35:15 +00:00
|
|
|
rect.top = _ports->_curPort->curTop;
|
|
|
|
rect.bottom = rect.top + _ports->getPointSize();
|
|
|
|
rect.left = _ports->_curPort->curLeft;
|
2009-10-28 12:58:13 +00:00
|
|
|
Draw(text, from, len, orgFontId, orgPenColor);
|
2010-01-31 12:35:15 +00:00
|
|
|
rect.right = _ports->_curPort->curLeft;
|
|
|
|
_paint16->bitsShow(rect);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draws a text in rect.
|
2011-01-09 00:32:26 +00:00
|
|
|
void GfxText16::Box(const char *text, bool show, const Common::Rect &rect, TextAlignment alignment, GuiResourceId fontId) {
|
2010-04-20 16:46:26 +00:00
|
|
|
int16 textWidth, maxTextWidth, textHeight, charCount;
|
2009-12-08 20:44:57 +00:00
|
|
|
int16 offset = 0;
|
2009-10-28 12:58:13 +00:00
|
|
|
int16 hline = 0;
|
2010-07-30 16:55:36 +00:00
|
|
|
GuiResourceId previousFontId = GetFontId();
|
|
|
|
int16 previousPenColor = _ports->_curPort->penClr;
|
2010-04-20 16:46:26 +00:00
|
|
|
bool doubleByteMode = false;
|
2014-11-01 23:36:29 +01:00
|
|
|
const char *curTextPos = text;
|
|
|
|
const char *curTextLine = text;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
if (fontId != -1)
|
|
|
|
SetFont(fontId);
|
2010-07-26 22:58:06 +00:00
|
|
|
else
|
2010-07-30 16:55:36 +00:00
|
|
|
fontId = previousFontId;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
2010-04-20 16:46:26 +00:00
|
|
|
if (g_sci->getLanguage() == Common::JA_JPN) {
|
|
|
|
if (SwitchToFont900OnSjis(text))
|
|
|
|
doubleByteMode = true;
|
|
|
|
}
|
2010-04-19 20:15:31 +00:00
|
|
|
|
2010-09-09 10:52:17 +00:00
|
|
|
// Reset reference code rects
|
|
|
|
_codeRefRects.clear();
|
|
|
|
_codeRefTempRect.left = _codeRefTempRect.top = -1;
|
|
|
|
|
2010-04-20 16:46:26 +00:00
|
|
|
maxTextWidth = 0;
|
2014-11-01 23:36:29 +01:00
|
|
|
while (*curTextPos) {
|
|
|
|
charCount = GetLongest(curTextPos, rect.width(), fontId);
|
2009-10-28 12:58:13 +00:00
|
|
|
if (charCount == 0)
|
|
|
|
break;
|
2014-11-01 23:36:29 +01:00
|
|
|
Width(curTextLine, 0, charCount, fontId, textWidth, textHeight, true);
|
2010-04-20 16:46:26 +00:00
|
|
|
maxTextWidth = MAX<int16>(maxTextWidth, textWidth);
|
2009-10-28 12:58:13 +00:00
|
|
|
switch (alignment) {
|
2010-01-31 21:54:43 +00:00
|
|
|
case SCI_TEXT16_ALIGNMENT_RIGHT:
|
2009-10-28 12:58:13 +00:00
|
|
|
offset = rect.width() - textWidth;
|
|
|
|
break;
|
2010-01-31 21:54:43 +00:00
|
|
|
case SCI_TEXT16_ALIGNMENT_CENTER:
|
2009-10-28 12:58:13 +00:00
|
|
|
offset = (rect.width() - textWidth) / 2;
|
|
|
|
break;
|
2010-01-31 21:54:43 +00:00
|
|
|
case SCI_TEXT16_ALIGNMENT_LEFT:
|
2009-10-28 12:58:13 +00:00
|
|
|
offset = 0;
|
|
|
|
break;
|
|
|
|
|
2010-04-19 20:43:17 +00:00
|
|
|
default:
|
2009-10-28 12:58:13 +00:00
|
|
|
warning("Invalid alignment %d used in TextBox()", alignment);
|
|
|
|
}
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->moveTo(rect.left + offset, rect.top + hline);
|
2009-10-28 12:58:13 +00:00
|
|
|
|
2011-01-09 00:32:26 +00:00
|
|
|
if (show) {
|
2014-11-01 23:36:29 +01:00
|
|
|
Show(curTextLine, 0, charCount, fontId, previousPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
} else {
|
2014-11-01 23:36:29 +01:00
|
|
|
Draw(curTextLine, 0, charCount, fontId, previousPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hline += textHeight;
|
2014-11-01 23:36:29 +01:00
|
|
|
curTextLine = curTextPos;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
2010-07-30 16:55:36 +00:00
|
|
|
SetFont(previousFontId);
|
|
|
|
_ports->penColor(previousPenColor);
|
2010-04-20 16:46:26 +00:00
|
|
|
|
|
|
|
if (doubleByteMode) {
|
2010-06-29 14:55:32 +00:00
|
|
|
// Kanji is written by pc98 rom to screen directly. Because of
|
2011-05-25 10:31:37 -04:00
|
|
|
// GetLongest() behavior (not cutting off the last char, that causes a
|
2010-06-29 14:55:32 +00:00
|
|
|
// new line), results in the script thinking that the text would need
|
|
|
|
// less space. The coordinate adjustment in fontsjis.cpp handles the
|
|
|
|
// incorrect centering because of that and this code actually shows all
|
|
|
|
// of the chars - if we don't do this, the scripts will only show most
|
|
|
|
// of the chars, but the last few pixels won't get shown most of the
|
|
|
|
// time.
|
2010-04-20 16:46:26 +00:00
|
|
|
Common::Rect kanjiRect = rect;
|
|
|
|
_ports->offsetRect(kanjiRect);
|
|
|
|
kanjiRect.left &= 0xFFC;
|
|
|
|
kanjiRect.right = kanjiRect.left + maxTextWidth;
|
|
|
|
kanjiRect.bottom = kanjiRect.top + hline;
|
|
|
|
kanjiRect.left *= 2; kanjiRect.right *= 2;
|
|
|
|
kanjiRect.top *= 2; kanjiRect.bottom *= 2;
|
|
|
|
_screen->copyDisplayRectToScreen(kanjiRect);
|
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2011-01-08 23:16:44 +00:00
|
|
|
void GfxText16::DrawString(const char *text) {
|
2010-07-30 16:55:36 +00:00
|
|
|
GuiResourceId previousFontId = GetFontId();
|
|
|
|
int16 previousPenColor = _ports->_curPort->penClr;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
2010-07-30 16:55:36 +00:00
|
|
|
Draw(text, 0, strlen(text), previousFontId, previousPenColor);
|
|
|
|
SetFont(previousFontId);
|
|
|
|
_ports->penColor(previousPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:23:53 +00:00
|
|
|
// we need to have a separate status drawing code
|
|
|
|
// In KQ4 the IV char is actually 0xA, which would otherwise get considered as linebreak and not printed
|
2011-01-08 23:16:44 +00:00
|
|
|
void GfxText16::DrawStatus(const char *text) {
|
2010-09-26 18:23:53 +00:00
|
|
|
uint16 curChar, charWidth;
|
|
|
|
uint16 textLen = strlen(text);
|
|
|
|
Common::Rect rect;
|
|
|
|
|
|
|
|
GetFont();
|
|
|
|
if (!_font)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rect.top = _ports->_curPort->curTop;
|
|
|
|
rect.bottom = rect.top + _ports->_curPort->fontHeight;
|
|
|
|
while (textLen--) {
|
|
|
|
curChar = (*(const byte *)text++);
|
|
|
|
switch (curChar) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
charWidth = _font->getCharWidth(curChar);
|
|
|
|
_font->draw(curChar, _ports->_curPort->top + _ports->_curPort->curTop, _ports->_curPort->left + _ports->_curPort->curLeft, _ports->_curPort->penClr, _ports->_curPort->greyedOutput);
|
|
|
|
_ports->_curPort->curLeft += charWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-29 14:55:32 +00:00
|
|
|
// Sierra did this in their PC98 interpreter only, they identify a text as being
|
|
|
|
// sjis and then switch to font 900
|
2010-04-20 16:46:26 +00:00
|
|
|
bool GfxText16::SwitchToFont900OnSjis(const char *text) {
|
2010-04-19 20:15:31 +00:00
|
|
|
byte firstChar = (*(const byte *)text++);
|
2010-04-20 16:46:26 +00:00
|
|
|
if (((firstChar >= 0x81) && (firstChar <= 0x9F)) || ((firstChar >= 0xE0) && (firstChar <= 0xEF))) {
|
2010-04-19 20:15:31 +00:00
|
|
|
SetFont(900);
|
2010-04-20 16:46:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-04-19 20:15:31 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 10:52:17 +00:00
|
|
|
reg_t GfxText16::allocAndFillReferenceRectArray() {
|
|
|
|
uint rectCount = _codeRefRects.size();
|
|
|
|
if (rectCount) {
|
|
|
|
reg_t rectArray;
|
|
|
|
byte *rectArrayPtr = g_sci->getEngineState()->_segMan->allocDynmem(4 * 2 * (rectCount + 1), "text code reference rects", &rectArray);
|
|
|
|
GfxCoordAdjuster *coordAdjuster = g_sci->_gfxCoordAdjuster;
|
|
|
|
for (uint curRect = 0; curRect < rectCount; curRect++) {
|
|
|
|
coordAdjuster->kernelLocalToGlobal(_codeRefRects[curRect].left, _codeRefRects[curRect].top);
|
|
|
|
coordAdjuster->kernelLocalToGlobal(_codeRefRects[curRect].right, _codeRefRects[curRect].bottom);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 0, _codeRefRects[curRect].left);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 2, _codeRefRects[curRect].top);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 4, _codeRefRects[curRect].right);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 6, _codeRefRects[curRect].bottom);
|
|
|
|
rectArrayPtr += 8;
|
|
|
|
}
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 0, 0x7777);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 2, 0x7777);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 4, 0x7777);
|
|
|
|
WRITE_LE_UINT16(rectArrayPtr + 6, 0x7777);
|
|
|
|
return rectArray;
|
|
|
|
}
|
|
|
|
return NULL_REG;
|
|
|
|
}
|
|
|
|
|
2010-06-15 13:01:07 +00:00
|
|
|
void GfxText16::kernelTextSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight) {
|
2010-06-24 11:52:08 +00:00
|
|
|
Common::Rect rect(0, 0, 0, 0);
|
2010-06-15 13:01:07 +00:00
|
|
|
Size(rect, text, font, maxWidth);
|
|
|
|
*textWidth = rect.width();
|
|
|
|
*textHeight = rect.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used SCI1+ for text codes
|
|
|
|
void GfxText16::kernelTextFonts(int argc, reg_t *argv) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
delete _codeFonts;
|
|
|
|
_codeFontsCount = argc;
|
|
|
|
_codeFonts = new GuiResourceId[argc];
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
_codeFonts[i] = (GuiResourceId)argv[i].toUint16();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used SCI1+ for text codes
|
|
|
|
void GfxText16::kernelTextColors(int argc, reg_t *argv) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
delete _codeColors;
|
|
|
|
_codeColorsCount = argc;
|
|
|
|
_codeColors = new uint16[argc];
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
_codeColors[i] = argv[i].toUint16();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-26 19:33:07 +00:00
|
|
|
} // End of namespace Sci
|