diff options
-rw-r--r-- | engines/gnap/gamesys.cpp | 42 | ||||
-rw-r--r-- | engines/gnap/gnap.cpp | 24 | ||||
-rw-r--r-- | engines/gnap/gnap.h | 4 | ||||
-rw-r--r-- | engines/gnap/scenes/arcade.cpp | 6 |
4 files changed, 43 insertions, 33 deletions
diff --git a/engines/gnap/gamesys.cpp b/engines/gnap/gamesys.cpp index 6a9cc0f10d..ecfa3c54ba 100644 --- a/engines/gnap/gamesys.cpp +++ b/engines/gnap/gamesys.cpp @@ -261,8 +261,6 @@ void GameSys::drawSpriteToSurface(Graphics::Surface *surface, int x, int y, int } void GameSys::drawTextToSurface(Graphics::Surface *surface, int x, int y, byte r, byte g, byte b, const char *text) { - // NOTE Not that nice but will have to do for now - bool doDirty = false; if (!surface) { @@ -271,29 +269,33 @@ void GameSys::drawTextToSurface(Graphics::Surface *surface, int x, int y, byte r } uint32 color = surface->format.RGBToColor(r, g, b); + if (_vm->_font) { + _vm->_font->drawString(surface, text, x, y, _vm->_font->getStringWidth(text), color); - for (const char *cp = text; *cp != 0; ++cp) { - byte c = *cp; - if (c < 32 || c > 127) - c = (byte)'_'; - c -= 32; - int w = _dejaVuSans9ptCharDescriptors[c]._width; - const byte *data = _dejaVuSans9ptCharBitmaps + _dejaVuSans9ptCharDescriptors[c]._offset; - for (int xc = 0; xc < w; ++xc) { - for (int yc = 15; yc >= 0; --yc) { - byte *dst = (byte*)surface->getBasePtr(x + xc, y + yc); - if (data[1 - (yc >> 3)] & (1 << (yc & 7))) - WRITE_LE_UINT32(dst, color); + if (doDirty) + insertDirtyRect(Common::Rect(x, y, x + _vm->_font->getStringWidth(text), y + _vm->_font->getFontHeight())); + } else { + for (const char *cp = text; *cp != 0; ++cp) { + byte c = *cp; + if (c < 32 || c > 127) + c = (byte)'_'; + c -= 32; + int w = _dejaVuSans9ptCharDescriptors[c]._width; + const byte *data = _dejaVuSans9ptCharBitmaps + _dejaVuSans9ptCharDescriptors[c]._offset; + for (int xc = 0; xc < w; ++xc) { + for (int yc = 15; yc >= 0; --yc) { + byte *dst = (byte*)surface->getBasePtr(x + xc, y + yc); + if (data[1 - (yc >> 3)] & (1 << (yc & 7))) + WRITE_LE_UINT32(dst, color); + } + data += 2; } - data += 2; + x += w + 1; } - x += w + 1; - } - if (doDirty) { - insertDirtyRect(Common::Rect(x, y, x + getTextWidth(text), y + 16)); + if (doDirty) + insertDirtyRect(Common::Rect(x, y, x + getTextWidth(text), y + 16)); } - } int GameSys::getTextHeight(const char *text) { diff --git a/engines/gnap/gnap.cpp b/engines/gnap/gnap.cpp index dacf360eda..21329fefee 100644 --- a/engines/gnap/gnap.cpp +++ b/engines/gnap/gnap.cpp @@ -20,6 +20,7 @@ * */ +#include "graphics/cursorman.h" #include "gnap/gnap.h" #include "gnap/datarchive.h" #include "gnap/gamesys.h" @@ -28,14 +29,10 @@ #include "common/config-manager.h" #include "common/debug-channels.h" -#include "common/error.h" -#include "common/fs.h" #include "common/timer.h" #include "engines/util.h" -#include "graphics/cursorman.h" - namespace Gnap { static const int kCursors[] = { @@ -143,6 +140,15 @@ Common::Error GnapEngine::run() { if (!_exe->loadFromEXE("ufos.exe")) error("Could not load ufos.exe"); +#ifdef USE_FREETYPE2 + Common::SeekableReadStream *stream = _exe->getResource(Common::kPEFont, 2000); + _font = Graphics::loadTTFFont(*stream, 24); + if (!_font) + warning("Unable to load font"); +#else + _font = nullptr; +#endif + _dat = new DatManager(); _spriteCache = new SpriteCache(_dat); _soundCache = new SoundCache(_dat); @@ -167,6 +173,7 @@ Common::Error GnapEngine::run() { delete _spriteCache; delete _dat; delete _debugger; + delete _font; delete _exe; return Common::kNoError; @@ -342,10 +349,13 @@ void GnapEngine::updateCursorByHotspot() { int hotspotIndex = getHotspotIndexAtPos(Common::Point(_mouseX, _mouseY)); if (_debugger->_showHotspotNumber) { - // NOTE This causes some display glitches so don't worry + // NOTE This causes some display glitches char t[256]; - sprintf(t, "hotspot = %d", hotspotIndex); - _gameSys->fillSurface(0, 10, 10, 80, 16, 0, 0, 0); + sprintf(t, "hotspot = %2d", hotspotIndex); + if (!_font) + _gameSys->fillSurface(0, 10, 10, 80, 16, 0, 0, 0); + else + _gameSys->fillSurface(0, 8, 9, _font->getStringWidth(t) + 10, _font->getFontHeight() + 2, 0, 0, 0); _gameSys->drawTextToSurface(0, 10, 10, 255, 255, 255, t); } diff --git a/engines/gnap/gnap.h b/engines/gnap/gnap.h index d379a263b9..45f675c848 100644 --- a/engines/gnap/gnap.h +++ b/engines/gnap/gnap.h @@ -38,6 +38,9 @@ #include "engines/engine.h" #include "graphics/pixelformat.h" #include "graphics/wincursor.h" +#include "graphics/fontman.h" +#include "graphics/font.h" +#include "graphics/fonts/ttf.h" #include "gnap/debugger.h" #include "gnap/resource.h" @@ -243,6 +246,7 @@ public: PlayerGnap *_gnap; PlayerPlat *_plat; MusicPlayer *_music; + Graphics::Font *_font; int _lastUpdateClock; diff --git a/engines/gnap/scenes/arcade.cpp b/engines/gnap/scenes/arcade.cpp index 1547a50716..d26e0fb931 100644 --- a/engines/gnap/scenes/arcade.cpp +++ b/engines/gnap/scenes/arcade.cpp @@ -2623,9 +2623,6 @@ void Scene52::run() { _vm->hideCursor(); - // TODO loadFont("maturasc", "Matura MT Script Capitals", 2000); - // TODO setFontSize(24); - _gameScore = 0; _vm->_gameSys->drawTextToSurface(0, 300, 80, 255, 255, 255, "SCORE"); _vm->_gameSys->drawTextToSurface(0, 468, 80, 255, 255, 255, "0"); @@ -2720,9 +2717,6 @@ void Scene52::run() { _vm->_sceneDone = true; } } - - // TODO freeFont(); - _vm->_gameSys->waitForUpdate(); } |