diff options
-rw-r--r-- | engines/glk/frotz/bitmap_font.cpp | 64 | ||||
-rw-r--r-- | engines/glk/frotz/bitmap_font.h | 73 | ||||
-rw-r--r-- | engines/glk/frotz/screen.cpp | 36 | ||||
-rw-r--r-- | engines/glk/frotz/screen.h | 41 | ||||
-rw-r--r-- | engines/glk/module.mk | 1 |
5 files changed, 139 insertions, 76 deletions
diff --git a/engines/glk/frotz/bitmap_font.cpp b/engines/glk/frotz/bitmap_font.cpp new file mode 100644 index 0000000000..cc43c79b25 --- /dev/null +++ b/engines/glk/frotz/bitmap_font.cpp @@ -0,0 +1,64 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "glk/frotz/bitmap_font.h" + +namespace Glk { +namespace Frotz { + +/*--------------------------------------------------------------------------*/ + +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 % srcWidth) == 0); + assert((src.h % srcHeight) == 0); + + // Set up a characters array + _chars.resize((src.w / srcWidth) * (src.h / srcHeight)); + + // 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 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 < c.w; ++xCtr, ++srcP) { + if (!*srcP) + dst->hLine(x + xCtr, y + yCtr, x + xCtr, color); + } + } +} + +} // End of namespace Frotz +} // End of namespace Glk diff --git a/engines/glk/frotz/bitmap_font.h b/engines/glk/frotz/bitmap_font.h new file mode 100644 index 0000000000..96c412784d --- /dev/null +++ b/engines/glk/frotz/bitmap_font.h @@ -0,0 +1,73 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GLK_FROTZ_BITMAP_FONT +#define GLK_FROTZ_BITMAP_FONT + +#include "common/array.h" +#include "common/rect.h" +#include "graphics/font.h" +#include "graphics/managed_surface.h" + +namespace Glk { +namespace Frotz { + +/** + * Implements a fixed width font stored as a grid on a passed surface + */ +class BitmapFont : public Graphics::Font { +private: + Common::Array<Graphics::ManagedSurface> _chars; + size_t _startingChar; + Common::Point _size; +public: + /** + * Constructor + */ + 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 _size.y; } + + /** + * Get the maximum character width + */ + virtual int getMaxCharWidth() const override { return _size.x; } + + /** + * Get the width of the given character + */ + virtual int getCharWidth(uint32 chr) const override { return _size.x; } + + /** + * Draw a character + */ + virtual void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override; +}; + +} // End of namespace Frotz +} // End of namespace Glk + +#endif diff --git a/engines/glk/frotz/screen.cpp b/engines/glk/frotz/screen.cpp index 60fb6d9506..faf85d9d39 100644 --- a/engines/glk/frotz/screen.cpp +++ b/engines/glk/frotz/screen.cpp @@ -21,6 +21,7 @@ */ #include "glk/frotz/screen.h" +#include "glk/frotz/bitmap_font.h" #include "glk/frotz/frotz.h" #include "glk/conf.h" #include "common/file.h" @@ -72,40 +73,5 @@ void FrotzScreen::loadFonts(Common::Archive *archive) { f.close(); } -/*--------------------------------------------------------------------------*/ - -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 % srcWidth) == 0); - assert((src.h % srcHeight) == 0); - - // Set up a characters array - _chars.resize((src.w / srcWidth) * (src.h / srcHeight)); - - // 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 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 < c.w; ++xCtr, ++srcP) { - if (!*srcP) - dst->hLine(x + xCtr, y + yCtr, x + xCtr, color); - } - } -} - } // End of namespace Frotz } // End of namespace Glk diff --git a/engines/glk/frotz/screen.h b/engines/glk/frotz/screen.h index 223ef3b124..ef616a1eb1 100644 --- a/engines/glk/frotz/screen.h +++ b/engines/glk/frotz/screen.h @@ -23,11 +23,6 @@ #ifndef GLK_FROTZ_FONTS #define GLK_FROTZ_FONTS -#include "graphics/font.h" -#include "graphics/surface.h" -#include "common/archive.h" -#include "common/array.h" -#include "common/rect.h" #include "glk/screen.h" namespace Glk { @@ -49,42 +44,6 @@ public: FrotzScreen(); }; -/** - * Implements a fixed width font stored as a grid on a passed surface - */ -class BitmapFont : public Graphics::Font { -private: - Common::Array<Graphics::ManagedSurface> _chars; - size_t _startingChar; - Common::Point _size; -public: - /** - * Constructor - */ - 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 _size.y; } - - /** - * Get the maximum character width - */ - virtual int getMaxCharWidth() const override { return _size.x; } - - /** - * Get the width of the given character - */ - virtual int getCharWidth(uint32 chr) const override { return _size.x; } - - /** - * Draw a character - */ - virtual void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override; -}; - } // End of namespace Frotz } // End of namespace Glk diff --git a/engines/glk/module.mk b/engines/glk/module.mk index 38f19c5a8a..a51fb7e413 100644 --- a/engines/glk/module.mk +++ b/engines/glk/module.mk @@ -31,6 +31,7 @@ MODULE_OBJS := \ alan2/parse.o \ alan2/rules.o \ alan2/saveload.o \ + frotz/bitmap_font.o \ frotz/config.o \ frotz/detection.o \ frotz/frotz.o \ |