| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | namespace eval ::tk {} |
| | namespace eval ::tk::dialog {} |
| | namespace eval ::tk::dialog::color { |
| | namespace import ::tk::msgcat::* |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color:: {args} { |
| | variable ::tk::Priv |
| | set dataName __tk__color |
| | upvar ::tk::dialog::color::$dataName data |
| | set w .$dataName |
| |
|
| | |
| | |
| | set data(lines,red,start) 0 |
| | set data(lines,red,last) -1 |
| | set data(lines,green,start) 0 |
| | set data(lines,green,last) -1 |
| | set data(lines,blue,start) 0 |
| | set data(lines,blue,last) -1 |
| |
|
| | |
| | |
| | |
| | |
| | set data(NUM_COLORBARS) 16 |
| |
|
| | |
| | |
| | set data(BARS_WIDTH) 160 |
| |
|
| | |
| | |
| | |
| | set data(PLGN_HEIGHT) 10 |
| |
|
| | |
| | |
| | set data(PLGN_WIDTH) 10 |
| |
|
| | Config $dataName $args |
| | InitValues $dataName |
| |
|
| | set sc [winfo screen $data(-parent)] |
| | set winExists [winfo exists $w] |
| | if {!$winExists || $sc ne [winfo screen $w]} { |
| | if {$winExists} { |
| | destroy $w |
| | } |
| | toplevel $w -class TkColorDialog -screen $sc |
| | if {[tk windowingsystem] eq "x11"} {wm attributes $w -type dialog} |
| | BuildDialog $w |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | if {[winfo viewable [winfo toplevel $data(-parent)]] } { |
| | wm transient $w $data(-parent) |
| | } |
| |
|
| | |
| | |
| | |
| |
|
| | ::tk::PlaceWindow $w widget $data(-parent) |
| | wm title $w $data(-title) |
| |
|
| | |
| |
|
| | ::tk::SetFocusGrab $w $data(okBtn) |
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | vwait ::tk::Priv(selectColor) |
| | set result $Priv(selectColor) |
| | ::tk::RestoreFocusGrab $w $data(okBtn) |
| | unset data |
| |
|
| | return $result |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::InitValues {dataName} { |
| | upvar ::tk::dialog::color::$dataName data |
| |
|
| | |
| | |
| | set data(intensityIncr) [expr {256 / $data(NUM_COLORBARS)}] |
| |
|
| | |
| | set data(colorbarWidth) [expr {$data(BARS_WIDTH) / $data(NUM_COLORBARS)}] |
| |
|
| | |
| | |
| | |
| | set data(indent) [expr {$data(PLGN_WIDTH) / 2}] |
| |
|
| | set data(colorPad) 2 |
| | set data(selPad) [expr {$data(PLGN_WIDTH) / 2}] |
| |
|
| | |
| | |
| | |
| | set data(minX) $data(indent) |
| |
|
| | |
| | |
| | |
| | set data(maxX) [expr {$data(BARS_WIDTH) + $data(indent)-1}] |
| |
|
| | |
| | |
| | |
| | set data(canvasWidth) [expr {$data(BARS_WIDTH) + $data(PLGN_WIDTH)}] |
| |
|
| | |
| | |
| | set data(selection) $data(-initialcolor) |
| | set data(finalColor) $data(-initialcolor) |
| | set rgb [winfo rgb . $data(selection)] |
| |
|
| | set data(red,intensity) [expr {[lindex $rgb 0]/0x100}] |
| | set data(green,intensity) [expr {[lindex $rgb 1]/0x100}] |
| | set data(blue,intensity) [expr {[lindex $rgb 2]/0x100}] |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::Config {dataName argList} { |
| | variable ::tk::Priv |
| | upvar ::tk::dialog::color::$dataName data |
| |
|
| | |
| | |
| | if {[info exists Priv(selectColor)] && $Priv(selectColor) ne ""} { |
| | set defaultColor $Priv(selectColor) |
| | } else { |
| | set defaultColor [. cget -background] |
| | } |
| |
|
| | set specs [list \ |
| | [list -initialcolor "" "" $defaultColor] \ |
| | [list -parent "" "" "."] \ |
| | [list -title "" "" [mc "Color"]] \ |
| | ] |
| |
|
| | |
| | |
| | tclParseConfigSpec ::tk::dialog::color::$dataName $specs "" $argList |
| |
|
| | if {$data(-title) eq ""} { |
| | set data(-title) " " |
| | } |
| | if {[catch {winfo rgb . $data(-initialcolor)} err]} { |
| | return -code error -errorcode [list TK LOOKUP COLOR $data(-initialcolor)] \ |
| | $err |
| | } |
| |
|
| | if {![winfo exists $data(-parent)]} { |
| | return -code error -errorcode [list TK LOOKUP WINDOW $data(-parent)] \ |
| | "bad window path name \"$data(-parent)\"" |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::BuildDialog {w} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | |
| | |
| | set topFrame [frame $w.top -relief raised -bd 1] |
| |
|
| | |
| | set stripsFrame [frame $topFrame.colorStrip] |
| |
|
| | set maxWidth [::tk::mcmaxamp &Red &Green &Blue] |
| | set maxWidth [expr {$maxWidth<6 ? 6 : $maxWidth}] |
| | set colorList { |
| | red "&Red" |
| | green "&Green" |
| | blue "&Blue" |
| | } |
| | foreach {color l} $colorList { |
| | |
| | set f [frame $stripsFrame.$color] |
| |
|
| | |
| | set box [frame $f.box] |
| |
|
| | ::tk::AmpWidget label $box.label -text "[mc $l]:" \ |
| | -width $maxWidth -anchor ne |
| | bind $box.label <<AltUnderlined>> [list focus $box.entry] |
| |
|
| | entry $box.entry -textvariable \ |
| | ::tk::dialog::color::[winfo name $w]($color,intensity) \ |
| | -width 4 |
| | pack $box.label -side left -fill y -padx 2 -pady 3 |
| | pack $box.entry -side left -anchor n -pady 0 |
| | pack $box -side left -fill both |
| |
|
| | set height [expr { |
| | [winfo reqheight $box.entry] - |
| | 2*([$box.entry cget -highlightthickness] + [$box.entry cget -bd]) |
| | }] |
| |
|
| | canvas $f.color -height $height \ |
| | -width $data(BARS_WIDTH) -relief sunken -bd 2 |
| | canvas $f.sel -height $data(PLGN_HEIGHT) \ |
| | -width $data(canvasWidth) -highlightthickness 0 |
| | pack $f.color -expand yes -fill both |
| | pack $f.sel -expand yes -fill both |
| |
|
| | pack $f -side top -fill x -padx 0 -pady 2 |
| |
|
| | set data($color,entry) $box.entry |
| | set data($color,col) $f.color |
| | set data($color,sel) $f.sel |
| |
|
| | bind $data($color,col) <Configure> \ |
| | [list tk::dialog::color::DrawColorScale $w $color 1] |
| | bind $data($color,col) <Enter> \ |
| | [list tk::dialog::color::EnterColorBar $w $color] |
| | bind $data($color,col) <Leave> \ |
| | [list tk::dialog::color::LeaveColorBar $w $color] |
| |
|
| | bind $data($color,sel) <Enter> \ |
| | [list tk::dialog::color::EnterColorBar $w $color] |
| | bind $data($color,sel) <Leave> \ |
| | [list tk::dialog::color::LeaveColorBar $w $color] |
| |
|
| | bind $box.entry <Return> [list tk::dialog::color::HandleRGBEntry $w] |
| | } |
| |
|
| | pack $stripsFrame -side left -fill both -padx 4 -pady 10 |
| |
|
| | |
| | |
| | |
| | set selFrame [frame $topFrame.sel] |
| | set lab [::tk::AmpWidget label $selFrame.lab \ |
| | -text [mc "&Selection:"] -anchor sw] |
| | set ent [entry $selFrame.ent \ |
| | -textvariable ::tk::dialog::color::[winfo name $w](selection) \ |
| | -width 16] |
| | set f1 [frame $selFrame.f1 -relief sunken -bd 2] |
| | set data(finalCanvas) [frame $f1.demo -bd 0 -width 100 -height 70] |
| |
|
| | pack $lab $ent -side top -fill x -padx 4 -pady 2 |
| | pack $f1 -expand yes -anchor nw -fill both -padx 6 -pady 10 |
| | pack $data(finalCanvas) -expand yes -fill both |
| |
|
| | bind $ent <Return> [list tk::dialog::color::HandleSelEntry $w] |
| |
|
| | pack $selFrame -side left -fill none -anchor nw |
| | pack $topFrame -side top -expand yes -fill both -anchor nw |
| |
|
| | |
| | |
| | set botFrame [frame $w.bot -relief raised -bd 1] |
| |
|
| | ::tk::AmpWidget button $botFrame.ok -text [mc "&OK"] \ |
| | -command [list tk::dialog::color::OkCmd $w] |
| | ::tk::AmpWidget button $botFrame.cancel -text [mc "&Cancel"] \ |
| | -command [list tk::dialog::color::CancelCmd $w] |
| |
|
| | set data(okBtn) $botFrame.ok |
| | set data(cancelBtn) $botFrame.cancel |
| |
|
| | grid x $botFrame.ok x $botFrame.cancel x -sticky ew |
| | grid configure $botFrame.ok $botFrame.cancel -padx 10 -pady 10 |
| | grid columnconfigure $botFrame {0 4} -weight 1 -uniform space |
| | grid columnconfigure $botFrame {1 3} -weight 1 -uniform button |
| | grid columnconfigure $botFrame 2 -weight 2 -uniform space |
| | pack $botFrame -side bottom -fill x |
| |
|
| | |
| | bind $lab <<AltUnderlined>> [list focus $ent] |
| | bind $w <Escape> [list tk::ButtonInvoke $data(cancelBtn)] |
| | bind $w <Alt-Key> [list tk::AltKeyInDialog $w %A] |
| |
|
| | wm protocol $w WM_DELETE_WINDOW [list tk::dialog::color::CancelCmd $w] |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::SetRGBValue {w color} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | set data(red,intensity) [lindex $color 0] |
| | set data(green,intensity) [lindex $color 1] |
| | set data(blue,intensity) [lindex $color 2] |
| |
|
| | RedrawColorBars $w all |
| |
|
| | |
| | foreach color {red green blue} { |
| | set x [RgbToX $w $data($color,intensity)] |
| | MoveSelector $w $data($color,sel) $color $x 0 |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::XToRgb {w x} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | set x [expr {($x * $data(intensityIncr))/ $data(colorbarWidth)}] |
| | if {$x > 255} { |
| | set x 255 |
| | } |
| | return $x |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::RgbToX {w color} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | return [expr {($color * $data(colorbarWidth)/ $data(intensityIncr))}] |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::DrawColorScale {w c {create 0}} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | |
| | |
| | set col $data($c,col) |
| | set sel $data($c,sel) |
| |
|
| | |
| | if {$create} { |
| | |
| | if { $data(lines,$c,last) > $data(lines,$c,start)} { |
| | for {set i $data(lines,$c,start)} \ |
| | {$i <= $data(lines,$c,last)} {incr i} { |
| | $sel delete $i |
| | } |
| | } |
| | |
| | if {[info exists data($c,index)]} { |
| | $sel delete $data($c,index) |
| | } |
| |
|
| | |
| | CreateSelector $w $sel $c |
| | $sel bind $data($c,index) <Button-1> \ |
| | [list tk::dialog::color::StartMove $w $sel $c %x $data(selPad) 1] |
| | $sel bind $data($c,index) <B1-Motion> \ |
| | [list tk::dialog::color::MoveSelector $w $sel $c %x $data(selPad)] |
| | $sel bind $data($c,index) <ButtonRelease-1> \ |
| | [list tk::dialog::color::ReleaseMouse $w $sel $c %x $data(selPad)] |
| |
|
| | set height [winfo height $col] |
| | |
| | |
| | set data($c,clickRegion) [$sel create rectangle 0 0 \ |
| | $data(canvasWidth) $height -fill {} -outline {}] |
| |
|
| | bind $col <Button-1> \ |
| | [list tk::dialog::color::StartMove $w $sel $c %x $data(colorPad)] |
| | bind $col <B1-Motion> \ |
| | [list tk::dialog::color::MoveSelector $w $sel $c %x $data(colorPad)] |
| | bind $col <ButtonRelease-1> \ |
| | [list tk::dialog::color::ReleaseMouse $w $sel $c %x $data(colorPad)] |
| |
|
| | $sel bind $data($c,clickRegion) <Button-1> \ |
| | [list tk::dialog::color::StartMove $w $sel $c %x $data(selPad)] |
| | $sel bind $data($c,clickRegion) <B1-Motion> \ |
| | [list tk::dialog::color::MoveSelector $w $sel $c %x $data(selPad)] |
| | $sel bind $data($c,clickRegion) <ButtonRelease-1> \ |
| | [list tk::dialog::color::ReleaseMouse $w $sel $c %x $data(selPad)] |
| | } else { |
| | |
| | set l $data(lines,$c,start) |
| | } |
| |
|
| | |
| | set highlightW [expr {[$col cget -highlightthickness] + [$col cget -bd]}] |
| | for {set i 0} { $i < $data(NUM_COLORBARS)} { incr i} { |
| | set intensity [expr {$i * $data(intensityIncr)}] |
| | set startx [expr {$i * $data(colorbarWidth) + $highlightW}] |
| | if {$c eq "red"} { |
| | set color [format "#%02x%02x%02x" \ |
| | $intensity $data(green,intensity) $data(blue,intensity)] |
| | } elseif {$c eq "green"} { |
| | set color [format "#%02x%02x%02x" \ |
| | $data(red,intensity) $intensity $data(blue,intensity)] |
| | } else { |
| | set color [format "#%02x%02x%02x" \ |
| | $data(red,intensity) $data(green,intensity) $intensity] |
| | } |
| |
|
| | if {$create} { |
| | set index [$col create rect $startx $highlightW \ |
| | [expr {$startx +$data(colorbarWidth)}] \ |
| | [expr {[winfo height $col] + $highlightW}] \ |
| | -fill $color -outline $color] |
| | } else { |
| | $col itemconfigure $l -fill $color -outline $color |
| | incr l |
| | } |
| | } |
| | $sel raise $data($c,index) |
| |
|
| | if {$create} { |
| | set data(lines,$c,last) $index |
| | set data(lines,$c,start) [expr {$index - $data(NUM_COLORBARS) + 1}] |
| | } |
| |
|
| | RedrawFinalColor $w |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::CreateSelector {w sel c } { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| | set data($c,index) [$sel create polygon \ |
| | 0 $data(PLGN_HEIGHT) \ |
| | $data(PLGN_WIDTH) $data(PLGN_HEIGHT) \ |
| | $data(indent) 0] |
| | set data($c,x) [RgbToX $w $data($c,intensity)] |
| | $sel move $data($c,index) $data($c,x) 0 |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::RedrawFinalColor {w} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | set color [format "#%02x%02x%02x" $data(red,intensity) \ |
| | $data(green,intensity) $data(blue,intensity)] |
| |
|
| | $data(finalCanvas) configure -bg $color |
| | set data(finalColor) $color |
| | set data(selection) $color |
| | set data(finalRGB) [list \ |
| | $data(red,intensity) \ |
| | $data(green,intensity) \ |
| | $data(blue,intensity)] |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::RedrawColorBars {w colorChanged} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | switch $colorChanged { |
| | red { |
| | DrawColorScale $w green |
| | DrawColorScale $w blue |
| | } |
| | green { |
| | DrawColorScale $w red |
| | DrawColorScale $w blue |
| | } |
| | blue { |
| | DrawColorScale $w red |
| | DrawColorScale $w green |
| | } |
| | default { |
| | DrawColorScale $w red |
| | DrawColorScale $w green |
| | DrawColorScale $w blue |
| | } |
| | } |
| | RedrawFinalColor $w |
| | } |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::StartMove {w sel color x delta {dontMove 0}} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | if {!$dontMove} { |
| | MoveSelector $w $sel $color $x $delta |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::MoveSelector {w sel color x delta} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | incr x -$delta |
| |
|
| | if { $x < 0 } { |
| | set x 0 |
| | } elseif { $x > $data(BARS_WIDTH)} { |
| | set x $data(BARS_WIDTH) |
| | } |
| | set diff [expr {$x - $data($color,x)}] |
| | $sel move $data($color,index) $diff 0 |
| | set data($color,x) [expr {$data($color,x) + $diff}] |
| |
|
| | |
| | return $x |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::ReleaseMouse {w sel color x delta} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | set x [MoveSelector $w $sel $color $x $delta] |
| |
|
| | |
| | set data($color,intensity) [XToRgb $w $x] |
| |
|
| | RedrawColorBars $w $color |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::ResizeColorBars {w} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | if { |
| | ($data(BARS_WIDTH) < $data(NUM_COLORBARS)) || |
| | (($data(BARS_WIDTH) % $data(NUM_COLORBARS)) != 0) |
| | } then { |
| | set data(BARS_WIDTH) $data(NUM_COLORBARS) |
| | } |
| | InitValues [winfo name $w] |
| | foreach color {red green blue} { |
| | $data($color,col) configure -width $data(canvasWidth) |
| | DrawColorScale $w $color 1 |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::HandleSelEntry {w} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | set text [string trim $data(selection)] |
| | |
| | if {[catch {set color [winfo rgb . $text]} ]} { |
| | set data(selection) $data(finalColor) |
| | return |
| | } |
| |
|
| | set R [expr {[lindex $color 0]/0x100}] |
| | set G [expr {[lindex $color 1]/0x100}] |
| | set B [expr {[lindex $color 2]/0x100}] |
| |
|
| | SetRGBValue $w "$R $G $B" |
| | set data(selection) $text |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | proc ::tk::dialog::color::HandleRGBEntry {w} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | foreach c {red green blue} { |
| | if {[catch { |
| | set data($c,intensity) [expr {int($data($c,intensity))}] |
| | }]} { |
| | set data($c,intensity) 0 |
| | } |
| |
|
| | if {$data($c,intensity) < 0} { |
| | set data($c,intensity) 0 |
| | } |
| | if {$data($c,intensity) > 255} { |
| | set data($c,intensity) 255 |
| | } |
| | } |
| |
|
| | SetRGBValue $w "$data(red,intensity) \ |
| | $data(green,intensity) $data(blue,intensity)" |
| | } |
| |
|
| | |
| | |
| | proc ::tk::dialog::color::EnterColorBar {w color} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | $data($color,sel) itemconfigure $data($color,index) -fill red |
| | } |
| |
|
| | |
| | |
| | proc ::tk::dialog::color::LeaveColorBar {w color} { |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | $data($color,sel) itemconfigure $data($color,index) -fill black |
| | } |
| |
|
| | |
| | |
| | proc ::tk::dialog::color::OkCmd {w} { |
| | variable ::tk::Priv |
| | upvar ::tk::dialog::color::[winfo name $w] data |
| |
|
| | set Priv(selectColor) $data(finalColor) |
| | } |
| |
|
| | |
| | |
| | proc ::tk::dialog::color::CancelCmd {w} { |
| | variable ::tk::Priv |
| | set Priv(selectColor) "" |
| | } |
| |
|