mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +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
Notes:
sideshowbarker
2024-07-18 05:02:37 +09:00
Author: https://github.com/niax Commit: https://github.com/SerenityOS/serenity/commit/4fe380f6da3 Pull-request: https://github.com/SerenityOS/serenity/pull/9634 Reviewed-by: https://github.com/awesomekling
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());
|
||||
}
|
||||
|
||||
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());
|
||||
|
|
Loading…
Reference in a new issue