From 4fe380f6da394fdcb1e755c30c0773024a3aaf7e Mon Sep 17 00:00:00 2001 From: Nicholas Hollett Date: Tue, 31 Aug 2021 01:48:03 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/Color.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index 76df0b8b85..ab459e6284 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -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 shades(u32 steps, float max = 1.f) const + { + float shade = 1.f; + float step = max / steps; + Vector shades; + for (u32 i = 0; i < steps; i++) { + shade -= step; + shades.append(this->darkened(shade)); + } + return shades; + } + + Vector tints(u32 steps, float max = 1.f) const + { + float shade = 1.f; + float step = max / steps; + Vector 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());