From c98576f0c1c6d8ac6b9a7cd1c20fa89a05322954 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 16:11:48 +0100 Subject: [PATCH] new screen tools funcs --- widget/include/Cevo/CevoScreenTools.h | 12 ++++ widget/src/CevoScreenTools.cpp | 97 +++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index 10f2ae3..1020d8a 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -182,6 +182,18 @@ void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int heig // `growth` more pixels animating in (negative: shrinking), out of `max`. void paintProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int pos, int growth, int max, const Texture &texture); +// Same as paintProgressBar, but pos/growth/max are expressed relative to a +// `size`-pixel-wide bar instead of raw pixel counts; optionally draws a +// "complete" checkmark sprite when pos+growth reaches max. +void paintRelativeProgressBar(Dpi::Canvas &canvas, int kind, int x, int y, int size, int pos, int growth, int max, + bool indicateComplete, const Texture &texture); +// Darkens dst's [x,y,width,height) region to half brightness per channel. +void makeBlue(Dpi::Bitmap &dst, int x, int y, int width, int height); +// Converts dst's [x,y,width,height) region to a greyscale-derived red tint. +void makeRed(Dpi::Bitmap &dst, int x, int y, int width, int height); +// Draws a labelled HGrSystem icon-bar count (e.g. "Food +3") at (x,y), +// `val` icons wide (tens-icon then ones-icon), capped to fit within `w`. +void countBar(Dpi::Bitmap &dst, int x, int y, int w, int kind, const QString &cap, int val, const Texture &texture); void biColorTextOut(Dpi::Canvas &canvas, QColor mainColor, QColor backColor, int x, int y, const QString &text); int biColorTextWidth(Dpi::Canvas &canvas, const QString &text); diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index 69479c7..67a37cd 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -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