diff options
author | Paul Gilbert | 2018-11-25 17:14:04 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | 6080a1d09105c8c743d9e739df91109c809fcef1 (patch) | |
tree | 31cca1bc8abc279c790ee3d027f4fa63e75d06de /engines/glk/frotz | |
parent | 9fa7e9be8180614b5f7c94440a8243f775e56aef (diff) | |
download | scummvm-rg350-6080a1d09105c8c743d9e739df91109c809fcef1.tar.gz scummvm-rg350-6080a1d09105c8c743d9e739df91109c809fcef1.tar.bz2 scummvm-rg350-6080a1d09105c8c743d9e739df91109c809fcef1.zip |
GLK: FROTZ: Draw character graphic chars at the same size as the fixed width font
Diffstat (limited to 'engines/glk/frotz')
-rw-r--r-- | engines/glk/frotz/screen.cpp | 41 | ||||
-rw-r--r-- | engines/glk/frotz/screen.h | 21 |
2 files changed, 29 insertions, 33 deletions
diff --git a/engines/glk/frotz/screen.cpp b/engines/glk/frotz/screen.cpp index edd62eb7da..08bf8c9ad0 100644 --- a/engines/glk/frotz/screen.cpp +++ b/engines/glk/frotz/screen.cpp @@ -40,37 +40,40 @@ void FrotzScreen::loadFonts(Common::Archive *archive) { if (!f.open("infocom_graphics.bmp", *archive)) error("Could not load font"); + Common::Point fontSize(_fonts[0]->getMaxCharWidth(), _fonts[0]->getFontHeight()); decoder.loadStream(f); - _fonts.push_back(new Frotz::BitmapFont(*decoder.getSurface())); + _fonts.push_back(new Frotz::BitmapFont(*decoder.getSurface(), fontSize)); } /*--------------------------------------------------------------------------*/ -BitmapFont::BitmapFont(const Graphics::Surface &src, uint charWidth, - uint charHeight, unsigned char startingChar) : _startingChar(startingChar) { +BitmapFont::BitmapFont(const Graphics::Surface &src, const Common::Point &size, + uint srcWidth, uint srcHeight, unsigned char startingChar) : + _startingChar(startingChar), _size(size) { assert(src.format.bytesPerPixel == 1); - assert((src.w % charWidth) == 0); - assert((src.h % charHeight) == 0); - _surface.copyFrom(src); + assert((src.w % srcWidth) == 0); + assert((src.h % srcHeight) == 0); - Common::Rect r(charWidth, charHeight); - for (uint y = 0; y < src.h; y += charHeight) { - r.moveTo(0, y); - for (uint x = 0; x < src.w; x += charWidth, r.translate(charWidth, 0)) - _chars.push_back(r); - } -} + // Set up a characters array + _chars.resize((src.w / srcWidth) * (src.h / srcHeight)); -BitmapFont::~BitmapFont() { - _surface.free(); + // Iterate through loading characters + Common::Rect r(srcWidth, srcHeight); + int charsPerRow = src.w / srcWidth; + for (uint idx = 0; idx < _chars.size(); ++idx) { + r.moveTo((idx % charsPerRow) * srcWidth, (idx / charsPerRow) * srcHeight); + + _chars[idx].create(size.x, size.y, src.format); + _chars[idx].transBlitFrom(src, r, Common::Rect(0, 0, size.x, size.y)); + } } void BitmapFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const { - const Common::Rect &r = _chars[chr - _startingChar]; - for (int yCtr = 0; yCtr < r.height(); ++yCtr) { - const byte *srcP = (const byte *)_surface.getBasePtr(r.left, r.top + yCtr); + const Graphics::ManagedSurface &c = _chars[chr - _startingChar]; + for (int yCtr = 0; yCtr < c.h; ++yCtr) { + const byte *srcP = (const byte *)c.getBasePtr(0, yCtr); - for (int xCtr = 0; xCtr < r.width(); ++xCtr, ++srcP) { + for (int xCtr = 0; xCtr < c.w; ++xCtr, ++srcP) { if (!*srcP) dst->hLine(x + xCtr, y + yCtr, x + xCtr, color); } diff --git a/engines/glk/frotz/screen.h b/engines/glk/frotz/screen.h index 568c3c73bf..223ef3b124 100644 --- a/engines/glk/frotz/screen.h +++ b/engines/glk/frotz/screen.h @@ -54,37 +54,30 @@ public: */ class BitmapFont : public Graphics::Font { private: - Graphics::Surface _surface; - Common::Array<Common::Rect> _chars; + Common::Array<Graphics::ManagedSurface> _chars; size_t _startingChar; + Common::Point _size; public: /** * Constructor */ - BitmapFont(const Graphics::Surface &src, uint charWidth = 8, uint charHeight = 8, - unsigned char startingChar = ' '); - - /** - * Destructor - */ - ~BitmapFont(); + BitmapFont(const Graphics::Surface &src, const Common::Point &size, + uint srcWidth = 8, uint srcHeight = 8, unsigned char startingChar = ' '); /** * Get the font height */ - virtual int getFontHeight() const override { return _chars[0].height(); } + virtual int getFontHeight() const override { return _size.y; } /** * Get the maximum character width */ - virtual int getMaxCharWidth() const override { return _chars[0].width(); } + virtual int getMaxCharWidth() const override { return _size.x; } /** * Get the width of the given character */ - virtual int getCharWidth(uint32 chr) const override { - return _chars[chr - _startingChar].width(); - } + virtual int getCharWidth(uint32 chr) const override { return _size.x; } /** * Draw a character |