summaryrefslogtreecommitdiffstats
path: root/application/Colors.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-08-19 02:06:32 +0200
committerPetr Mrázek <peterix@gmail.com>2015-08-19 23:52:53 +0200
commit6858f1dd6294a93c1e1ec8007cb0434b53646488 (patch)
tree83656c5ff2ef9aa8d5bf7b2441727282751c78fc /application/Colors.cpp
parent9681f724e5ac0d859c575d093c6dd656a3b9e5c7 (diff)
downloadMultiMC-6858f1dd6294a93c1e1ec8007cb0434b53646488.tar
MultiMC-6858f1dd6294a93c1e1ec8007cb0434b53646488.tar.gz
MultiMC-6858f1dd6294a93c1e1ec8007cb0434b53646488.tar.lz
MultiMC-6858f1dd6294a93c1e1ec8007cb0434b53646488.tar.xz
MultiMC-6858f1dd6294a93c1e1ec8007cb0434b53646488.zip
GH-1197 add console log color adaptation
rainbow library was part of KDE - KGuiAddons
Diffstat (limited to 'application/Colors.cpp')
-rw-r--r--application/Colors.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/application/Colors.cpp b/application/Colors.cpp
new file mode 100644
index 00000000..8812c93d
--- /dev/null
+++ b/application/Colors.cpp
@@ -0,0 +1,26 @@
+#include "Colors.h"
+
+/**
+ * Blend the color with the front color, adapting to the back color
+ */
+QColor Color::blend(QColor front, QColor back, QColor color, uchar ratio)
+{
+ Q_ASSERT(front.isValid());
+ Q_ASSERT(back.isValid());
+ if (Rainbow::luma(front) > Rainbow::luma(back))
+ {
+ // for dark color schemes, produce a fitting color first
+ color = Rainbow::tint(front, color, 0.5);
+ }
+ // adapt contrast
+ return Rainbow::mix(front, color, float(ratio) / float(0xff));
+}
+
+/**
+ * Blend the color with the back color
+ */
+QColor Color::blendBackground(QColor back, QColor color, uchar ratio)
+{
+ // adapt contrast
+ return Rainbow::mix(back, color, float(ratio) / float(0xff));
+}