Menu

#870 Bad slider updates w/256 color display

obsolete: 8.2b2
open
5
2004-03-30
2000-11-01
No

OriginalBugID: 2567 Bug
Version: 8.2b2
SubmitDate: '1999-08-18'
LastModified: '2000-01-03'
Severity: SER
Status: UnAssn
Submitter: techsupp
ChangedBy: hobbs
OS: Windows 98
Machine: X86

Name:
Christopher Nelson

ReproducibleScript:
namespace eval ::brightness {
namespace export main

# "global" array(s)
variable Brightness
}

proc brightness::main { w } {
variable Brightness

#----------------------------------------
# Control overall brightness
set brightctrl [frame $w.brightness]
pack $w.brightness -side top -padx 1m -pady 1m
Scale $brightctrl.w "" brightness "#000000000000" "#ffffffffffff"
set brightScale $brightctrl.w
pack $brightctrl.w -side top -expand 1 -fill x -anchor n
set Brightness(current,brightness) 0

#----------------------------------------
# Control color balance
set colorctrl [frame $w.balance]
pack $w.balance -side top -padx 1m -pady 1m
Scale $colorctrl.r Red rBalance "#000000000000" "#ffff00000000"
Scale $colorctrl.g Green gBalance "#000000000000" "#0000ffff0000"
Scale $colorctrl.b Blue bBalance "#000000000000" "#00000000ffff"
pack $colorctrl.r $colorctrl.g $colorctrl.b -side top -expand 1
-fill x

foreach balance { r g b } {
#set Brightness(current,${balance}Balance) 0
trace variable brightness::Brightness(current,${balance}Balance)
w [namespace code [list TraceBalance $colorctrl.r.scale $colorctrl.g.scale $colorctrl.b.scale
$brightScale.scale]]
}

}
# brightness::tab
#
# brightness::Scale --
#
# Create a scale and an entry to control one component
# (brightness, or red, green, or blue balance).
#
# Arguments:
# w - Frame to create with the scale and entry in it
# label - Label for the scale
# variable - Variable to associate with the scale and entry
# color - Color for the scale's trough
# balance - Color balance for the scale's trough
#
# Results:
#
proc brightness::Scale { w label index minColor maxColor } {
variable Brightness

# Create the outer frame
frame $w

set Brightness($w.scale,minColor) $minColor
set Brightness($w.scale,maxColor) $maxColor
lappend Brightness(dynamicWidgets) $w.scale

set color [InterpolateColor -100 $minColor 100 $maxColor 0]

# Put a scale in it.
scale $w.scale -from -100 -to 100 -orient horizontal -length 6i -width .25i -variable brightness::Brightness(current,$index) -highlightthickness 0 -troughcolor $color -showvalue 0
if {[string length $label]} {
$w.scale configure -label $label
} else {
$w.scale configure -tickinterval 100.0
}
pack $w.scale -side left -anchor s

# Whenever the variable changes, update the color of the scale
trough.
# Note: the variable may change via scale or entry
trace variable brightness::Brightness(current,$index) w [namespace code [list TraceScaleValue $w.scale]]

# The range on the scale limits the range of the variable so we
# don't have to do anything to limit the range of the variable when
# users type in illegal values (e.g, 999)
# Need room for "-100"
entry $w.entry -textvariable brightness::Brightness(current,$index) -width 4

# Pack the entry so it lines up with the trough
if {[$w.scale cget -tickinterval] == 0.0} {
pack $w.entry -side left -anchor s -pady .5m
} else {
set font [$w.scale cget -font]
pack $w.entry -side left -anchor s -pady [expr {5+[font metrics $font -linespace]}]
}
}
# brightness::Scale
#
proc brightness::TraceScaleValue { scale args } {
variable Brightness
# Get min, max, current value of scale
set from [$scale cget -from]
set to [$scale cget -to]
set value [$scale get]

set color [InterpolateColor $from $Brightness($scale,minColor) $to $Brightness($scale,maxColor) $value]

$scale configure -troughcolor $color
}
#-----------------------------------------------------------------------

# Turn {r g b} into #rrrrggggbbbb
proc brightness::MakeColor { rgb } {
set color "#"
foreach component $rgb {
if {$component > 65535.0} {
set component 65535.0
}
append color [format "%04x" [expr {int($component)}]]
}
return $color
}

# Get the color representing value from a max and min value and their
# corresponding colors
proc brightness::InterpolateColor {
minValue minColor maxValue maxColor value
} {
set minRGB [winfo rgb . $minColor]
set maxRGB [winfo rgb . $maxColor]

# For each component, do a linear interpolation:
# minValue value maxValue
# -------- = ----- = --------
# minComp ? maxComp
#
# Which gives:
#
# value - minValue comp - minComp
# ------------------- = -----------------
# maxValue - minValue maxComp - minComp
#
# and then:
#
# / value - minValue # comp = minComp + | ------------------- * (maxComp - minComp) |
# \ maxValue - minValue /
set newRGB {}
foreach minComp $minRGB maxComp $maxRGB {
if {$minComp == $maxComp} {
set comp $minComp
} else {
set ratio [expr
{double($value-$minValue)/($maxValue-$minValue)}]
set comp [expr {$minComp+($ratio*($maxComp-$minComp))}]
}
lappend newRBG $comp
}

return [MakeColor $newRBG]
}
# brightness::InterpolateColor

#-----------------------------------------------------------------------

# Balance adjustments
proc brightness::TraceBalance { rScale gScale bScale wScale args } {
variable Brightness
# Compute the components of the composite color sample
set max 0
foreach component {r g b} {
set from [[set ${component}Scale] cget -from]
set to [[set ${component}Scale] cget -to]
set value [[set ${component}Scale] get]

set percent [expr {double($value-$from)/($to-$from)}]
set $component [expr {$percent * 65535}]

if {[set $component] > $max} {
set max [set $component]
}
}

# Normalize the components (make max 65535)
foreach component {r g b} {
set $component [expr {[set $component]/$max * 65535}]
}
# Build a color from the normalized components
set color [MakeColor [list $r $g $b]]

# Set the maximum color of the composite bar's trough to the new
color
set Brightness($wScale,maxColor) $color

# Update the composite scroll bar's trough color
TraceScaleValue $wScale
}
# brightness::TraceBalance

brightness::main ""

ObservedBehavior:
On at least W95 and W98, in Tcl 8.0, 8.1, and 8.2b2 when the script is
run on a 256 color display, moving one of the R, G, or B scales colors
others. The others retain the wrong color until the mouse pointer is
dragged through them. With 16 bit or Truecolor, there is no problem.
It also seems to be OK on NT (this per a report to me by a co-worker, I
haven't verified this for myself).

DesiredBehavior:
Dragging one of the R, G, or B scales should not affect the other two.

Discussion

  • Don Porter

    Don Porter - 2001-03-23
    • labels: 104344 --> 15. [scale]
     
  • Don Porter

    Don Porter - 2003-11-12
    • assigned_to: nobody --> das
     
  • Daniel A. Steffen

    Logged In: YES
    user_id=90580

    reassigning to win [scale] maintainer

     
  • Daniel A. Steffen

    • assigned_to: das --> hobbs