Skip to content

Commit

Permalink
NEVERHOOD: Implement TextSurface, used in the save/load menus
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent d1d1596 commit 96153bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
34 changes: 34 additions & 0 deletions engines/neverhood/graphics.cpp
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions engines/neverhood/graphics.h
Expand Up @@ -137,6 +137,22 @@ class FontSurface : public BaseSurface {
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);
Expand Down

0 comments on commit 96153bf

Please sign in to comment.