diff options
author | Bendegúz Nagy | 2016-06-22 20:32:30 +0200 |
---|---|---|
committer | Bendegúz Nagy | 2016-08-26 23:02:22 +0200 |
commit | 9538db0b6100b407d3ed1450256ffdc63efef4c2 (patch) | |
tree | bc2eb9a201803d43b9f4204072fa3783dcc2eb31 /engines | |
parent | f46a588164f7a49767ed75cd108d16cfc6cf7410 (diff) | |
download | scummvm-rg350-9538db0b6100b407d3ed1450256ffdc63efef4c2.tar.gz scummvm-rg350-9538db0b6100b407d3ed1450256ffdc63efef4c2.tar.bz2 scummvm-rg350-9538db0b6100b407d3ed1450256ffdc63efef4c2.zip |
Add: TextMan, font loading and basic text display
Diffstat (limited to 'engines')
-rw-r--r-- | engines/dm/dm.cpp | 4 | ||||
-rw-r--r-- | engines/dm/dm.h | 3 | ||||
-rw-r--r-- | engines/dm/gfx.cpp | 24 | ||||
-rw-r--r-- | engines/dm/gfx.h | 6 | ||||
-rw-r--r-- | engines/dm/text.cpp | 37 | ||||
-rw-r--r-- | engines/dm/text.h | 20 |
6 files changed, 91 insertions, 3 deletions
diff --git a/engines/dm/dm.cpp b/engines/dm/dm.cpp index 3a1a951c2b..8d38c5bf85 100644 --- a/engines/dm/dm.cpp +++ b/engines/dm/dm.cpp @@ -20,6 +20,7 @@ #include "loadsave.h" #include "objectman.h" #include "inventory.h" +#include "text.h" namespace DM { @@ -54,6 +55,7 @@ DMEngine::DMEngine(OSystem *syst) : Engine(syst), _console(nullptr) { _loadsaveMan = nullptr; _objectMan = nullptr; _inventoryMan = nullptr; + _textMan = nullptr; _stopWaitingForPlayerInput = false; _gameTimeTicking = false; @@ -74,6 +76,7 @@ DMEngine::~DMEngine() { delete _loadsaveMan; delete _objectMan; delete _inventoryMan; + delete _textMan; // clear debug channels DebugMan.clearAllDebugChannels(); @@ -151,6 +154,7 @@ Common::Error DMEngine::run() { _loadsaveMan = new LoadsaveMan(this); _objectMan = new ObjectMan(this); _inventoryMan = new InventoryMan(this); + _textMan = new TextMan(this); _displayMan->setUpScreens(320, 200); initializeGame(); // @ F0463_START_InitializeGame_CPSADEF diff --git a/engines/dm/dm.h b/engines/dm/dm.h index 2a718ce868..f2d14c9422 100644 --- a/engines/dm/dm.h +++ b/engines/dm/dm.h @@ -17,6 +17,7 @@ class ChampionMan; class LoadsaveMan; class ObjectMan; class InventoryMan; +class TextMan; enum direction { @@ -104,6 +105,8 @@ public: LoadsaveMan *_loadsaveMan; ObjectMan *_objectMan; InventoryMan *_inventoryMan; + TextMan *_textMan; + bool _stopWaitingForPlayerInput; // G0321_B_StopWaitingForPlayerInput bool _gameTimeTicking; // @ G0301_B_GameTimeTicking bool _restartGameAllowed; // @ G0524_B_RestartGameAllowed diff --git a/engines/dm/gfx.cpp b/engines/dm/gfx.cpp index 1af0a03c0b..ab0f9f114e 100644 --- a/engines/dm/gfx.cpp +++ b/engines/dm/gfx.cpp @@ -685,12 +685,13 @@ void DisplayMan::unpackGraphics() { unpackedBitmapsSize += getWidth(i) * getHeight(i); for (uint16 i = 22; i <= 532; ++i) unpackedBitmapsSize += getWidth(i) * getHeight(i); + unpackedBitmapsSize += (5 + 1) * (6 + 1) * 128; // 5 x 6 characters, 128 of them, +1 for convenience padding // graphics items go from 0-20 and 22-532 inclusive, _unpackedItemPos 21 and 22 are there for indexing convenience if (_bitmaps) { delete[] _bitmaps[0]; delete[] _bitmaps; } - _bitmaps = new byte*[533]; + _bitmaps = new byte*[575]; // largest graphic indice (i think) _bitmaps[0] = new byte[unpackedBitmapsSize]; loadIntoBitmap(0, _bitmaps[0]); for (uint16 i = 1; i <= 20; ++i) { @@ -698,10 +699,29 @@ void DisplayMan::unpackGraphics() { loadIntoBitmap(i, _bitmaps[i]); } _bitmaps[22] = _bitmaps[20] + getWidth(20) * getHeight(20); - for (uint16 i = 23; i < 533; ++i) { + for (uint16 i = 23; i <= 532; ++i) { _bitmaps[i] = _bitmaps[i - 1] + getWidth(i - 1) * getHeight(i - 1); loadIntoBitmap(i, _bitmaps[i]); } + _bitmaps[kFontGraphicIndice] = _bitmaps[532] + getWidth(532) * getHeight(532); + loadFNT1intoBitmap(kFontGraphicIndice, _bitmaps[kFontGraphicIndice]); +} + +void DisplayMan::loadFNT1intoBitmap(uint16 index, byte* destBitmap) +{ + uint8 *data = _packedBitmaps + _packedItemPos[index]; + for (uint16 i = 0; i < 6; i++) { + for (uint16 w = 0; w < 128; ++w) { + *destBitmap++ = kColorBlack; + + uint16 nextByte = *data++; + for (int16 pixel = 4; pixel >= 0; --pixel) { + *destBitmap++ = (nextByte >> pixel) & 0x1; + } + } + } + memset(data, 0, 128); + data += 128; } void DisplayMan::loadPalette(uint16 *palette) { diff --git a/engines/dm/gfx.h b/engines/dm/gfx.h index 87d6bda69f..38d6630a96 100644 --- a/engines/dm/gfx.h +++ b/engines/dm/gfx.h @@ -40,7 +40,8 @@ enum GraphicIndice { kStatusBoxDeadChampion = 8, // @ C008_GRAPHIC_STATUS_BOX_DEAD_CHAMPION kSlotBoxNormalIndice = 33, // @ C033_GRAPHIC_SLOT_BOX_NORMAL kSlotBoxWoundedIndice = 34, // @ C034_GRAPHIC_SLOT_BOX_WOUNDED - kChampionIcons = 28 // @ C028_GRAPHIC_CHAMPION_ICONS + kChampionIcons = 28, // @ C028_GRAPHIC_CHAMPION_ICONS + kFontGraphicIndice = 557 // @ C557_GRAPHIC_FONT }; extern uint16 gPalSwoosh[16]; @@ -221,6 +222,8 @@ extern Viewport gDungeonViewport; #define kDoorOrnThivesEyeMask 16 // @ C16_DOOR_ORNAMENT_THIEVES_EYE_MASK class DisplayMan { + friend class DM::TextMan; + DMEngine *_vm; uint16 _screenWidth; uint16 _screenHeight; @@ -248,6 +251,7 @@ class DisplayMan { // the original function has two position parameters, but they are always set to zero void loadIntoBitmap(uint16 index, byte *destBitmap); // @ F0466_EXPAND_GraphicToBitmap void unpackGraphics(); + void loadFNT1intoBitmap(uint16 index, byte *destBitmap); void drawFloorPitOrStairsBitmapFlippedHorizontally(StairIndex relIndex, Frame &frame); // @ F0105_DUNGEONVIEW_DrawFloorPitOrStairsBitmapFlippedHorizontally void drawFloorPitOrStairsBitmap(StairIndex relIndex, Frame &frame); // @ F0104_DUNGEONVIEW_DrawFloorPitOrStairsBitmap diff --git a/engines/dm/text.cpp b/engines/dm/text.cpp new file mode 100644 index 0000000000..116058de35 --- /dev/null +++ b/engines/dm/text.cpp @@ -0,0 +1,37 @@ +#include "text.h" + + +namespace DM { + +TextMan::TextMan(DMEngine* vm) : _vm(vm) {} + +#define kLetterWidth 5 +#define kLetterHeight 6 + +void TextMan::printTextToBitmap(byte* destBitmap, uint16 destPixelWidth, uint16 destX, uint16 destY, Color textColor, Color bgColor, char* text, uint16 destHeight, Viewport &viewport) { + uint16 textLength = strlen(text); + uint16 nextX = destX; + uint16 nextY = destY; + byte *srcBitmap = _vm->_displayMan->getBitmap(kFontGraphicIndice); + + + for (char *begin = text, *end = text + textLength; begin != end; ++begin) { + // Note: this does no wraps in the middle of words + if (nextX + kLetterWidth + 1 > destPixelWidth || (*begin == '\n')) { + nextX = destX; + nextY += kLetterHeight + 1; + } + if (nextY + kLetterHeight + 1 > destHeight) + break; + uint16 srcX = (1 + 5) * toupper(*begin); // 1 + 5 is not the letter width, arbitrary choice of the unpacking code + _vm->_displayMan->blitToBitmap(srcBitmap, 6 * 128, srcX, 0, destBitmap, destPixelWidth, + nextX, nextX + kLetterWidth + 1, nextY, nextY + kLetterHeight + 1, kColorNoTransparency, viewport); + nextX += kLetterWidth + 1; + } +} + +void TextMan::printTextToScreen(uint16 destX, uint16 destY, Color textColor, Color bgColor, char* text, Viewport &viewport) { + printTextToBitmap(_vm->_displayMan->_vgaBuffer, _vm->_displayMan->_screenWidth, destX, destY, textColor, bgColor, text, _vm->_displayMan->_screenHeight, viewport); +} + +} diff --git a/engines/dm/text.h b/engines/dm/text.h new file mode 100644 index 0000000000..7f57525012 --- /dev/null +++ b/engines/dm/text.h @@ -0,0 +1,20 @@ +#ifndef DM_TEXT_H +#define DM_TEXT_H + +#include "dm.h" +#include "gfx.h" + +namespace DM { + +class TextMan { + DMEngine *_vm; +public: + TextMan(DMEngine *vm); + void printTextToBitmap(byte *destBitmap, uint16 destPixelWidth, uint16 destX, uint16 destY, + Color textColor, Color bgColor, char *text, uint16 destHeight, Viewport &viewport = gDefultViewPort); // @ F0040_TEXT_Print + void printTextToScreen(uint16 destX, uint16 destY, Color textColor, Color bgColor, char *text, Viewport &viewport = gDefultViewPort); +}; + +} + +#endif |