diff options
Diffstat (limited to 'engines/made/resource.cpp')
-rw-r--r-- | engines/made/resource.cpp | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/engines/made/resource.cpp b/engines/made/resource.cpp index f86c6ce371..7151f2424a 100644 --- a/engines/made/resource.cpp +++ b/engines/made/resource.cpp @@ -205,33 +205,69 @@ const char *MenuResource::getString(uint index) const { return NULL; } -/* XmidiResource */ +/* FontResource */ -XmidiResource::XmidiResource() : _data(NULL), _size(0) { +FontResource::FontResource() : _data(NULL), _size(0) { } -XmidiResource::~XmidiResource() { +FontResource::~FontResource() { if (_data) delete[] _data; } -void XmidiResource::load(byte *source, int size) { +void FontResource::load(byte *source, int size) { _data = new byte[size]; _size = size; memcpy(_data, source, size); } -/* FontResource */ +int FontResource::getHeight() const { + return _data[0]; +} -FontResource::FontResource() : _data(NULL), _size(0) { +int FontResource::getCharWidth(uint c) const { + byte *charData = getCharData(c); + if (charData) + return charData[0]; + else + return 0; } -FontResource::~FontResource() { +byte *FontResource::getChar(uint c) const { + byte *charData = getCharData(c); + if (charData) + return charData + 1; + else + return NULL; +} + +int FontResource::getTextWidth(const char *text) { + int width = 0; + if (text) { + int len = strlen(text); + for (int pos = 0; pos < len; pos++) + width += getCharWidth(text[pos]); + } + return width; +} + +byte *FontResource::getCharData(uint c) const { + if (c < 28 || c > 255) + return NULL; + return _data + 1 + (c - 28) * (getHeight() + 1); +} + +/* GenericResource */ + +GenericResource::GenericResource() : _data(NULL), _size(0) { +} + +GenericResource::~GenericResource() { if (_data) delete[] _data; } -void FontResource::load(byte *source, int size) { +void GenericResource::load(byte *source, int size) { _data = new byte[size]; _size = size; memcpy(_data, source, size); @@ -301,14 +337,18 @@ MenuResource *ProjectReader::getMenu(int index) { return createResource<MenuResource>(kResMENU, index); } -XmidiResource *ProjectReader::getXmidi(int index) { - return createResource<XmidiResource>(kResXMID, index); -} - FontResource *ProjectReader::getFont(int index) { return createResource<FontResource>(kResFONT, index); } +GenericResource *ProjectReader::getXmidi(int index) { + return createResource<GenericResource>(kResXMID, index); +} + +GenericResource *ProjectReader::getMidi(int index) { + return createResource<GenericResource>(kResMIDI, index); +} + void ProjectReader::loadIndex(ResourceSlots *slots) { _fd->readUint32LE(); // skip INDX _fd->readUint32LE(); // skip index size |