From a4ae3939d966740802bf482b5ffaec8a0cb1dfde Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sat, 28 Nov 2015 19:00:34 +0100 Subject: [PATCH] STARK: Use the appropriate font height when rendering text --- engines/stark/visual/text.cpp | 24 ++++++++++++++---------- engines/stark/visual/text.h | 4 +++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/engines/stark/visual/text.cpp b/engines/stark/visual/text.cpp index 9b5913a03dd..c36d489612b 100644 --- a/engines/stark/visual/text.cpp +++ b/engines/stark/visual/text.cpp @@ -41,7 +41,8 @@ VisualText::VisualText(Gfx::Driver *gfx) : _color(0), _backgroundColor(0), _targetWidth(600), - _font(nullptr) { + _fontCustomIndex(-1), + _fontType(FontProvider::kBigFont) { } VisualText::~VisualText() { @@ -76,16 +77,23 @@ void VisualText::setTargetWidth(uint32 width) { _targetWidth = width; } +void VisualText::setFont(FontProvider::FontType type, int32 customFontIndex) { + freeTexture(); + + _fontType = type; + _fontCustomIndex = customFontIndex; +} + void VisualText::createTexture() { - assert(_font); + const Graphics::Font *font = StarkFontProvider->getFont(_fontType, _fontCustomIndex); + int height = StarkFontProvider->getFontHeight(_fontType, _fontCustomIndex); Common::Array lines; - _font->wordWrapText(_text, _targetWidth, lines); + font->wordWrapText(_text, _targetWidth, lines); - int height = _font->getFontHeight() + 1; int width = 0; for (uint i = 0; i < lines.size(); i++) { - width = MAX(width, _font->getStringWidth(lines[i])); + width = MAX(width, font->getStringWidth(lines[i])); } Common::Rect boundingRect = Common::Rect(width, height * lines.size()); @@ -95,7 +103,7 @@ void VisualText::createTexture() { surface.fillRect(boundingRect, _backgroundColor); for (uint i = 0; i < lines.size(); i++) { - _font->drawString(&surface, lines[i], 0, height * i, _targetWidth, _color); + font->drawString(&surface, lines[i], 0, height * i, _targetWidth, _color); } _texture = _gfx->createTexture(&surface); surface.free(); @@ -114,8 +122,4 @@ void VisualText::render(const Common::Point &position) { _gfx->drawSurface(_texture, position); } -void VisualText::setFont(FontProvider::FontType type, int32 customFontIndex) { - _font = StarkFontProvider->getFont(type, customFontIndex); -} - } // End of namespace Stark diff --git a/engines/stark/visual/text.h b/engines/stark/visual/text.h index 39b4a82da65..b2a2695722c 100644 --- a/engines/stark/visual/text.h +++ b/engines/stark/visual/text.h @@ -63,11 +63,13 @@ private: Gfx::Driver *_gfx; Common::String _text; - const Graphics::Font *_font; uint32 _color; uint32 _backgroundColor; uint32 _targetWidth; Gfx::Texture *_texture; + + FontProvider::FontType _fontType; + int32 _fontCustomIndex; }; } // End of namespace Stark