From d0e88011dc025a1e68964a9363cece66c677969f Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Thu, 20 Aug 2015 01:49:03 +0200 Subject: GH-1197 finish color stuff --- application/ColorCache.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 application/ColorCache.cpp (limited to 'application/ColorCache.cpp') diff --git a/application/ColorCache.cpp b/application/ColorCache.cpp new file mode 100644 index 00000000..e216b597 --- /dev/null +++ b/application/ColorCache.cpp @@ -0,0 +1,35 @@ +#include "ColorCache.h" + + +/** + * Blend the color with the front color, adapting to the back color + */ +QColor ColorCache::blend(QColor color) +{ + if (Rainbow::luma(m_front) > Rainbow::luma(m_back)) + { + // for dark color schemes, produce a fitting color first + color = Rainbow::tint(m_front, color, 0.5); + } + // adapt contrast + return Rainbow::mix(m_front, color, m_bias); +} + +/** + * Blend the color with the back color + */ +QColor ColorCache::blendBackground(QColor color) +{ + // adapt contrast + return Rainbow::mix(m_back, color, m_bias); +} + +void ColorCache::recolorAll() +{ + auto iter = m_colors.begin(); + while(iter != m_colors.end()) + { + iter->front = blend(iter->original); + iter->back = blendBackground(iter->original); + } +} -- cgit