From 06bf4367ac6d71d162389619b8dd574bce1ba320 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 14 May 2021 13:33:56 +1000 Subject: Add method to mix colours in a proportion. --- src/Geometry.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/Geometry.h b/src/Geometry.h index a6e49ad5b..e28cf861e 100644 --- a/src/Geometry.h +++ b/src/Geometry.h @@ -167,6 +167,9 @@ PRectangle PixelAlignOutside(const PRectangle &rc, int pixelDivisions) noexcept; constexpr const float componentMaximum = 255.0f; class ColourAlpha { int co; + constexpr static unsigned int Mixed(unsigned char a, unsigned char b, double proportion) noexcept { + return static_cast(a + proportion * (b - a)); + } public: constexpr explicit ColourAlpha(int co_ = 0) noexcept : co(co_) { } @@ -242,6 +245,14 @@ public: const unsigned int alpha = (GetAlpha() + other.GetAlpha()) / 2; return ColourAlpha(red, green, blue, alpha); } + + constexpr ColourAlpha MixedWith(ColourAlpha other, double proportion) const noexcept { + return ColourAlpha( + Mixed(GetRed(), other.GetRed(), proportion), + Mixed(GetGreen(), other.GetGreen(), proportion), + Mixed(GetBlue(), other.GetBlue(), proportion), + Mixed(GetAlpha(), other.GetAlpha(), proportion)); + } }; /** -- cgit v1.2.3