aboutsummaryrefslogtreecommitdiff
path: root/engines/neverhood
diff options
context:
space:
mode:
authorjohndoe1232012-09-19 11:03:28 +0000
committerWillem Jan Palenstijn2013-05-08 20:43:42 +0200
commit96153bfe04fff5edc8253226125b225cee6681a0 (patch)
treeebfeb324f1f83d31da1ecf60c8452e994f404202 /engines/neverhood
parentd1d1596fd136783a7bc4db9264ba1627b8511355 (diff)
downloadscummvm-rg350-96153bfe04fff5edc8253226125b225cee6681a0.tar.gz
scummvm-rg350-96153bfe04fff5edc8253226125b225cee6681a0.tar.bz2
scummvm-rg350-96153bfe04fff5edc8253226125b225cee6681a0.zip
NEVERHOOD: Implement TextSurface, used in the save/load menus
Diffstat (limited to 'engines/neverhood')
-rw-r--r--engines/neverhood/graphics.cpp34
-rw-r--r--engines/neverhood/graphics.h16
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);