[PATCH] gitk: Improve readability of highlighted text

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Selected text is indicated by displaying a rectangle under the selected
text. When the default background color of dark blue is used for the
selection rectangle, it does not have sufficient contrast with the default
text color of black, and the highlighted text cannot be read easily.

To fix this, determine the HSV value of the selection background color.
Then, set the color of the selected text based on that value -- white if
the value is less than 0.6, black otherwise. This ensures that there is
sufficent contrast to make the text readable over the background color.
Also tag all selected text with secseltext, so that it can be reverted to
the default color on a change of selection.
---
 gitk | 44 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/gitk b/gitk
index 9a2daf3..0a5423a 100755
--- a/gitk
+++ b/gitk
@@ -2464,7 +2464,8 @@ proc makewindow {} {
     pack .bright.sb -side right -fill y
     pack $cflist -side left -fill both -expand 1
     $cflist tag configure highlight \
-	-background [$cflist cget -selectbackground]
+	-background [$cflist cget -selectbackground] \
+	-foreground [getseltextcolor [$cflist cget -selectbackground]]
     $cflist tag configure bold -font mainfontbold
 
     .pwbottom add .bright
@@ -7188,21 +7189,44 @@ proc dispnexttag {} {
 }
 
 proc make_secsel {id} {
-    global linehtag linentag linedtag canv canv2 canv3
+    global linehtag linentag linedtag canv canv2 canv3 fgcolor
 
     if {![info exists linehtag($id)]} return
-    $canv delete secsel
+
+    allcanvs delete secsel
+
+    set textfill [getseltextcolor [$canv cget -selectbackground]]
+    foreach t [$canv find withtag secseltext] {
+	$canv itemconf $t -fill $fgcolor
+	$canv dtag $t secseltext
+    }
     set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \
 	       -tags secsel -fill [$canv cget -selectbackground]]
     $canv lower $t
+    $canv itemconf $linehtag($id) -fill $textfill
+    $canv addtag secseltext withtag $linehtag($id)
+
+    foreach t [$canv2 find withtag secseltext] {
+	$canv2 itemconf $t -fill $fgcolor
+	$canv2 dtag $t secseltext
+    }
     $canv2 delete secsel
     set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \
 	       -tags secsel -fill [$canv2 cget -selectbackground]]
     $canv2 lower $t
+    $canv2 itemconf $linentag($id) -fill $textfill
+    $canv2 addtag secseltext withtag $linentag($id)
+
+    foreach t [$canv3 find withtag secseltext] {
+	$canv3 itemconf $t -fill $fgcolor
+	$canv3 dtag $t secseltext
+    }
     $canv3 delete secsel
     set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \
 	       -tags secsel -fill [$canv3 cget -selectbackground]]
     $canv3 lower $t
+    $canv3 itemconf $linedtag($id) -fill $textfill
+    $canv3 addtag secseltext withtag $linedtag($id)
 }
 
 proc make_idmark {id} {
@@ -11529,14 +11553,26 @@ proc choosecolor {v vi w x cmd} {
     eval $cmd $c
 }
 
+proc getseltextcolor {c} {
+    # Get the largest RGB value -- this is the V in HSV
+    set value [lindex [lsort -integer [winfo rgb . $c]] end]
+
+    # If the normalized value is darker than 0.6 use white text,
+    # otherwise use black text
+    return [expr ($value < (65535 * .6))?"white":"black"]
+}
+
 proc setselbg {c} {
     global bglist cflist
     foreach w $bglist {
 	$w configure -selectbackground $c
     }
+    set textfill [getseltextcolor $c]
     $cflist tag configure highlight \
-	-background [$cflist cget -selectbackground]
+	-background [$cflist cget -selectbackground] \
+	-foreground $textfill
     allcanvs itemconf secsel -fill $c
+    allcanvs itemconf secseltext -fill $textfill
 }
 
 # This sets the background color and the color scheme for the whole UI.
-- 
1.9.0.msysgit.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]