add gradient func
This commit is contained in:
1 parent
60958fa28e
commit
6513c6f8ec
2 files changed
+58
No files matched your search
@@ -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
|
// ScreenTools.pas's TurnToYear(): maps a game turn to a calendar year
|
||||||
// (negative = BC), using the same variable-length-era table as the original.
|
// (negative = BC), using the same variable-length-era table as the original.
|
||||||
int turnToYear(int turn);
|
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
|
} // namespace Cevo
|
||||||
@@ -705,4 +705,54 @@ int turnToYear(int turn)
|
|||||||
return result;
|
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
|
} // namespace Cevo
|
||||||
Reference in new issue
Block a user