summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--library/palette.tcl14
2 files changed, 17 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5df447c..6da7c18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-11-29 Donal K. Fellows <fellowsd@cs.man.ac.uk>
+
+ * library/palette.tcl (tk_setPalette): Added heuristic to guess
+ from the background whether to use black or white for the
+ foreground when not told specifically. Suggested by Chris Nelson.
+
2001-11-27 David Gravereaux <davygrvy@pobox.com>
* win/makefile.vc: Fixed CAT32 target. cat.c is located in the Tcl
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}]]