From 5540ef2d67301dbce1941eab9507285dc508f5ba Mon Sep 17 00:00:00 2001 From: Benjamin Haisch Date: Fri, 25 Apr 2008 11:05:56 +0000 Subject: [PATCH] Added FontResource type svn-id: r31717 --- engines/made/resource.cpp | 66 +++++++++++++++++++++++++++------------ engines/made/resource.h | 33 ++++++++++---------- 2 files changed, 63 insertions(+), 36 deletions(-) diff --git a/engines/made/resource.cpp b/engines/made/resource.cpp index f86c6ce3713..cfab28cca56 100644 --- a/engines/made/resource.cpp +++ b/engines/made/resource.cpp @@ -205,22 +205,6 @@ const char *MenuResource::getString(uint index) const { return NULL; } -/* XmidiResource */ - -XmidiResource::XmidiResource() : _data(NULL), _size(0) { -} - -XmidiResource::~XmidiResource() { - if (_data) - delete[] _data; -} - -void XmidiResource::load(byte *source, int size) { - _data = new byte[size]; - _size = size; - memcpy(_data, source, size); -} - /* FontResource */ FontResource::FontResource() : _data(NULL), _size(0) { @@ -237,6 +221,48 @@ void FontResource::load(byte *source, int size) { memcpy(_data, source, size); } +int FontResource::getHeight() const { + return _data[0]; +} + +int FontResource::getCharWidth(char c) const { + byte *charData = getCharData(c); + if (charData) + return charData[0]; + else + return 0; +} + +byte *FontResource::getChar(char c) const { + byte *charData = getCharData(c); + if (charData) + return charData + 1; + else + return NULL; +} + +byte *FontResource::getCharData(char c) const { + if (c < 28 || c > 255) + return NULL; + return _data + 1 + (c - 28) * (getHeight() + 1); +} + +/* XmidiResource */ + +XmidiResource::XmidiResource() : _data(NULL), _size(0) { +} + +XmidiResource::~XmidiResource() { + if (_data) + delete[] _data; +} + +void XmidiResource::load(byte *source, int size) { + _data = new byte[size]; + _size = size; + memcpy(_data, source, size); +} + /* ProjectReader */ ProjectReader::ProjectReader() { @@ -301,14 +327,14 @@ MenuResource *ProjectReader::getMenu(int index) { return createResource(kResMENU, index); } -XmidiResource *ProjectReader::getXmidi(int index) { - return createResource(kResXMID, index); -} - FontResource *ProjectReader::getFont(int index) { return createResource(kResFONT, index); } +XmidiResource *ProjectReader::getXmidi(int index) { + return createResource(kResXMID, index); +} + void ProjectReader::loadIndex(ResourceSlots *slots) { _fd->readUint32LE(); // skip INDX _fd->readUint32LE(); // skip index size diff --git a/engines/made/resource.h b/engines/made/resource.h index 4e90673f097..93c57818bd9 100644 --- a/engines/made/resource.h +++ b/engines/made/resource.h @@ -45,8 +45,8 @@ enum ResourceType { kResSNDS = MKID_BE('SNDS'), kResANIM = MKID_BE('ANIM'), kResMENU = MKID_BE('MENU'), - kResXMID = MKID_BE('XMID'), - kResFONT = MKID_BE('FONT') + kResFONT = MKID_BE('FONT'), + kResXMID = MKID_BE('XMID') }; struct ResourceSlot; @@ -112,24 +112,25 @@ protected: Common::Array _strings; }; -class XmidiResource : public Resource { -public: - XmidiResource(); - ~XmidiResource(); - void load(byte *source, int size); - byte *getData() const { return _data; } - int getSize() const { return _size; } -protected: - byte *_data; - int _size; -}; - -// TODO class FontResource : public Resource { public: FontResource(); ~FontResource(); void load(byte *source, int size); + int getHeight() const; + int getCharWidth(char c) const; + byte *getChar(char c) const; +protected: + byte *_data; + int _size; + byte *getCharData(char c) const; +}; + +class XmidiResource : public Resource { +public: + XmidiResource(); + ~XmidiResource(); + void load(byte *source, int size); byte *getData() const { return _data; } int getSize() const { return _size; } protected: @@ -160,8 +161,8 @@ public: AnimationResource *getAnimation(int index); SoundResource *getSound(int index); MenuResource *getMenu(int index); - XmidiResource *getXmidi(int index); FontResource *getFont(int index); + XmidiResource *getXmidi(int index); void freeResource(Resource *resource);