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);
|
|
|
|
|
|
|
|
TextObject::TextObject(const char *text, const int x, const int y, /*const*/ Font *font, const Color& fgColor) :
|
2004-12-09 23:55:43 +00:00
|
|
|
_fgColor(fgColor), _x(x), _y(y) {
|
2005-03-19 21:48:23 +00:00
|
|
|
|
2004-12-09 23:55:43 +00:00
|
|
|
strcpy(_textID, text);
|
2005-03-19 21:48:23 +00:00
|
|
|
char msgId[32];
|
|
|
|
std::string msg = parseMsgText(_textID, msgId);
|
|
|
|
|
|
|
|
// Calculate bitmap dimensions
|
|
|
|
_bitmapHeight = _bitmapWidth = 0;
|
|
|
|
|
|
|
|
for (int i = 0; msg[i] != '\0'; ++i) {
|
2005-03-20 11:49:21 +00:00
|
|
|
_bitmapWidth += font->getCharLogicalWidth(msg[i]) + font->getCharStartingCol(msg[i]);
|
2005-03-19 21:48:23 +00:00
|
|
|
|
|
|
|
int h = font->getCharHeight(msg[i]) + font->getCharStartingLine(msg[i]);
|
|
|
|
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) {
|
|
|
|
uint32 charWidth = font->getCharWidth(msg[c]);
|
2005-03-20 11:49:21 +00:00
|
|
|
uint32 charLogicalWidth = font->getCharLogicalWidth(msg[c]);
|
2005-03-19 21:48:23 +00:00
|
|
|
uint8 startingCol = font->getCharStartingCol(msg[c]);
|
|
|
|
uint8 startingLine = font->getCharStartingLine(msg[c]);
|
|
|
|
|
|
|
|
if (startingLine < line + 1 && font->getCharHeight(msg[c]) + startingLine > line) {
|
|
|
|
memcpy(_textBitmap + offset + startingCol,
|
|
|
|
font->getCharData(msg[c]) + charWidth * (line - startingLine), charWidth);
|
|
|
|
}
|
|
|
|
|
2005-03-20 11:49:21 +00:00
|
|
|
offset += charLogicalWidth + startingCol;
|
2005-03-19 21:48:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_textObjectHandle = g_driver->prepareToTextBitmap(_textBitmap, _bitmapWidth, _bitmapHeight, _fgColor);
|
|
|
|
|
2004-12-31 21:35:04 +00:00
|
|
|
g_engine->registerTextObject(this);
|
2003-08-22 05:53:29 +00:00
|
|
|
}
|
|
|
|
|
2005-03-19 21:48:23 +00:00
|
|
|
TextObject::~TextObject() {
|
|
|
|
delete[] _textBitmap;
|
|
|
|
if (_textObjectHandle->bitmapData)
|
|
|
|
delete _textObjectHandle->bitmapData;
|
|
|
|
if (_textObjectHandle->surface)
|
|
|
|
SDL_FreeSurface((SDL_Surface *)_textObjectHandle->surface);
|
|
|
|
if (_textObjectHandle->texIds)
|
|
|
|
delete _textObjectHandle->texIds;
|
2003-08-22 05:53:29 +00:00
|
|
|
|
2005-03-19 21:48:23 +00:00
|
|
|
delete _textObjectHandle;
|
|
|
|
}
|
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
|
|
|
}
|