[Scummvm-git-logs] scummvm master -> e2174c5296ca33e40b33d95681bb97f3f88a07a2
whiterandrek
noreply at scummvm.org
Tue Feb 8 15:37:37 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e2174c5296 PETKA: improved text rendering
Commit: e2174c5296ca33e40b33d95681bb97f3f88a07a2
https://github.com/scummvm/scummvm/commit/e2174c5296ca33e40b33d95681bb97f3f88a07a2
Author: Andrei Prykhodko (whiterandrek at gmail.com)
Date: 2022-02-08T17:37:33+02:00
Commit Message:
PETKA: improved text rendering
bug #12064
Changed paths:
engines/petka/objects/text.cpp
engines/petka/objects/text.h
engines/petka/petka.cpp
engines/petka/petka.h
diff --git a/engines/petka/objects/text.cpp b/engines/petka/objects/text.cpp
index e3bf99c9194..fe3731eaba0 100644
--- a/engines/petka/objects/text.cpp
+++ b/engines/petka/objects/text.cpp
@@ -38,16 +38,16 @@ QText::QText(const Common::U32String &text, uint16 textColor, uint16 outlineColo
_resourceId = -2;
_z = 3000;
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 20));
+ auto *font = g_vm->getTextFont();
Common::Rect rect = calculateBoundingBoxForText(text, *font);
rect.right += 10;
- rect.bottom += 10;
+ rect.bottom += 4;
_rect = Common::Rect((640 - rect.width()) / 2, 479 - rect.height(), 639 - (640 - rect.width()) / 2, 479);
- Graphics::Surface *s = g_vm->resMgr()->getSurface(-2, _rect.width(), _rect.height());
+ Graphics::Surface *s = g_vm->resMgr()->getSurface(-2, rect.width(), rect.height());
- drawText(*s, 0, 630, text, textColor, *font);
+ drawText(*s, 0, 630, text, textColor, *font, Graphics::kTextAlignCenter);
drawOutline(s, outlineColor);
}
@@ -146,11 +146,10 @@ QTextDescription::QTextDescription(const Common::U32String &desc, uint32 frame)
delete convS;
Common::Rect textArea(160, 275, 598, 376);
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 16));
-
+ auto *font = g_vm->getDescriptionFont();
auto textSurface = s->getSubArea(textArea);
- drawText(textSurface, 0, textArea.width(), desc, 0, *font);
+ drawText(textSurface, 0, textArea.width(), desc, 0, *font, Graphics::kTextAlignLeft);
g_vm->videoSystem()->addDirtyRect(_rect);
}
@@ -180,16 +179,19 @@ QTextChoice::QTextChoice(const Common::Array<Common::U32String> &choices, uint16
int w = 0;
int h = 0;
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 20));
+ auto *font = g_vm->getTextFont();
+
_rects.resize(choices.size());
for (uint i = 0; i < _choices.size(); ++i) {
_rects[i] = calculateBoundingBoxForText(_choices[i], *font);
w = MAX<int>(w, _rects[i].width());
- h += _rects[i].height();
+ _rects[i].setWidth(w);
+ _rects[i].setHeight(font->getFontHeight());
+ h += font->getFontHeight();
}
w += 10;
- h += 5;
+ h += 4;
_rect = Common::Rect((640 - w) / 2, 479 - h, 639 - (640 - w) / 2, 479);
@@ -197,10 +199,10 @@ QTextChoice::QTextChoice(const Common::Array<Common::U32String> &choices, uint16
int y = 0;
for (uint i = 0; i < _choices.size(); ++i) {
- drawText(*s, y, 630, _choices[i], _choiceColor, *font);
+ drawText(*s, y, 630, _choices[i], _choiceColor, *font, Graphics::TextAlign::kTextAlignLeft);
_rects[i].moveTo(0, y);
- y += _rects[i].height();
+ y += font->getFontHeight();
}
drawOutline(s, outlineColor);
}
@@ -217,12 +219,12 @@ void QTextChoice::onMouseMove(Common::Point p) {
if (newChoice != _activeChoice) {
Graphics::Surface *s = g_vm->resMgr()->getSurface(-2);
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 20));
+ auto *font = g_vm->getTextFont();
s->fillRect(Common::Rect(s->w, s->h), 0);
for (uint i = 0; i < _choices.size(); ++i) {
uint color = (i == newChoice) ? _selectedColor : _choiceColor;
- drawText(*s, _rects[i].top, 630, _choices[i], color, *font);
+ drawText(*s, _rects[i].top, 630, _choices[i], color, *font, Graphics::kTextAlignLeft);
}
drawOutline(s, _outlineColor);
_activeChoice = newChoice;
@@ -243,9 +245,10 @@ Common::Rect QText::calculateBoundingBoxForText(const Common::U32String &text, G
font.wordWrapText(text, 630, lines);
Common::Rect rect = font.getBoundingBox(lines[0]);
+ rect.setHeight(font.getFontHeight());
for (uint j = 1; j < lines.size(); ++j) {
auto box = font.getBoundingBox(lines[j]);
- rect.setHeight(rect.height() + box.height());
+ rect.setHeight(rect.height() + font.getFontHeight());
if (box.width() > rect.width())
rect.setWidth(box.width());
}
@@ -253,14 +256,14 @@ Common::Rect QText::calculateBoundingBoxForText(const Common::U32String &text, G
return rect;
}
-void QText::drawText(Graphics::Surface &s, int y, int maxWidth, const Common::U32String &text, uint color, Graphics::Font &font) {
+void QText::drawText(Graphics::Surface &s, int y, int maxWidth, const Common::U32String &text, uint color, Graphics::Font &font, Graphics::TextAlign alignment) {
Common::Array<Common::U32String> lines;
font.wordWrapText(text, maxWidth, lines);
int h = 0;
for (uint i = 0; i < lines.size(); ++i) {
- font.drawString(&s, lines[i], 0, y + h, s.w, color);
- h += font.getBoundingBox(lines[i]).height();
+ font.drawString(&s, lines[i], 0, y + h, s.w, color, alignment);
+ h += font.getFontHeight();
}
}
diff --git a/engines/petka/objects/text.h b/engines/petka/objects/text.h
index d2a75255a51..0482d1e49e5 100644
--- a/engines/petka/objects/text.h
+++ b/engines/petka/objects/text.h
@@ -45,7 +45,7 @@ protected:
static void drawOutline(Graphics::Surface *surface, uint16 color);
static Common::Rect calculateBoundingBoxForText(const Common::U32String &text, Graphics::Font &font);
- static void drawText(Graphics::Surface &s, int y, int maxWidth, const Common::U32String &text, uint color, Graphics::Font &font);
+ static void drawText(Graphics::Surface &s, int y, int maxWidth, const Common::U32String &text, uint color, Graphics::Font &font, Graphics::TextAlign alignment);
protected:
Common::Rect _rect;
diff --git a/engines/petka/petka.cpp b/engines/petka/petka.cpp
index 8f5b4cca819..11a3112dce4 100644
--- a/engines/petka/petka.cpp
+++ b/engines/petka/petka.cpp
@@ -32,6 +32,8 @@
#include "engines/util.h"
#include "graphics/surface.h"
+#include "graphics/font.h"
+#include "graphics/fonts/ttf.h"
#include "video/avi_decoder.h"
@@ -87,6 +89,9 @@ Common::Error PetkaEngine::run() {
_vsys.reset(new VideoSystem(*this));
_resMgr.reset(new QManager(*this));
+ _textFont.reset(Graphics::loadTTFFontFromArchive("FreeSansBold.ttf", 20, Graphics::kTTFSizeModeCell));
+ _descriptionFont.reset(Graphics::loadTTFFontFromArchive("FreeSansBold.ttf", 16, Graphics::kTTFSizeModeCell));
+
loadPart(isDemo() ? 1 : 0);
if (ConfMan.hasKey("save_slot")) {
diff --git a/engines/petka/petka.h b/engines/petka/petka.h
index 2bb21494d97..f0d0a7a0b12 100644
--- a/engines/petka/petka.h
+++ b/engines/petka/petka.h
@@ -51,6 +51,10 @@ namespace Common {
class SeekableReadStream;
}
+namespace Graphics {
+class Font;
+}
+
namespace Video {
class VideoDecoder;
}
@@ -105,6 +109,9 @@ public:
Common::RandomSource &getRnd();
const Common::String &getSpeechPath();
+ Graphics::Font *getTextFont() const { return _textFont.get(); }
+ Graphics::Font *getDescriptionFont() const { return _descriptionFont.get(); }
+
Common::Error loadGameState(int slot) override;
bool canLoadGameStateCurrently() override;
@@ -129,6 +136,8 @@ private:
Common::ScopedPtr<VideoSystem> _vsys;
Common::ScopedPtr<BigDialogue> _dialogMan;
Common::ScopedPtr<Video::VideoDecoder> _videoDec;
+ Common::ScopedPtr<Graphics::Font> _textFont;
+ Common::ScopedPtr<Graphics::Font> _descriptionFont;
Common::RandomSource _rnd;
More information about the Scummvm-git-logs
mailing list