LibGfx: Add color helper for getting shades and tints

Shades are colors darker than the color, tints are colors lighter.
This is helpful in places where we need a bunch of similar colors
with some small differences.
This commit is contained in:
Nicholas Hollett 2021-08-31 01:48:03 +01:00 committed by Andreas Kling
parent 60e27dea9c
commit 4fe380f6da
Notes: sideshowbarker 2024-07-18 05:02:37 +09:00

View file

@ -237,6 +237,30 @@ public:
return Color(min(255, (int)((float)red() * amount)), min(255, (int)((float)green() * amount)), min(255, (int)((float)blue() * amount)), alpha());
}
Vector<Color> shades(u32 steps, float max = 1.f) const
{
float shade = 1.f;
float step = max / steps;
Vector<Color> shades;
for (u32 i = 0; i < steps; i++) {
shade -= step;
shades.append(this->darkened(shade));
}
return shades;
}
Vector<Color> tints(u32 steps, float max = 1.f) const
{
float shade = 1.f;
float step = max / steps;
Vector<Color> tints;
for (u32 i = 0; i < steps; i++) {
shade += step;
tints.append(this->lightened(shade));
}
return tints;
}
constexpr Color inverted() const
{
return Color(~red(), ~green(), ~blue(), alpha());