rest of LAF support patch and my addons for driver drawing
This commit is contained in:
parent
5a8b560d26
commit
b04615fac3
13 changed files with 334 additions and 55 deletions
|
@ -21,21 +21,65 @@
|
|||
#include "localize.h"
|
||||
#include "driver.h"
|
||||
|
||||
TextObject::TextObject(const char *text, const int x, const int y, const Color& fgColor) :
|
||||
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) :
|
||||
_fgColor(fgColor), _x(x), _y(y) {
|
||||
|
||||
strcpy(_textID, text);
|
||||
char msgId[32];
|
||||
std::string msg = parseMsgText(_textID, msgId);
|
||||
|
||||
// Calculate bitmap dimensions
|
||||
_bitmapHeight = _bitmapWidth = 0;
|
||||
|
||||
for (int i = 0; msg[i] != '\0'; ++i) {
|
||||
_bitmapWidth += font->getCharWidth(msg[i]) + font->getCharStartingCol(msg[i]);
|
||||
|
||||
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]);
|
||||
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);
|
||||
}
|
||||
|
||||
offset += charWidth + startingCol;
|
||||
}
|
||||
}
|
||||
|
||||
_textObjectHandle = g_driver->prepareToTextBitmap(_textBitmap, _bitmapWidth, _bitmapHeight, _fgColor);
|
||||
|
||||
g_engine->registerTextObject(this);
|
||||
}
|
||||
|
||||
void TextObject::setX(int x) {_x = x; }
|
||||
void TextObject::setY(int y) {_y = y; }
|
||||
void TextObject::setColor(Color *newcolor) { _fgColor = newcolor; }
|
||||
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;
|
||||
|
||||
std::string parseMsgText(char *msg, char *msgId);
|
||||
delete _textObjectHandle;
|
||||
}
|
||||
|
||||
void TextObject::draw() {
|
||||
char msgId[32];
|
||||
|
||||
std::string msg = parseMsgText(_textID, msgId);
|
||||
g_driver->drawEmergString(_x, _y, msg.c_str(), _fgColor);
|
||||
g_driver->drawTextBitmap(_x, _y, _textObjectHandle);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue