From 88f3fc07603d132b12d366509e547e4367787700 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Tue, 27 Sep 2016 02:34:20 +0300 Subject: CHEWY: Implement initial sprite drawing, font loading and text drawing --- engines/chewy/resource.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'engines/chewy/resource.cpp') diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp index 13bd9d2e97..368f589cc1 100644 --- a/engines/chewy/resource.cpp +++ b/engines/chewy/resource.cpp @@ -21,9 +21,12 @@ */ #include "common/debug.h" +#include "common/rect.h" #include "common/stream.h" #include "common/substream.h" #include "common/textconsole.h" +#include "graphics/pixelformat.h" +#include "graphics/surface.h" #include "chewy/chewy.h" #include "chewy/resource.h" @@ -34,13 +37,11 @@ namespace Chewy { // ====================== // back/episode1.gep // cut/blende.rnd -// misc/*.taf, room/*.taf // misc/exit.eib // misc/inventar.iib // misc/inventar.sib // room/csp.int // room/test.rdi -// txt/*.tff // txt/*.tap // txt/diah.adh // txt/inv_st.s and txt/room_st.s @@ -323,4 +324,62 @@ Common::SeekableReadStream *VideoResource::getVideoStream(uint num) { return new Common::SeekableSubReadStream(&_stream, chunk->pos, chunk->pos + chunk->size); } +Font::Font(Common::String filename) { + const uint32 headerFont = MKTAG('T', 'F', 'F', '\0'); + Common::File stream; + + stream.open(filename); + + uint32 header = stream.readUint32BE(); + + if (header != headerFont) + error("Invalid resource - %s", filename.c_str()); + + stream.skip(4); // total memory + _count = stream.readUint16LE(); + _first = stream.readUint16LE(); + _last = stream.readUint16LE(); + _width = stream.readUint16LE(); + _height = stream.readUint16LE(); + + _fontSurface.create(_width * _count, _height, ::Graphics::PixelFormat::createFormatCLUT8()); + + byte cur; + int bitIndex = 7; + byte *p; + + cur = stream.readByte(); + + for (uint n = 0; n < _count; n++) { + for (uint y = 0; y < _height; y++) { + for (uint x = n * _width; x < n * _width + _width; x++) { + p = (byte *)_fontSurface.getBasePtr(x, y); + *p = (cur & (1 << bitIndex)) ? 0 : 0xFF; + + bitIndex--; + if (bitIndex < 0) { + bitIndex = 7; + cur = stream.readByte(); + } + } + } + } +} + +Font::~Font() { + _fontSurface.free(); +} + +::Graphics::Surface *Font::getLine(Common::String text) { + ::Graphics::Surface *line = new ::Graphics::Surface(); + line->create(text.size() * _width, _height, ::Graphics::PixelFormat::createFormatCLUT8()); + + for (uint i = 0; i < text.size(); i++) { + int c = text[i]; + line->copyRectToSurface(_fontSurface, i * _width, 0, Common::Rect((c - _first) * _width, 0, (c - _first) * _width + _width, _height)); + } + + return line; +} + } // End of namespace Chewy -- cgit v1.2.3