implemented help illustrations

This commit is contained in:
Geoffray Levasseur committed 2026-11-17 12:12:38 +01:00
1 parent 3753749f2e
commit 3645c06305
2 files changed
+68 -15

No files matched your search

+55 -7
View File
@@ -36,7 +36,9 @@
// (Imp/Ter/Feature/Model/Text) still render a plain placeholder paragraph
// instead of the original's full icon-rich, per-TextFormat layout engine
// (pkAdvIcon/pkBigIcon/pkTer/pkModel/...); extend prepare() similarly if
// needed. waterSign()/paintTerrIcon() (cosmetic pixel effects) are no-ops.
// needed. waterSign() draws the real improvement/wonder illustration but
// skips the original's per-pixel sky-detecting watermark blend (plain blit
// instead); paintTerrIcon() (cosmetic terrain compositing) is still a no-op.
#include "Help.h"
#include "ui_Help.h"
@@ -808,11 +810,35 @@ void HelpDlg::addTextual(const QString &text)
s.remove(0, p + 1);
continue;
}
if (s.at(0) == QLatin1Char('@')) { // image - not rendered, skip
int p = s.size() >= 2 && s.at(1) == QLatin1Char('@') ? 2 : 1;
while (p < s.size() && s.at(p) != QLatin1Char('\\'))
++p;
s.remove(0, p + 1);
if (s.at(0) == QLatin1Char('@')) { // image
if (s.size() >= 2 && s.at(1) == QLatin1Char('@')) { // generate from icon
int picpix = 0;
int p = 2;
while (p < s.size() && s.at(p) != QLatin1Char('\\')) {
picpix = picpix * 10 + (s.at(p).unicode() - QLatin1Char('0').unicode());
++p;
}
if (picpix < 0 || picpix >= nImp)
picpix = 0;
mainText.addLine(QString(), TextFormat::Illu, picpix);
mainText.lineFeed();
mainText.lineFeed();
s.remove(0, p + 1);
} else { // external image
int p = 1;
while (p < s.size() && s.at(p) != QLatin1Char('\\'))
++p;
if (!extPic)
extPic = std::make_unique<Dpi::Bitmap>();
extPic->loadFromFile(localizedFilePath(QStringLiteral("Help/") + s.mid(1, p - 1) +
QLatin1String(PngExt)));
if (extPic->width() > 0 && extPic->height() > 0) {
mainText.addLine(QString(), TextFormat::External);
for (int i = 0; i <= (extPic->height() - 12) / 24; ++i)
mainText.lineFeed();
}
s.remove(0, p + 1);
}
continue;
}
@@ -1024,6 +1050,11 @@ void HelpDlg::paintTerrIcon(int x, int y, int xSrc, int ySrc)
Q_UNUSED(ySrc);
}
void HelpDlg::waterSign(int x0, int y0, int iix)
{
Term::impImage(offscreen.canvas(), x0, y0, iix);
}
void HelpDlg::offscreenPaint()
{
FramedDlg::offscreenPaint();
@@ -1031,6 +1062,21 @@ void HelpDlg::offscreenPaint()
Dpi::Canvas &canvas = offscreen.canvas();
canvas.begin();
fillSeamless(canvas, 0, 0, innerWidth, innerHeight, 0, scrollBar->position() * 24, paper);
// External illustrations (Help/*.png) are drawn first, behind the text.
if (extPic) {
for (int idx = 0; idx <= scrollBar->position() + innerHeight / 24 && idx < mainText.count(); ++idx) {
if (mainText.info(idx).format != TextFormat::External)
continue;
const int i = idx - scrollBar->position();
int yl = extPic->height();
if (4 + i * 24 + yl > innerHeight)
yl = innerHeight - (4 + i * 24);
if (yl > 0)
bitBltBitmap(offscreen, 8, 4 + i * 24, extPic->width(), yl, *extPic, 0, 0);
}
}
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
for (int i = -2; i <= innerHeight / 24; ++i) {
const int idx = scrollBar->position() + i;
@@ -1038,6 +1084,8 @@ void HelpDlg::offscreenPaint()
continue;
x0[static_cast<std::size_t>(i + 2)] = 8;
line(canvas, i, i == sel);
if (mainText.info(idx).format == TextFormat::Illu)
waterSign(8, i * 24 - 8, mainText.info(idx).picPix);
}
canvas.end();
markUsedOffscreen(innerWidth, innerHeight);
@@ -1052,7 +1100,7 @@ void HelpDlg::resizeEvent(QResizeEvent *event)
void HelpDlg::closeEvent(QCloseEvent *event)
{
// ExtPic.Height := 0; -- the external-link preview bitmap isn't ported.
extPic.reset(); // Help.pas's ExtPic.Height := 0 - free the illustration bitmap.
FramedDlg::closeEvent(event);
}