[Scummvm-git-logs] scummvm master -> 0639c0708e82d60393aa9007bd7bcc846d2b04d1
whiterandrek
whiterandrek at gmail.com
Mon Oct 5 21:09:17 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
6a35dda135 PETKA: implement drawing multiline text
0639c0708e PETKA: implement dirty rects for QTextDescription
Commit: 6a35dda135986d06adb44430222dd49d91323090
https://github.com/scummvm/scummvm/commit/6a35dda135986d06adb44430222dd49d91323090
Author: Andrei Prykhodko (whiterandrek at gmail.com)
Date: 2020-10-05T23:53:25+03:00
Commit Message:
PETKA: implement drawing multiline text
Changed paths:
engines/petka/objects/text.cpp
engines/petka/objects/text.h
diff --git a/engines/petka/objects/text.cpp b/engines/petka/objects/text.cpp
index c0eed78323..e36aac8332 100644
--- a/engines/petka/objects/text.cpp
+++ b/engines/petka/objects/text.cpp
@@ -39,15 +39,16 @@ QText::QText(const Common::U32String &text, uint16 textColor, uint16 outlineColo
_resourceId = -2;
_z = 3000;
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 18));
- Common::Rect rect = font->getBoundingBox(text, 0, 0, 0);
+ Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 20));
+
+ Common::Rect rect = calculateBoundingBoxForText(text, *font);
rect.right += 10;
- rect.bottom += 4;
+ rect.bottom += 10;
_rect = Common::Rect((640 - rect.width()) / 2, 479 - rect.height(), 639 - (640 - rect.width()) / 2, 479);
Graphics::Surface *s = g_vm->resMgr()->findOrCreateSurface(-2, _rect.width(), _rect.height());
- font->drawString(s, text, 0, 0, s->w, textColor);
+ drawText(*s, 0, 630, text, textColor, *font);
drawOutline(s, outlineColor);
}
@@ -145,11 +146,12 @@ QTextDescription::QTextDescription(const Common::U32String &desc, uint32 frame)
convS->free();
delete convS;
-
Common::Rect textArea(160, 275, 598, 376);
Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 16));
- font->drawString(s, desc, textArea.left, textArea.top, textArea.width(), 0);
+ auto textSurface = s->getSubArea(textArea);
+
+ drawText(textSurface, 0, textArea.width(), desc, 0, *font);
}
void QTextDescription::onClick(Common::Point p) {
@@ -171,24 +173,26 @@ QTextChoice::QTextChoice(const Common::Array<Common::U32String> &choices, uint16
int w = 0;
int h = 0;
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 18));
+
+ Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 20));
_rects.resize(choices.size());
for (uint i = 0; i < _choices.size(); ++i) {
- _rects[i] = font->getBoundingBox(_choices[i]);
- _rects[i].bottom += 5;
- _rects[i].right += 15;
- if (_rects[i].width() > w)
- w = _rects[i].width();
+ _rects[i] = calculateBoundingBoxForText(_choices[i], *font);
+ w = MAX<int>(w, _rects[i].width());
h += _rects[i].height();
}
+ w += 10;
+ h += 5;
+
_rect = Common::Rect((640 - w) / 2, 479 - h, 639 - (640 - w) / 2, 479);
Graphics::Surface *s = g_vm->resMgr()->findOrCreateSurface(-2, w, h);
int y = 0;
for (uint i = 0; i < _choices.size(); ++i) {
- font->drawString(s, _choices[i], 0, y, s->w, color);
+ drawText(*s, y, 630, _choices[i], _choiceColor, *font);
+
_rects[i].moveTo(0, y);
y += _rects[i].height();
}
@@ -206,15 +210,12 @@ void QTextChoice::onMouseMove(Common::Point p) {
if (newChoice != _activeChoice) {
Graphics::Surface *s = g_vm->resMgr()->loadBitmap(-2);
- Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 18));
+ Common::ScopedPtr<Graphics::Font> font(Graphics::loadTTFFontFromArchive("FreeSans.ttf", 20));
s->fillRect(Common::Rect(s->w, s->h), 0);
for (uint i = 0; i < _choices.size(); ++i) {
- if (i == newChoice) {
- font->drawString(s, _choices[newChoice], _rects[newChoice].left, _rects[newChoice].top, s->w, _selectedColor);
- } else {
- font->drawString(s, _choices[i], _rects[i].left, _rects[i].top, s->w, _choiceColor);
- }
+ uint color = (i == newChoice) ? _selectedColor : _choiceColor;
+ drawText(*s, _rects[i].top, 630, _choices[i], color, *font);
}
_activeChoice = newChoice;
@@ -227,4 +228,33 @@ void QTextChoice::onClick(Common::Point p) {
}
}
+Common::Rect QText::calculateBoundingBoxForText(const Common::U32String &text, Graphics::Font &font) {
+ if (text.empty())
+ return {};
+
+ Common::Array<Common::U32String> lines;
+ font.wordWrapText(text, 630, lines);
+
+ Common::Rect rect = font.getBoundingBox(lines[0]);
+ for (uint j = 1; j < lines.size(); ++j) {
+ auto box = font.getBoundingBox(lines[j]);
+ rect.setHeight(rect.height() + box.height());
+ if (box.width() > rect.width())
+ rect.setWidth(box.width());
+ }
+
+ return rect;
+}
+
+void QText::drawText(Graphics::Surface &s, int y, int maxWidth, const Common::U32String &text, uint color, Graphics::Font &font) {
+ 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();
+ }
+}
+
} // End of namespace Petka
diff --git a/engines/petka/objects/text.h b/engines/petka/objects/text.h
index 3ce3d2835d..499e2499ea 100644
--- a/engines/petka/objects/text.h
+++ b/engines/petka/objects/text.h
@@ -45,6 +45,8 @@ protected:
QText();
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);
protected:
Common::Rect _rect;
Commit: 0639c0708e82d60393aa9007bd7bcc846d2b04d1
https://github.com/scummvm/scummvm/commit/0639c0708e82d60393aa9007bd7bcc846d2b04d1
Author: Andrei Prykhodko (whiterandrek at gmail.com)
Date: 2020-10-06T00:07:23+03:00
Commit Message:
PETKA: implement dirty rects for QTextDescription
Changed paths:
engines/petka/objects/text.cpp
engines/petka/objects/text.h
diff --git a/engines/petka/objects/text.cpp b/engines/petka/objects/text.cpp
index e36aac8332..0601111ff6 100644
--- a/engines/petka/objects/text.cpp
+++ b/engines/petka/objects/text.cpp
@@ -152,6 +152,8 @@ QTextDescription::QTextDescription(const Common::U32String &desc, uint32 frame)
auto textSurface = s->getSubArea(textArea);
drawText(textSurface, 0, textArea.width(), desc, 0, *font);
+
+ g_vm->videoSystem()->addDirtyRect(_rect);
}
void QTextDescription::onClick(Common::Point p) {
@@ -159,10 +161,14 @@ void QTextDescription::onClick(Common::Point p) {
}
void QTextDescription::draw() {
- Graphics::Surface *s = g_vm->resMgr()->loadBitmap(-2);
- FlicDecoder *flc = g_vm->resMgr()->loadFlic(6008);
- g_vm->videoSystem()->transBlitFrom(*s, flc->getTransColor(s->format));
- // todo dirty rects
+ QManager *resMgr = g_vm->resMgr();
+ VideoSystem *videoSys = g_vm->videoSystem();
+ Graphics::Surface *s = resMgr->loadBitmap(-2);
+ FlicDecoder *flc = resMgr->loadFlic(6008);
+
+ for (auto dirty : videoSys->rects()) {
+ videoSys->transBlitFrom(*s, dirty, dirty, flc->getTransColor(s->format));
+ }
}
QTextChoice::QTextChoice(const Common::Array<Common::U32String> &choices, uint16 color, uint16 selectedColor) {
diff --git a/engines/petka/objects/text.h b/engines/petka/objects/text.h
index 499e2499ea..0b2905668f 100644
--- a/engines/petka/objects/text.h
+++ b/engines/petka/objects/text.h
@@ -73,6 +73,7 @@ public:
void draw() override;
void onClick(Common::Point p) override;
bool isInPoint(Common::Point p) override { return true; }
+ void update(int t) override {}
};
class QTextChoice : public QText {
More information about the Scummvm-git-logs
mailing list