pollymc/launcher/ui/ColorCache.cpp

36 lines
786 B
C++
Raw Permalink Normal View History

2015-08-20 05:19:03 +05:30
#include "ColorCache.h"
/**
* Blend the color with the front color, adapting to the back color
*/
QColor ColorCache::blend(QColor color)
{
2018-07-15 18:21:05 +05:30
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);
2015-08-20 05:19:03 +05:30
}
/**
* Blend the color with the back color
*/
QColor ColorCache::blendBackground(QColor color)
{
2018-07-15 18:21:05 +05:30
// adapt contrast
return Rainbow::mix(m_back, color, m_bias);
2015-08-20 05:19:03 +05:30
}
void ColorCache::recolorAll()
{
2018-07-15 18:21:05 +05:30
auto iter = m_colors.begin();
while(iter != m_colors.end())
{
iter->front = blend(iter->original);
iter->back = blendBackground(iter->original);
}
2015-08-20 05:19:03 +05:30
}