mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
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:
parent
60e27dea9c
commit
4fe380f6da
1 changed files with 24 additions and 0 deletions
|
@ -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());
|
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
|
constexpr Color inverted() const
|
||||||
{
|
{
|
||||||
return Color(~red(), ~green(), ~blue(), alpha());
|
return Color(~red(), ~green(), ~blue(), alpha());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue