Files
c-evo-evo/game/localplayer/Help.Paint.cpp
T
2026-11-17 12:28:13 +01:00

293 lines
11 KiB
C++

// This file is part of c-evo-evo.
//
// This software is governed by the CeCILL license under French law and
// abiding by the rules of distribution of free software. You can use,
// modify and/or redistribute the software under the terms of the CeCILL
// license as circulated by CEA, CNRS and INRIA at the following URL
// "http://www.cecill.info".
//
// As a counterpart to the access to the source code and rights to copy,
// modify and redistribute granted by the license, users are provided only
// with a limited warranty and the software's author, the holder of the
// economic rights, and the successive licensors have only limited
// liability.
//
// In this respect, the user's attention is drawn to the risks associated
// with loading, using, modifying and/or developing or reproducing the
// software by the user in light of its specific status of free software,
// that may mean that it is complicated to manipulate, and that also
// therefore means that it is reserved for developers and experienced
// professionals having in-depth computer knowledge. Users are therefore
// encouraged to load and test the software's suitability as regards their
// requirements in conditions enabling the security of their systems and/or
// data to be ensured and, more generally, to use and operate it in the
// same conditions as regards security.
//
// The fact that you are presently reading this means that you have had
// knowledge of the CeCILL license and that you accept its terms.
// See the PORT STATUS comment at the top of Help.cpp for how this file fits
// into the overall Help.pas port. This file: offscreenPaint()/line() and
// the real per-TextFormat icon rendering.
#include "Help.h"
#include "ui_Help.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/Protocol.h"
#include "ClientTools.h"
#include "Term.h"
#include "Tribes.h"
namespace Cevo {
namespace Help {
void HelpDlg::line(Dpi::Canvas &canvas, int i, bool lit)
{
const int idx = scrollBar->position() + i;
if (idx < 0 || idx >= mainText.count())
return;
const QString &s = mainText.text(idx);
if (s.isEmpty())
return;
int x = x0[static_cast<std::size_t>(i + 2)];
int y = 2 + i * 24;
if (&canvas != &offscreen.canvas()) {
x += SideFrame;
y += WideFrame;
}
const HelpLineInfo &lineInfo = mainText.info(idx);
const bool isHeader = lineInfo.format == TextFormat::Caption || lineInfo.format == TextFormat::Section;
if (isHeader)
canvas.font().setBold(true);
const QColor textColor = isHeader ? captionColor : colorFromDelphi(0x000000);
biColorTextOut(canvas, textColor, colorFromDelphi(0x7F007F), x, y, s);
if (lit) {
canvas.pen().setColor(textColor);
canvas.moveTo(x + 1, y + 18);
canvas.lineTo(x + biColorTextWidth(canvas, s), y + 18);
}
if (isHeader)
canvas.font().setBold(false);
}
void HelpDlg::paintTerIcon(Dpi::Canvas &canvas, int &x0Ref, int y, int picpix)
{
if (!noMap || !noMap->hGrTerrain)
return;
GraphicSet &hGrTerrain = *noMap->hGrTerrain;
const int xxt = noMap->xxt;
const int yyt = noMap->yyt;
int srcno;
if (picpix >= 3 * 12)
srcno = 2 * 9 + 6;
else if (picpix % 12 == Term::fJungle)
srcno = 18 * 9;
else if (picpix % 12 < Term::fJungle)
srcno = picpix % 12;
else
srcno = 27 + (picpix % 12 - 9) * 18;
const int ofs = x0Ref + 8;
x0Ref = 2 * xxt + 8 + ofs;
const int Y = y + 13;
if (srcno >= Term::fJungle) {
sprite(canvas, hGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
3 + yyt + 2 * (yyt * 3 + 1));
sprite(canvas, hGrTerrain, ofs, Y - 2 * yyt, xxt * 2, yyt * 3 - 2, 1 + srcno % 9 * (xxt * 2 + 1),
1 + srcno / 9 * (yyt * 3 + 1));
} else {
sprite(canvas, hGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8, yyt * 2 - 4, 5 + srcno % 9 * (xxt * 2 + 1),
3 + yyt + srcno / 9 * (yyt * 3 + 1));
}
if (picpix >= 3 * 12) { // rare resource
sprite(canvas, hGrTerrain, ofs, Y - 2 * yyt, xxt * 2, yyt * 3, 1 + 8 * (xxt * 2 + 1),
1 + (picpix - 2 * 12) * (yyt * 3 + 1));
} else if (picpix >= 12) { // special tile
int srcno2;
if (picpix % 12 == Term::fJungle)
srcno2 = 17 * 9 + 8;
else if (picpix % 12 < Term::fJungle)
srcno2 = picpix % 12;
else
srcno2 = 18 + 8 + (picpix % 12 - 9) * 18;
srcno2 += picpix / 12 * 9;
sprite(canvas, hGrTerrain, ofs, Y - 2 * yyt, xxt * 2, yyt * 3, 1 + srcno2 % 9 * (xxt * 2 + 1),
1 + srcno2 / 9 * (yyt * 3 + 1));
}
}
void HelpDlg::paintTerrIcon(int x, int y, int xSrc, int ySrc)
{
if (!noMap || !noMap->hGrTerrain)
return;
GraphicSet &hGrTerrain = *noMap->hGrTerrain;
const int xxt = noMap->xxt;
const int yyt = noMap->yyt;
Dpi::Canvas &canvas = offscreen.canvas();
frame(canvas, x - 1, y - 1, x + xSizeBig, y + ySizeBig, Qt::black, Qt::black);
if (2 * yyt < 40) {
sprite(canvas, hGrTerrain, x, y, 56, 2 * yyt, xSrc, ySrc);
sprite(canvas, hGrTerrain, x, y + 2 * yyt, 56, 40 - 2 * yyt, xSrc, ySrc);
} else {
sprite(canvas, hGrTerrain, x, y, 56, 40, xSrc, ySrc);
}
sprite(canvas, hGrTerrain, x, y, xxt, yyt, xSrc + xxt, ySrc + yyt);
sprite(canvas, hGrTerrain, x, y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc);
sprite(canvas, hGrTerrain, x + xxt, y, 56 - xxt, yyt, xSrc, ySrc + yyt);
sprite(canvas, hGrTerrain, x + xxt, y + yyt, 56 - xxt, 40 - yyt, xSrc, ySrc);
}
void HelpDlg::waterSign(int x0, int y0, int iix)
{
Term::impImage(offscreen.canvas(), x0, y0, iix);
}
void HelpDlg::paintIcon(Dpi::Canvas &canvas, int i)
{
const int idx = scrollBar->position() + i;
if (idx < 0 || idx >= mainText.count())
return;
const HelpLineInfo &info = mainText.info(idx);
const int y = i * 24;
int &x0i = x0[static_cast<std::size_t>(i + 2)];
// Leading link-indicator dot (shown for every clickable line).
if (info.category != LinkCategory::NoLink && HGrSystem) {
if (i == sel)
sprite(canvas, *HGrSystem, 12, y + 5, 14, 14, 65, 20);
else if (info.crossLink)
sprite(canvas, *HGrSystem, 12, y + 5, 14, 14, 80, 1);
else if (!(kind == LinkCategory::Misc && no == static_cast<int>(MiscLinkIndex::Main)))
sprite(canvas, *HGrSystem, 10, y + 6, 14, 14, 65, 1);
x0i = 24;
} else {
x0i = 0;
}
if (!HGrSystem)
return;
switch (info.format) {
case TextFormat::AdvIcon:
case TextFormat::AdvIconAsPreq: {
frame(canvas, 8 - 1 + x0i, 2 - 1 + y, 8 + Term::xSizeSmall + x0i, 2 + Term::ySizeSmall + y, Qt::black,
Qt::black);
const int ai = Term::advIcon[static_cast<std::size_t>(info.picPix)];
if (ai < 84) {
if (Term::smallImp)
bitBltBitmap(offscreen, 8 + x0i, 2 + y, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp,
(ai + Term::SystemIconLines * 7) % 7 * Term::xSizeSmall,
(ai + Term::SystemIconLines * 7) / 7 * Term::ySizeSmall);
} else {
dump(offscreen, *HGrSystem, 8 + x0i, 2 + y, 36, 20, 1 + (ai - 84) % 8 * 37, 295 + (ai - 84) / 8 * 21);
}
const int era = ClientTools::advValue[static_cast<std::size_t>(info.picPix)] / 1000;
bitBltBitmap(offscreen, x0i + 4, 4 + y, 14, 14, HGrSystem->mask, 127 + era * 15, 85, RasterOp::And);
sprite(canvas, *HGrSystem, x0i + 3, 3 + y, 14, 14, 127 + era * 15, 85);
x0i += 8 + 8 + 36;
break;
}
case TextFormat::SmallIcon:
case TextFormat::SmallIconAsPreq: {
frame(canvas, 8 - 1 + x0i, 2 - 1 + y, 8 + Term::xSizeSmall + x0i, 2 + Term::ySizeSmall + y, Qt::black,
Qt::black);
if (Term::smallImp) {
if (info.picPix == imPalace)
bitBltBitmap(offscreen, 8 + x0i, 2 + y, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp, 0,
Term::ySizeSmall);
else
bitBltBitmap(offscreen, 8 + x0i, 2 + y, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp,
info.picPix % 7 * Term::xSizeSmall,
(info.picPix + Term::SystemIconLines * 7) / 7 * Term::ySizeSmall);
}
x0i += 8 + 8 + 36;
break;
}
case TextFormat::Domain:
frame(canvas, 8 - 1 + x0i, 2 - 1 + y, 8 + 36 + x0i, 2 + 20 + y, Qt::black, Qt::black);
dump(offscreen, *HGrSystem, 8 + x0i, 2 + y, 36, 20, 75 + info.picPix * 37, 295);
x0i += 8 + 8 + 36;
break;
case TextFormat::Gov:
frame(canvas, 8 - 1 + x0i, 2 - 1 + y, 8 + Term::xSizeSmall + x0i, 2 + 20 + y, Qt::black, Qt::black);
if (Term::smallImp)
bitBltBitmap(offscreen, 8 + x0i, 2 + y, Term::xSizeSmall, Term::ySizeSmall, *Term::smallImp,
(info.picPix - 1) * Term::xSizeSmall, Term::ySizeSmall);
x0i += 8 + 8 + 36;
break;
case TextFormat::Feature:
darkGradient(canvas, x0i + 8 - 1, 7 + y - 3, 16, 1);
frame(canvas, x0i + 8, 7 + y - 2, x0i + 8 + 13, 7 + y - 2 + 13, QColor(0xC0C0C0), QColor(0xC0C0C0));
sprite(canvas, *HGrSystem, x0i + 8 + 2, 7 + y, 10, 10, 66 + info.picPix % 11 * 11,
137 + info.picPix / 11 * 11);
x0i += 8 + 8 + 2 + 13;
break;
case TextFormat::Model:
if (bigImp)
frameImage(canvas, *bigImp, x0i + 12, y - 7, 56, 40, 0, 0);
if (Tribes::hGrStdUnits)
sprite(canvas, *Tribes::hGrStdUnits, x0i + 8, y - 11, 64, 44, 1 + info.picPix % 10 * 65,
1 + info.picPix / 10 * 49);
x0i += 64 + 8 + 8;
break;
case TextFormat::Ter:
paintTerIcon(canvas, x0i, y, info.picPix);
break;
case TextFormat::Dot:
sprite(canvas, *HGrSystem, x0i + 18, 9 + y, 8, 8, 81, 16);
x0i = 20 + 8 + 4;
break;
case TextFormat::NormalDot:
x0i = 20 + 8 + 4;
break;
default:
break;
}
}
void HelpDlg::offscreenPaint()
{
FramedDlg::offscreenPaint();
captionColor = colorFromDelphi(0xC08040);
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;
if (idx < 0 || idx >= mainText.count())
continue;
paintIcon(canvas, i);
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);
}
} // namespace Help
} // namespace Cevo