new screen tools funcs

This commit is contained in:
Geoffray Levasseur committed 2026-11-03 16:11:48 +01:00
1 parent 4944243acb
commit c98576f0c1
2 files changed
+109

No files matched your search

+97
View File
@@ -504,6 +504,103 @@ void paintProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int pos, int
canvas.brush().setStyle(Qt::NoBrush);
}
void paintRelativeProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int size, int pos, int growth, int max,
bool indicateComplete, const Texture &texture)
{
if (growth > 0)
paintProgressBar(canvas, kind, x, y, pos * size / max, (growth * size + max / 2) / max, size, texture);
else
paintProgressBar(canvas, kind, x, y, pos * size / max, (growth * size - max / 2) / max, size, texture);
if (indicateComplete && pos + growth >= max && HGrSystem)
sprite(canvas, *HGrSystem, x + size - 10, y - 7, 23, 16, 1, 129);
}
void makeBlue(Dpi::Bitmap &dst, int x, int y, int width, int height)
{
Dpi::PixelPointer pixelPtr(&dst.image(), x, y);
for (int yy = 0; yy < height; ++yy) {
for (int xx = 0; xx < width; ++xx) {
const QRgb px = pixelPtr.pixelRGB();
pixelPtr.setPixelRGB(qRgb(qRed(px) / 2, qGreen(px) / 2, qBlue(px) / 2));
pixelPtr.nextPixel();
}
pixelPtr.nextLine();
}
}
void makeRed(Dpi::Bitmap &dst, int x, int y, int width, int height)
{
Dpi::PixelPointer pixelPtr(&dst.image(), x, y);
for (int yy = 0; yy < height; ++yy) {
for (int xx = 0; xx < width; ++xx) {
const QRgb px = pixelPtr.pixelRGB();
const int gray = (qBlue(px) + qGreen(px) + qRed(px)) * 85 >> 8;
pixelPtr.setPixelRGB(qRgb(gray, 0, 0));
pixelPtr.nextPixel();
}
pixelPtr.nextLine();
}
}
void countBar(Dpi::Bitmap &dst, int x, int y, int w, int kind, const QString &cap, int val, const Texture &texture)
{
if (val == 0)
return;
Q_ASSERT(kind >= 0);
if (!HGrSystem)
return;
Dpi::Canvas &canvas = dst.canvas();
const int xIcon = x - 5;
const int yIcon = y + 15;
dLine(canvas, x - 2, xIcon + w + 2, yIcon + 16, texture.colorBevelShade, texture.colorBevelLight);
const QString s = QString::number(val);
const int cl = val < 0 ? 0x0000FF : -1;
loweredTextOut(canvas, cl, texture, x - 2, y, cap);
loweredTextOut(canvas, cl, texture, xIcon + w + 2 - biColorTextWidth(canvas, s), yIcon, s);
int sd, ld;
if (kind == 12 && val >= 100) { // science with symbol for 100
val /= 10;
sd = 14 * (val / 10 + val % 10 - 1);
if (sd == 0)
sd = 1;
ld = sd < w - 44 ? sd : w - 44;
for (int i = 0; i < val % 10; ++i) {
bitBltBitmap(dst, xIcon + 4 + i * (14 * ld / sd), yIcon + 2 + 1, 14, 14, HGrSystem->mask,
67 + kind % 8 * 15, 70 + kind / 8 * 15, RasterOp::And);
sprite(canvas, *HGrSystem, xIcon + 3 + i * (14 * ld / sd), yIcon + 2, 14, 14, 67 + kind % 8 * 15,
70 + kind / 8 * 15);
}
for (int i = 0; i < val / 10; ++i) {
bitBltBitmap(dst, xIcon + 4 + (val % 10) * (14 * ld / sd) + i * (14 * ld / sd), yIcon + 3, 14, 14,
HGrSystem->mask, 67 + 7 % 8 * 15, 70 + 7 / 8 * 15, RasterOp::And);
sprite(canvas, *HGrSystem, xIcon + 3 + (val % 10) * (14 * ld / sd) + i * (14 * ld / sd), yIcon + 2, 14,
14, 67 + 7 % 8 * 15, 70 + 7 / 8 * 15);
}
} else {
val = std::abs(val);
sd = (val % 10 == 0) ? 14 * (val / 10 - 1) : 10 * (val % 10 - 1) + 14 * (val / 10);
if (sd == 0)
sd = 1;
ld = sd < w - 44 ? sd : w - 44;
for (int i = 0; i < val / 10; ++i) {
bitBltBitmap(dst, xIcon + 4 + i * (14 * ld / sd), yIcon + 3, 14, 14, HGrSystem->mask,
67 + kind % 8 * 15, 70 + kind / 8 * 15, RasterOp::And);
sprite(canvas, *HGrSystem, xIcon + 3 + i * (14 * ld / sd), yIcon + 2, 14, 14, 67 + kind % 8 * 15,
70 + kind / 8 * 15);
}
for (int i = 0; i < val % 10; ++i) {
bitBltBitmap(dst, xIcon + 4 + (val / 10) * (14 * ld / sd) + i * (10 * ld / sd), yIcon + 7, 10, 10,
HGrSystem->mask, 66 + kind % 11 * 11, 115 + kind / 11 * 11, RasterOp::And);
sprite(canvas, *HGrSystem, xIcon + 3 + (val / 10) * (14 * ld / sd) + i * (10 * ld / sd), yIcon + 6, 10,
10, 66 + kind % 11 * 11, 115 + kind / 11 * 11);
}
}
}
namespace {
// %c=combat %f=food %l=luxury %m=manufacture %n=nation %o=output