diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2001-11-29 10:54:21 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2001-11-29 10:54:21 (GMT) |
commit | a0adf6f6c7a9981a96a7effcfeaba15b12e5206b (patch) | |
tree | f430a3fe1a6fdfc5207db1951a73e2a740d689fb /library/palette.tcl | |
parent | f4767992165feb9196b4c3504330b9178d7ab824 (diff) | |
download | tk-a0adf6f6c7a9981a96a7effcfeaba15b12e5206b.zip tk-a0adf6f6c7a9981a96a7effcfeaba15b12e5206b.tar.gz tk-a0adf6f6c7a9981a96a7effcfeaba15b12e5206b.tar.bz2 |
Made tk_setPalette guess a reasonable default for the foreground colour.
Diffstat (limited to 'library/palette.tcl')
-rw-r--r-- | library/palette.tcl | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/library/palette.tcl b/library/palette.tcl index 7542ef5..55834d3 100644 --- a/library/palette.tcl +++ b/library/palette.tcl @@ -3,7 +3,7 @@ # This file contains procedures that change the color palette used # by Tk. # -# RCS: @(#) $Id: palette.tcl,v 1.7 2001/11/15 14:02:47 dkf Exp $ +# RCS: @(#) $Id: palette.tcl,v 1.8 2001/11/29 10:54:21 dkf Exp $ # # Copyright (c) 1995-1997 Sun Microsystems, Inc. # @@ -40,10 +40,18 @@ proc ::tk_setPalette {args} { if {![info exists new(background)]} { error "must specify a background color" } + set bg [winfo rgb . $new(background)] if {![info exists new(foreground)]} { - set new(foreground) black + # Note that the range of each value in the triple returned by + # [winfo rgb] is 0-65535, and your eyes are more sensitive to + # green than to red, and more to red than to blue. + foreach {r g b} $bg {break} + if {$r+1.5*$g+0.5*$b > 100000} { + set new(foreground) black + } else { + set new(foreground) white + } } - set bg [winfo rgb . $new(background)] set fg [winfo rgb . $new(foreground)] set darkerBg [format #%02x%02x%02x [expr {(9*[lindex $bg 0])/2560}] \ [expr {(9*[lindex $bg 1])/2560}] [expr {(9*[lindex $bg 2])/2560}]] |