From 7377c398550edc1fc8176ee4dbcd09d70f80d454 Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Sat, 21 Nov 2020 19:28:13 +0100 Subject: [PATCH] Tracker: make desktop color selection try user color first Change-Id: I47392bdafe8ecf1996886fd0a8324a114f4524fd Reviewed-on: https://review.haiku-os.org/c/haiku/+/3407 Reviewed-by: waddlesplash --- src/kits/tracker/PoseView.cpp | 36 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 1914817dc5..6a714ce21a 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -9035,20 +9035,32 @@ BPoseView::DrawPose(BPose* pose, int32 index, bool fullDraw) rgb_color BPoseView::DeskTextColor() const { - rgb_color color = ViewColor(); - float thresh = color.red + (color.green * 1.25f) + (color.blue * 0.45f); + rgb_color textColor = ui_color(B_DOCUMENT_TEXT_COLOR); + rgb_color viewColor = ViewColor(); - if (thresh >= 360) { - color.red = 0; - color.green = 0; - color.blue = 0; - } else { - color.red = 255; - color.green = 255; - color.blue = 255; + float readabilityThreshold = abs(textColor.red - viewColor.red) + + abs(textColor.green - viewColor.green) + + abs(textColor.blue - viewColor.blue); + if (readabilityThreshold > 120) { + // The readability threshold is highly subjective, but 120 (out of 768) + // seems to be generally suitable for most circumstances. + return textColor; + } else { + float blackWhiteThreshold = viewColor.red + + (viewColor.green * 1.25f) + (viewColor.blue * 0.45f); + + if (blackWhiteThreshold >= 360) { + viewColor.red = 0; + viewColor.green = 0; + viewColor.blue = 0; + } else { + viewColor.red = 255; + viewColor.green = 255; + viewColor.blue = 255; + } + + return viewColor; } - - return color; }