diff options
-rw-r--r-- | engines/neverhood/graphics.cpp | 34 | ||||
-rw-r--r-- | engines/neverhood/graphics.h | 16 |
2 files changed, 50 insertions, 0 deletions
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index a58cdcb4b9..b1597f2d5e 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -168,6 +168,40 @@ void FontSurface::drawString(BaseSurface *destSurface, int16 x, int16 y, const b } } +// TextSurface + +TextSurface::TextSurface(NeverhoodEngine *vm, uint32 fileHash, uint16 numRows, uint charCount, + byte firstChar, uint16 charWidth, uint16 charHeight) + : BaseSurface(vm, 0, charWidth * charCount, charHeight * numRows), + _numRows(numRows), _firstChar(firstChar), _charWidth(charWidth), _charHeight(charHeight), + _fileHash(fileHash), _charCount(charCount) { + + SpriteResource spriteResource(_vm); + spriteResource.load2(_fileHash); + drawSpriteResourceEx(spriteResource, false, false, 0, 0); +} + +void TextSurface::drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr) { + NDrawRect sourceRect; + chr -= _firstChar; + sourceRect.x = (chr % 16) * _charWidth; + sourceRect.y = (chr / 16) * _charHeight; + sourceRect.width = _charWidth; + sourceRect.height = _charHeight; + destSurface->copyFrom(_surface, x, y, sourceRect, true); +} + +void TextSurface::drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen) { + for (; stringLen > 0; stringLen--, string++) { + drawChar(destSurface, x, y, *string); + x += _charWidth; + } +} + +int16 TextSurface::getStringWidth(const byte *string, int stringLen) { + return string ? stringLen * _charWidth : 0; +} + // Misc void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, byte **palette, byte **pixels) { diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h index 5e91bdb8c6..3b30b25338 100644 --- a/engines/neverhood/graphics.h +++ b/engines/neverhood/graphics.h @@ -137,6 +137,22 @@ protected: uint16 _charHeight; }; +class TextSurface : public BaseSurface { +public: + TextSurface(NeverhoodEngine *vm, uint32 fileHash, uint16 numRows, uint charCount, + byte firstChar, uint16 charWidth, uint16 charHeight); + void drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr); + void drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen); + int16 getStringWidth(const byte *string, int stringLen); +protected: + uint16 _numRows; + byte _firstChar; + uint16 _charWidth; + uint16 _charHeight; + uint32 _fileHash; + uint _charCount; +}; + // Misc void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, byte **palette, byte **pixels); |