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 // (Imp/Ter/Feature/Model/Text) still render a plain placeholder paragraph
// instead of the original's full icon-rich, per-TextFormat layout engine // instead of the original's full icon-rich, per-TextFormat layout engine
// (pkAdvIcon/pkBigIcon/pkTer/pkModel/...); extend prepare() similarly if // (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 "Help.h"
#include "ui_Help.h" #include "ui_Help.h"
@@ -808,11 +810,35 @@ void HelpDlg::addTextual(const QString &text)
s.remove(0, p + 1); s.remove(0, p + 1);
continue; continue;
} }
if (s.at(0) == QLatin1Char('@')) { // image - not rendered, skip if (s.at(0) == QLatin1Char('@')) { // image
int p = s.size() >= 2 && s.at(1) == QLatin1Char('@') ? 2 : 1; if (s.size() >= 2 && s.at(1) == QLatin1Char('@')) { // generate from icon
while (p < s.size() && s.at(p) != QLatin1Char('\\')) int picpix = 0;
++p; int p = 2;
s.remove(0, p + 1); 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; continue;
} }
@@ -1024,6 +1050,11 @@ void HelpDlg::paintTerrIcon(int x, int y, int xSrc, int ySrc)
Q_UNUSED(ySrc); Q_UNUSED(ySrc);
} }
void HelpDlg::waterSign(int x0, int y0, int iix)
{
Term::impImage(offscreen.canvas(), x0, y0, iix);
}
void HelpDlg::offscreenPaint() void HelpDlg::offscreenPaint()
{ {
FramedDlg::offscreenPaint(); FramedDlg::offscreenPaint();
@@ -1031,6 +1062,21 @@ void HelpDlg::offscreenPaint()
Dpi::Canvas &canvas = offscreen.canvas(); Dpi::Canvas &canvas = offscreen.canvas();
canvas.begin(); canvas.begin();
fillSeamless(canvas, 0, 0, innerWidth, innerHeight, 0, scrollBar->position() * 24, paper); 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)]); canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
for (int i = -2; i <= innerHeight / 24; ++i) { for (int i = -2; i <= innerHeight / 24; ++i) {
const int idx = scrollBar->position() + i; const int idx = scrollBar->position() + i;
@@ -1038,6 +1084,8 @@ void HelpDlg::offscreenPaint()
continue; continue;
x0[static_cast<std::size_t>(i + 2)] = 8; x0[static_cast<std::size_t>(i + 2)] = 8;
line(canvas, i, i == sel); line(canvas, i, i == sel);
if (mainText.info(idx).format == TextFormat::Illu)
waterSign(8, i * 24 - 8, mainText.info(idx).picPix);
} }
canvas.end(); canvas.end();
markUsedOffscreen(innerWidth, innerHeight); markUsedOffscreen(innerWidth, innerHeight);
@@ -1052,7 +1100,7 @@ void HelpDlg::resizeEvent(QResizeEvent *event)
void HelpDlg::closeEvent(QCloseEvent *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); FramedDlg::closeEvent(event);
} }
+13 -8
View File
@@ -37,6 +37,7 @@
#include <array> #include <array>
#include <functional> #include <functional>
#include <memory>
#include <vector> #include <vector>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -45,6 +46,10 @@ class HelpDlg;
} }
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Dpi {
class Bitmap;
}
namespace Cevo { namespace Cevo {
namespace Help { namespace Help {
@@ -161,14 +166,11 @@ private:
void search(const QString &searchString); void search(const QString &searchString);
void line(Dpi::Canvas &canvas, int i, bool lit); void line(Dpi::Canvas &canvas, int i, bool lit);
void paintTerrIcon(int x, int y, int xSrc, int ySrc); void paintTerrIcon(int x, int y, int xSrc, int ySrc);
// Placeholder for the original's pixel-level water-reflection effect // Help.pas's WaterSign(): draws a big improvement/wonder illustration.
// on wonder/illustration icons - purely cosmetic, not yet ported. // Simplified from the original's per-pixel sky-detecting watermark blend
void waterSign(int x0, int y0, int iix) // (2x upscaled, faded into the paper background) to a plain icon blit -
{ // still shows the real illustration, just without the blend effect.
Q_UNUSED(x0); void waterSign(int x0, int y0, int iix);
Q_UNUSED(y0);
Q_UNUSED(iix);
}
void backBtnClicked(); void backBtnClicked();
void topBtnClicked(); void topBtnClicked();
void searchBtnClicked(); void searchBtnClicked();
@@ -182,6 +184,9 @@ private:
HyperText mainText; HyperText mainText;
HyperText searchResult; HyperText searchResult;
StringTable helpText; StringTable helpText;
// Help.pas's ExtPic: the single external illustration bitmap (Help/*.png)
// referenced by the currently displayed page's "@filename\" markup.
std::unique_ptr<Dpi::Bitmap> extPic;
std::vector<HistItem> histItems; std::vector<HistItem> histItems;
PVScrollBar *scrollBar; PVScrollBar *scrollBar;
std::array<int, 183> x0{}; // x0[-2..180], offset by +2 std::array<int, 183> x0{}; // x0[-2..180], offset by +2