aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Geometry.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-09-15 09:36:45 +1000
committerNeil <nyamatongwe@gmail.com>2021-09-15 09:36:45 +1000
commitd4a5d7d6955982496ba523a439fc98276a28e2d8 (patch)
treef9cd5e2a57e247dc59f47404cfea8469cc74b35c /src/Geometry.cxx
parentda71ace9e135d3494fafa7d67483ff1c217faa04 (diff)
downloadscintilla-mirror-d4a5d7d6955982496ba523a439fc98276a28e2d8.tar.gz
Move colour mixing implementations into implementation file.
Avoids some warnings but drops constexpr. Use MixedWith in PlatWin for GDI instead of local implementation. Add unit tests for Geometry.
Diffstat (limited to 'src/Geometry.cxx')
-rw-r--r--src/Geometry.cxx24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Geometry.cxx b/src/Geometry.cxx
index afdc5d161..97e99d431 100644
--- a/src/Geometry.cxx
+++ b/src/Geometry.cxx
@@ -12,6 +12,14 @@
#include "Geometry.h"
+namespace {
+
+constexpr unsigned int Mixed(unsigned char a, unsigned char b, double proportion) noexcept {
+ return static_cast<unsigned int>(a + proportion * (b - a));
+}
+
+}
+
namespace Scintilla::Internal {
PRectangle Clamp(PRectangle rc, Edge edge, XYPOSITION position) noexcept {
@@ -95,4 +103,20 @@ PRectangle PixelAlignOutside(const PRectangle &rc, int pixelDivisions) noexcept
std::floor(rc.bottom * pixelDivisions) / pixelDivisions);
}
+ColourRGBA ColourRGBA::MixedWith(ColourRGBA other) const noexcept {
+ const unsigned int red = (GetRed() + other.GetRed()) / 2;
+ const unsigned int green = (GetGreen() + other.GetGreen()) / 2;
+ const unsigned int blue = (GetBlue() + other.GetBlue()) / 2;
+ const unsigned int alpha = (GetAlpha() + other.GetAlpha()) / 2;
+ return ColourRGBA(red, green, blue, alpha);
+}
+
+ColourRGBA ColourRGBA::MixedWith(ColourRGBA other, double proportion) const noexcept {
+ return ColourRGBA(
+ Mixed(GetRed(), other.GetRed(), proportion),
+ Mixed(GetGreen(), other.GetGreen(), proportion),
+ Mixed(GetBlue(), other.GetBlue(), proportion),
+ Mixed(GetAlpha(), other.GetAlpha(), proportion));
+}
+
}