diff options
author | Paul Gilbert | 2018-11-25 12:41:39 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | 3a543a1e6d35a5bcab61a8fb4257b7d567d9e278 (patch) | |
tree | 154d7a7b6c7a76c35490a3b092f0957a3d0d7397 /engines/glk | |
parent | fb7dbffd59b797ed00785a2d3762355f9dbb9f7d (diff) | |
download | scummvm-rg350-3a543a1e6d35a5bcab61a8fb4257b7d567d9e278.tar.gz scummvm-rg350-3a543a1e6d35a5bcab61a8fb4257b7d567d9e278.tar.bz2 scummvm-rg350-3a543a1e6d35a5bcab61a8fb4257b7d567d9e278.zip |
GLK: FROTZ: Add derived Screen class to add Infocom character graphics font
Diffstat (limited to 'engines/glk')
-rw-r--r-- | engines/glk/frotz/frotz.cpp | 5 | ||||
-rw-r--r-- | engines/glk/frotz/frotz.h | 5 | ||||
-rw-r--r-- | engines/glk/frotz/pics_decoder.cpp | 6 | ||||
-rw-r--r-- | engines/glk/frotz/screen.cpp | 16 | ||||
-rw-r--r-- | engines/glk/frotz/screen.h | 12 | ||||
-rw-r--r-- | engines/glk/glk.cpp | 9 | ||||
-rw-r--r-- | engines/glk/glk.h | 5 | ||||
-rw-r--r-- | engines/glk/screen.cpp | 24 | ||||
-rw-r--r-- | engines/glk/screen.h | 18 |
9 files changed, 81 insertions, 19 deletions
diff --git a/engines/glk/frotz/frotz.cpp b/engines/glk/frotz/frotz.cpp index d3b0749649..421b7785a6 100644 --- a/engines/glk/frotz/frotz.cpp +++ b/engines/glk/frotz/frotz.cpp @@ -22,6 +22,7 @@ #include "glk/frotz/frotz.h" #include "glk/frotz/frotz_types.h" +#include "glk/frotz/screen.h" #include "common/config-manager.h" namespace Glk { @@ -38,6 +39,10 @@ Frotz::~Frotz() { reset_memory(); } +Screen *Frotz::createScreen() { + return new FrotzScreen(); +} + void Frotz::runGame(Common::SeekableReadStream *gameFile) { story_fp = gameFile; initialize(); diff --git a/engines/glk/frotz/frotz.h b/engines/glk/frotz/frotz.h index 0dd8b69e89..22604e59bd 100644 --- a/engines/glk/frotz/frotz.h +++ b/engines/glk/frotz/frotz.h @@ -32,6 +32,11 @@ namespace Frotz { * Frotz interpreter for Z-code games */ class Frotz : public Processor { +protected: + /** + * Create the screen class + */ + virtual Screen *createScreen() override; public: /** * Constructor diff --git a/engines/glk/frotz/pics_decoder.cpp b/engines/glk/frotz/pics_decoder.cpp index d601874ca5..6dde910508 100644 --- a/engines/glk/frotz/pics_decoder.cpp +++ b/engines/glk/frotz/pics_decoder.cpp @@ -42,15 +42,14 @@ Common::SeekableReadStream *PictureDecoder::decode(Common::ReadStream &src, uint Common::MemoryWriteStreamDynamic out(DisposeAfterUse::NO); byte buf[512]; byte transparent; - int colour_shift; - int first_colour; + int colour_shift = 0; + int first_colour = 0; int code, prev_code = 0; int next_entry; int bits_per_code; int bits_shift; int bits; int bufpos = 0; - int i; /* * Write out dimensions of image @@ -83,6 +82,7 @@ Common::SeekableReadStream *PictureDecoder::decode(Common::ReadStream &src, uint first_colour = 65; break; default: + error("Unsupported mode"); break; } diff --git a/engines/glk/frotz/screen.cpp b/engines/glk/frotz/screen.cpp index eef6d6118d..a71217cc26 100644 --- a/engines/glk/frotz/screen.cpp +++ b/engines/glk/frotz/screen.cpp @@ -21,10 +21,26 @@ */ #include "glk/frotz/screen.h" +#include "common/file.h" +#include "image/bmp.h" namespace Glk { namespace Frotz { +void FrotzScreen::loadFonts(Common::Archive *archive) { + Screen::loadFonts(archive); + + Image::BitmapDecoder decoder; + Common::File f; + if (!f.open("infocom_graphics.bmp", *archive)) + error("Could not load font"); + + decoder.loadStream(f); + _fonts.push_back(new Frotz::BitmapFont(*decoder.getSurface())); +} + +/*--------------------------------------------------------------------------*/ + BitmapFont::BitmapFont(const Graphics::Surface &src, uint charWidth, uint charHeight, unsigned char startingChar) : _startingChar(startingChar) { assert(src.format.bytesPerPixel == 1); diff --git a/engines/glk/frotz/screen.h b/engines/glk/frotz/screen.h index dac716c436..d8b2b89a3f 100644 --- a/engines/glk/frotz/screen.h +++ b/engines/glk/frotz/screen.h @@ -28,11 +28,23 @@ #include "common/archive.h" #include "common/array.h" #include "common/rect.h" +#include "glk/screen.h" namespace Glk { namespace Frotz { /** + * Derived screen class that adds in the Infocom character graphics font + */ +class FrotzScreen : public Glk::Screen { +protected: + /** + * Load the fonts + */ + virtual void loadFonts(Common::Archive *archive) override; +}; + +/** * Implements a fixed width font stored as a grid on a passed surface */ class BitmapFont : public Graphics::Font { diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp index 87b736cb25..98ce410d68 100644 --- a/engines/glk/glk.cpp +++ b/engines/glk/glk.cpp @@ -71,9 +71,10 @@ void GlkEngine::initialize() { DebugMan.addDebugChannel(kDebugSound, "sound", "Sound and Music handling"); initGraphicsMode(); - _conf = new Conf(getInterpreterType()); - _screen = new Screen(); + _conf = new Conf(getInterpreterType()); + _screen = createScreen(); + _screen->initialize(); _clipboard = new Clipboard(); _events = new Events(); _pictures = new Pictures(); @@ -82,6 +83,10 @@ void GlkEngine::initialize() { _windows = new Windows(_screen); } +Screen *GlkEngine::createScreen() { + return new Screen(); +} + void GlkEngine::initGraphicsMode() { uint width = ConfMan.hasKey("width") ? ConfMan.getInt("width") : 640; uint height = ConfMan.hasKey("height") ? ConfMan.getInt("height") : 480; diff --git a/engines/glk/glk.h b/engines/glk/glk.h index af9a42ba43..526755b1aa 100644 --- a/engines/glk/glk.h +++ b/engines/glk/glk.h @@ -90,6 +90,11 @@ protected: virtual bool hasFeature(EngineFeature f) const; /** + * Create the screen + */ + virtual Screen *createScreen(); + + /** * Main game loop for the individual interpreters */ virtual void runGame(Common::SeekableReadStream *gameFile) = 0; diff --git a/engines/glk/screen.cpp b/engines/glk/screen.cpp index cfe8cde84f..6768360df1 100644 --- a/engines/glk/screen.cpp +++ b/engines/glk/screen.cpp @@ -33,7 +33,12 @@ namespace Glk { #define FONTS_VERSION 1.0 #define FONTS_FILENAME "fonts.dat" -Screen::Screen() { +Screen::~Screen() { + for (int idx = 0; idx < FONTS_TOTAL; ++idx) + delete _fonts[idx]; +} + +void Screen::initialize() { if (!loadFonts()) error("Could not load data file"); @@ -49,11 +54,6 @@ Screen::Screen() { g_conf->_cellH = g_conf->_leading; } -Screen::~Screen() { - for (int idx = 0; idx < FONTS_TOTAL; ++idx) - delete _fonts[idx]; -} - void Screen::fill(const byte *rgb) { uint color = format.RGBToColor(rgb[0], rgb[1], rgb[2]); clear(color); @@ -100,7 +100,6 @@ void Screen::drawCaret(const Point &pos) { bool Screen::loadFonts() { Common::Archive *archive = nullptr; - _fonts.resize(FONTS_TOTAL); if (!Common::File::exists(FONTS_FILENAME) || (archive = Common::makeZipArchive(FONTS_FILENAME)) == nullptr) return false; @@ -122,12 +121,20 @@ bool Screen::loadFonts() { return false; } + loadFonts(archive); + + delete archive; + return true; +} + +void Screen::loadFonts(Common::Archive *archive) { // R ead in the fonts double monoAspect = g_conf->_monoAspect; double propAspect = g_conf->_propAspect; double monoSize = g_conf->_monoSize; double propSize = g_conf->_propSize; + _fonts.resize(FONTS_TOTAL); _fonts[0] = loadFont(MONOR, archive, monoSize, monoAspect, FONTR); _fonts[1] = loadFont(MONOB, archive, monoSize, monoAspect, FONTB); _fonts[2] = loadFont(MONOI, archive, monoSize, monoAspect, FONTI); @@ -137,9 +144,6 @@ bool Screen::loadFonts() { _fonts[5] = loadFont(PROPB, archive, propSize, propAspect, FONTB); _fonts[6] = loadFont(PROPI, archive, propSize, propAspect, FONTI); _fonts[7] = loadFont(PROPZ, archive, propSize, propAspect, FONTZ); - - delete archive; - return true; } const Graphics::Font *Screen::loadFont(FACES face, Common::Archive *archive, double size, double aspect, int diff --git a/engines/glk/screen.h b/engines/glk/screen.h index 541e9e190e..bb5d7f6d25 100644 --- a/engines/glk/screen.h +++ b/engines/glk/screen.h @@ -46,10 +46,8 @@ enum STYLES { FONTR, FONTB, FONTI, FONTZ }; */ class Screen : public Graphics::Screen { private: - Common::Array<const Graphics::Font *> _fonts; -private: /** - * Load all the fonts + * Open the fonts archive and load all the fonts */ bool loadFonts(); @@ -58,6 +56,13 @@ private: */ const Graphics::Font *loadFont(FACES face, Common::Archive *archive, double size, double aspect, int style); +protected: + Common::Array<const Graphics::Font *> _fonts; +protected: + /** + * Load the fonts + */ + virtual void loadFonts(Common::Archive *archive); public: /** * Return the font Id for a given name @@ -67,7 +72,7 @@ public: /** * Constructor */ - Screen(); + Screen() : Graphics::Screen() {} /** * Destructor @@ -75,6 +80,11 @@ public: virtual ~Screen(); /** + * Initialize the screen + */ + void initialize(); + + /** * Fills the screen with a given rgb color */ void fill(const byte *rgb); |