From 6513c6f8ec825a8b56991e717f4896368c5c3fa3 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Tue, 3 Nov 2026 14:17:15 +0100 Subject: [PATCH] add gradient func --- widget/include/Cevo/CevoScreenTools.h | 8 +++++ widget/src/CevoScreenTools.cpp | 50 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/widget/include/Cevo/CevoScreenTools.h b/widget/include/Cevo/CevoScreenTools.h index 8a6d936..5b317c3 100644 --- a/widget/include/Cevo/CevoScreenTools.h +++ b/widget/include/Cevo/CevoScreenTools.h @@ -197,5 +197,13 @@ void imageOpCCC(Dpi::Bitmap &bmp, int x, int y, int width, int height, int color // ScreenTools.pas's TurnToYear(): maps a game turn to a calendar year // (negative = BC), using the same variable-length-era table as the original. int turnToYear(int turn); +// ScreenTools.pas's MovementToString(): formats a x100-scaled movement +// points value as e.g. "1.5" / "12.75". +QString movementToString(int movement); +// ScreenTools.pas's LightGradient()/DarkGradient(): a 16-step horizontal +// brightness gradient starting at `color` (LightGradient) or the HGrSystem +// swatch at row 137+kind (DarkGradient), ending in a black L-shaped border. +void lightGradient(Dpi::Canvas &canvas, int x, int y, int width, QColor color); +void darkGradient(Dpi::Canvas &canvas, int x, int y, int width, int kind); } // namespace Cevo diff --git a/widget/src/CevoScreenTools.cpp b/widget/src/CevoScreenTools.cpp index 7f7c7d9..d1ba0c8 100644 --- a/widget/src/CevoScreenTools.cpp +++ b/widget/src/CevoScreenTools.cpp @@ -705,4 +705,54 @@ int turnToYear(int turn) return result; } +QString movementToString(int movement) +{ + QString result; + if (movement >= 1000) { + result += QChar(QLatin1Char('0').unicode() + movement / 1000); + movement %= 1000; + } + result += QChar(QLatin1Char('0').unicode() + movement / 100); + movement %= 100; + if (movement > 0) { + result += QLatin1Char('.'); + result += QChar(QLatin1Char('0').unicode() + movement / 10); + movement %= 10; + if (movement > 0) + result += QChar(QLatin1Char('0').unicode() + movement); + } + return result; +} + +namespace { +void gradient(Dpi::Canvas &canvas, int x, int y, int dx, int dy, int width, int height, QColor color, + const int (&brightness)[16]) +{ + auto clamp = [](int v) { return v < 0 ? 0 : (v >= 256 ? 255 : v); }; + for (int i = 0; i < 16; ++i) { + canvas.pen().setColor(QColor(clamp(color.red() + brightness[i]), clamp(color.green() + brightness[i]), + clamp(color.blue() + brightness[i]))); + canvas.moveTo(x + dx * i, y + dy * i); + canvas.lineTo(x + dx * i + width, y + dy * i + height); + } + canvas.pen().setColor(Qt::black); + canvas.moveTo(x + 1, y + 16 * dy + height); + canvas.lineTo(x + 16 * dx + width, y + 16 * dy + height); + canvas.lineTo(x + 16 * dx + width, y); +} +} // namespace + +void lightGradient(Dpi::Canvas &canvas, int x, int y, int width, QColor color) +{ + static constexpr int brightness[16] = { 16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44 }; + gradient(canvas, x, y, 0, 1, width, 0, color, brightness); +} + +void darkGradient(Dpi::Canvas &canvas, int x, int y, int width, int kind) +{ + static constexpr int brightness[16] = { 16, 12, 8, 4, 0, -4, -8, -36, 0, -20, -24, -28, -32, -36, -40, -44 }; + const QColor color = HGrSystem ? HGrSystem->data.image().pixelColor(187, 137 + kind) : QColor(Qt::black); + gradient(canvas, x, y, 0, 1, width, 0, color, brightness); +} + } // namespace Cevo