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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-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-01-31 21:54:43 +00:00
|
|
|
#include "sci/graphics/text16.h"
|
2009-10-26 19:33:07 +00:00
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
GfxText16::GfxText16(ResourceManager *resMan, GfxCache *cache, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen)
|
2010-01-31 17:45:22 +00:00
|
|
|
: _resMan(resMan), _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::CodeSetFonts(int argc, reg_t *argv) {
|
2009-10-28 12:58:13 +00:00
|
|
|
int i;
|
|
|
|
|
2010-01-03 19:37:43 +00:00
|
|
|
delete _codeFonts;
|
2009-10-28 12:58:13 +00:00
|
|
|
_codeFontsCount = argc;
|
|
|
|
_codeFonts = new GuiResourceId[argc];
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
_codeFonts[i] = (GuiResourceId)argv[i].toUint16();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::CodeSetColors(int argc, reg_t *argv) {
|
2009-10-28 12:58:13 +00:00
|
|
|
int i;
|
|
|
|
|
2010-01-03 19:37:43 +00:00
|
|
|
delete _codeColors;
|
2009-10-28 12:58:13 +00:00
|
|
|
_codeColorsCount = argc;
|
|
|
|
_codeColors = new uint16[argc];
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
_codeColors[i] = argv[i].toUint16();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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-01-31 21:54:43 +00:00
|
|
|
int16 GfxText16::CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor) {
|
2009-10-28 12:58:13 +00:00
|
|
|
const char *textCode = text;
|
|
|
|
int16 textCodeSize = 0;
|
|
|
|
char curCode;
|
|
|
|
unsigned char curCodeParm;
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
if (isdigit(curCodeParm)) {
|
|
|
|
curCodeParm -= '0';
|
|
|
|
} else {
|
|
|
|
curCodeParm = 0;
|
|
|
|
}
|
|
|
|
switch (curCode) {
|
|
|
|
case 'c': // set text color
|
|
|
|
if (curCodeParm == 0) {
|
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;
|
|
|
|
case 'f':
|
|
|
|
if (curCodeParm == 0) {
|
|
|
|
SetFont(orgFontId);
|
|
|
|
} else {
|
|
|
|
if (curCodeParm < _codeFontsCount) {
|
|
|
|
SetFont(_codeFonts[curCodeParm]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return textCodeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return max # of chars to fit maxwidth with full words
|
2010-01-31 21:54:43 +00:00
|
|
|
int16 GfxText16::GetLongest(const char *text, int16 maxWidth, GuiResourceId orgFontId) {
|
2010-04-16 18:23:50 +00:00
|
|
|
uint16 curChar;
|
2009-10-28 12:58:13 +00:00
|
|
|
int16 maxChars = 0, curCharCount = 0;
|
|
|
|
uint16 width = 0;
|
|
|
|
GuiResourceId oldFontId = GetFontId();
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 oldPenColor = _ports->_curPort->penClr;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
GetFont();
|
|
|
|
if (!_font)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (width <= maxWidth) {
|
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
|
|
|
curCharCount++;
|
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
switch (curChar) {
|
|
|
|
case 0x7C:
|
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1) {
|
|
|
|
curCharCount++;
|
|
|
|
curCharCount += CodeProcessing(text, orgFontId, oldPenColor);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-19 11:59:46 +00:00
|
|
|
// We need to add 0xD, 0xA and 0xD 0xA to curCharCount and then exit
|
2010-04-19 15:30:21 +00:00
|
|
|
// which means, we split text like
|
|
|
|
// 'Mature, experienced software analyst available.' 0xD 0xA
|
|
|
|
// 'Bug installation a proven speciality. "No version too clean."' (normal game text, this is from lsl2)
|
|
|
|
// and 0xA '-------' 0xA (which is the official sierra subtitle separator)
|
|
|
|
// 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
|
2010-04-19 09:46:27 +00:00
|
|
|
if ((*(const unsigned char *)text) == 0xA)
|
2010-04-18 12:09:22 +00:00
|
|
|
curCharCount++;
|
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:
|
|
|
|
curCharCount++;
|
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:
|
|
|
|
SetFont(oldFontId);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->penColor(oldPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
return curCharCount;
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
maxChars = curCharCount + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
width += _font->getCharWidth(curChar);
|
|
|
|
curCharCount++;
|
|
|
|
}
|
2010-04-16 13:27:30 +00:00
|
|
|
if (maxChars == 0) {
|
2010-04-16 18:23:50 +00:00
|
|
|
// Text w/o space, supposingly kanji - we don't adjust back to last char here strangely. If we do, we don't
|
|
|
|
// get the same text cutting like in sierra sci
|
|
|
|
maxChars = curCharCount;
|
2010-04-16 13:27:30 +00:00
|
|
|
}
|
2009-10-28 12:58:13 +00:00
|
|
|
SetFont(oldFontId);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->penColor(oldPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
return maxChars;
|
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::Width(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight) {
|
2010-04-16 18:23:50 +00:00
|
|
|
uint16 curChar;
|
2009-10-28 12:58:13 +00:00
|
|
|
GuiResourceId oldFontId = GetFontId();
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 oldPenColor = _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-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) {
|
|
|
|
len -= CodeProcessing(text, orgFontId, 0);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetFont(oldFontId);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->penColor(oldPenColor);
|
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) {
|
2009-10-28 12:58:13 +00:00
|
|
|
Width(str, 0, (int16)strlen(str), orgFontId, textWidth, textHeight);
|
|
|
|
}
|
|
|
|
|
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) {
|
2009-10-28 12:58:13 +00:00
|
|
|
GuiResourceId oldFontId = GetFontId();
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 oldPenColor = _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-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-04-19 20:15:31 +00:00
|
|
|
StringWidth(text, oldFontId, 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);
|
2010-04-19 20:15:31 +00:00
|
|
|
const char *curPos = text;
|
|
|
|
while (*curPos) {
|
|
|
|
charCount = GetLongest(curPos, rect.right, oldFontId);
|
2009-10-28 12:58:13 +00:00
|
|
|
if (charCount == 0)
|
|
|
|
break;
|
2010-04-19 20:15:31 +00:00
|
|
|
Width(curPos, 0, charCount, oldFontId, textWidth, textHeight);
|
2009-10-28 12:58:13 +00:00
|
|
|
maxTextWidth = MAX(textWidth, maxTextWidth);
|
|
|
|
totalHeight += textHeight;
|
2010-04-19 20:15:31 +00:00
|
|
|
curPos += charCount;
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
rect.bottom = totalHeight;
|
|
|
|
rect.right = maxWidth ? maxWidth : MIN(rect.right, maxTextWidth);
|
|
|
|
}
|
|
|
|
SetFont(oldFontId);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->penColor(oldPenColor);
|
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:
|
|
|
|
break;
|
|
|
|
case 0x7C:
|
|
|
|
if (getSciVersion() >= SCI_VERSION_1_1) {
|
|
|
|
len -= CodeProcessing(text, orgFontId, orgPenColor);
|
|
|
|
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.
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::Box(const char *text, int16 bshow, const Common::Rect &rect, TextAlignment alignment, GuiResourceId fontId) {
|
2009-12-08 20:44:57 +00:00
|
|
|
int16 textWidth, textHeight, charCount;
|
|
|
|
int16 offset = 0;
|
2009-10-28 12:58:13 +00:00
|
|
|
int16 hline = 0;
|
|
|
|
GuiResourceId orgFontId = GetFontId();
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 orgPenColor = _ports->_curPort->penClr;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
if (fontId != -1)
|
|
|
|
SetFont(fontId);
|
|
|
|
|
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
|
|
|
while (*text) {
|
|
|
|
charCount = GetLongest(text, rect.width(), orgFontId);
|
|
|
|
if (charCount == 0)
|
|
|
|
break;
|
|
|
|
Width(text, 0, charCount, orgFontId, textWidth, textHeight);
|
|
|
|
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
|
|
|
|
|
|
|
if (bshow) {
|
|
|
|
Show(text, 0, charCount, orgFontId, orgPenColor);
|
|
|
|
} else {
|
|
|
|
Draw(text, 0, charCount, orgFontId, orgPenColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
hline += textHeight;
|
|
|
|
text += charCount;
|
|
|
|
}
|
|
|
|
SetFont(orgFontId);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->penColor(orgPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-01-31 21:54:43 +00:00
|
|
|
void GfxText16::Draw_String(const char *text) {
|
2009-10-28 12:58:13 +00:00
|
|
|
GuiResourceId orgFontId = GetFontId();
|
2010-01-31 12:35:15 +00:00
|
|
|
int16 orgPenColor = _ports->_curPort->penClr;
|
2009-10-28 12:58:13 +00:00
|
|
|
|
|
|
|
Draw(text, 0, strlen(text), orgFontId, orgPenColor);
|
|
|
|
SetFont(orgFontId);
|
2010-01-31 12:35:15 +00:00
|
|
|
_ports->penColor(orgPenColor);
|
2009-10-28 12:58:13 +00:00
|
|
|
}
|
|
|
|
|
2010-04-19 20:15:31 +00:00
|
|
|
// Sierra did this in their PC98 interpreter only, they identify a text as being sjis and then switch to font 900
|
|
|
|
void GfxText16::SwitchToFont900OnSjis(const char *text) {
|
|
|
|
byte firstChar = (*(const byte *)text++);
|
|
|
|
if (((firstChar >= 0x81) && (firstChar <= 0x9F)) || ((firstChar >= 0xE0) && (firstChar <= 0xEF)))
|
|
|
|
SetFont(900);
|
|
|
|
}
|
|
|
|
|
2009-10-26 19:33:07 +00:00
|
|
|
} // End of namespace Sci
|