2003-08-22 05:53:29 +00:00
|
|
|
// Residual - Virtual machine to run LucasArts' 3D adventure games
|
2005-01-01 10:23:18 +00:00
|
|
|
// Copyright (C) 2003-2005 The ScummVM-Residual Team (www.scummvm.org)
|
2003-08-22 05:53:29 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2003-08-24 17:56:03 +00:00
|
|
|
#include "stdafx.h"
|
2003-08-22 05:53:29 +00:00
|
|
|
#include "textobject.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "localize.h"
|
2005-01-12 18:06:43 +00:00
|
|
|
#include "driver.h"
|
2003-08-22 05:53:29 +00:00
|
|
|
|
2005-03-19 21:48:23 +00:00
|
|
|
std::string parseMsgText(const char *msg, char *msgId);
|
|
|
|
|
2005-03-20 13:51:40 +00:00
|
|
|
TextObject::TextObject() :
|
|
|
|
_created(false), _x(0), _y(0), _width(0), _height(0), _textBitmap(NULL),
|
|
|
|
_bitmapWidth(0), _bitmapHeight(0), _textObjectHandle(NULL), _justify(0),
|
|
|
|
_font(NULL), _text(NULL) {
|
|
|
|
memset(_textID, 0, 10);
|
|
|
|
_fgColor._vals[0] = 0;
|
|
|
|
_fgColor._vals[1] = 0;
|
|
|
|
_fgColor._vals[2] = 0;
|
|
|
|
}
|
2005-03-19 21:48:23 +00:00
|
|
|
|
2005-03-20 13:51:40 +00:00
|
|
|
TextObject::~TextObject() {
|
|
|
|
destroyBitmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextObject::setDefaultsTextObjectParams() {
|
|
|
|
_x = 0;
|
|
|
|
_y = 0;
|
|
|
|
_width = 0;
|
|
|
|
_height = 0;
|
|
|
|
_font = NULL;
|
|
|
|
_fgColor._vals[0] = 0;
|
|
|
|
_fgColor._vals[1] = 0;
|
|
|
|
_fgColor._vals[2] = 0;
|
|
|
|
_justify = 0;
|
|
|
|
_text = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextObject::createBitmap() {
|
|
|
|
if (_created)
|
|
|
|
destroyBitmap();
|
|
|
|
|
|
|
|
strcpy(_textID, _text);
|
2005-03-19 21:48:23 +00:00
|
|
|
char msgId[32];
|
|
|
|
std::string msg = parseMsgText(_textID, msgId);
|
|
|
|
|
2005-03-20 13:51:40 +00:00
|
|
|
_bitmapWidth = 0;
|
|
|
|
_bitmapHeight = 0;
|
2005-03-19 21:48:23 +00:00
|
|
|
|
|
|
|
for (int i = 0; msg[i] != '\0'; ++i) {
|
2005-03-20 13:51:40 +00:00
|
|
|
_bitmapWidth += _font->getCharLogicalWidth(msg[i]) + _font->getCharStartingCol(msg[i]);
|
2005-03-19 21:48:23 +00:00
|
|
|
|
2005-03-20 13:51:40 +00:00
|
|
|
int h = _font->getCharHeight(msg[i]) + _font->getCharStartingLine(msg[i]);
|
2005-03-19 21:48:23 +00:00
|
|
|
if (h > _bitmapHeight)
|
|
|
|
_bitmapHeight = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
//printf("creating textobject: %s\nheight: %d\nwidth: %d\n", msg.c_str(), _bitmapHeight, _bitmapWidth);
|
|
|
|
|
|
|
|
_textBitmap = new uint8[_bitmapHeight * _bitmapWidth];
|
|
|
|
memset(_textBitmap, 0, _bitmapHeight * _bitmapWidth);
|
|
|
|
|
|
|
|
// Fill bitmap
|
|
|
|
int offset = 0;
|
|
|
|
for (int line = 0; line < _bitmapHeight; ++line) {
|
|
|
|
for (int c = 0; msg[c] != '\0'; ++c) {
|
2005-03-20 13:51:40 +00:00
|
|
|
uint32 charWidth = _font->getCharWidth(msg[c]);
|
|
|
|
uint32 charLogicalWidth = _font->getCharLogicalWidth(msg[c]);
|
|
|
|
uint8 startingCol = _font->getCharStartingCol(msg[c]);
|
|
|
|
uint8 startingLine = _font->getCharStartingLine(msg[c]);
|
2005-03-19 21:48:23 +00:00
|
|
|
|
2005-03-20 13:51:40 +00:00
|
|
|
if (startingLine < line + 1 && _font->getCharHeight(msg[c]) + startingLine > line) {
|
2005-03-19 21:48:23 +00:00
|
|
|
memcpy(_textBitmap + offset + startingCol,
|
2005-03-20 13:51:40 +00:00
|
|
|
_font->getCharData(msg[c]) + charWidth * (line - startingLine), charWidth);
|
2005-03-19 21:48:23 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 11:49:21 +00:00
|
|
|
offset += charLogicalWidth + startingCol;
|
2005-03-19 21:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-20 14:03:08 +00:00
|
|
|
_textObjectHandle = g_driver->createTextBitmap(_textBitmap, _bitmapWidth, _bitmapHeight, _fgColor);
|
2005-03-19 21:48:23 +00:00
|
|
|
|
2005-03-20 14:03:08 +00:00
|
|
|
delete[] _textBitmap;
|
2005-03-20 13:51:40 +00:00
|
|
|
_created = true;
|
2004-12-31 21:35:04 +00:00
|
|
|
g_engine->registerTextObject(this);
|
2003-08-22 05:53:29 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 13:51:40 +00:00
|
|
|
void TextObject::destroyBitmap() {
|
|
|
|
if (_textObjectHandle) {
|
|
|
|
g_driver->destroyTextBitmap(_textObjectHandle);
|
|
|
|
delete _textObjectHandle;
|
|
|
|
_textObjectHandle = NULL;
|
|
|
|
}
|
|
|
|
_created = false;
|
2005-03-19 21:48:23 +00:00
|
|
|
}
|
2005-01-02 13:34:50 +00:00
|
|
|
|
2003-08-22 05:53:29 +00:00
|
|
|
void TextObject::draw() {
|
2005-03-19 21:48:23 +00:00
|
|
|
g_driver->drawTextBitmap(_x, _y, _textObjectHandle);
|
2003-08-22 05:53:29 +00:00
|
|
|
}
|