1
##########################################################################
2
# mkWireColorPopup w name color
4
# Create a dialog box with sliders and buttons to adjust current color
5
# of wire mesh for current surface
8
# w - Name to use for new top-level window.
9
# name - Label for ColorPopup
10
# color - CurrentColor (set to UseMap if map is used)
11
# Updated Nov 2006, Michael Barton, Arizona State University
13
##########################################################################
14
# COPYRIGHT: (C) 2006 by Michael Barton and the GRASS Development Team
16
# This program is free software under the GNU General Public
17
# License (>=v2). Read the file COPYING that comes with GRASS
20
##########################################################################
25
proc mkWireColorPopup {w name {color "#000000"} {mode 0}} {
29
toplevel $w -class Dialog
30
wm title $w [G_msg "Select Wire Color"]
31
wm iconname $w "Color"
32
wm geometry $w 300x450
34
wm resizable $w false false
36
if {"$color" != "UseMap"} then {
37
set tmp [tcl_to_rgb $color]
38
set r [expr ($tmp&0xff0000)>>16]
39
set g [expr ($tmp&0x00ff00)>>8]
40
set b [expr ($tmp&0x0000ff)]
49
# Create two frames in the main window. The top frame will hold the
50
# sliders that interactively change color and the bottom one will hold
51
# the buttons for predefined color. Below the two frames we create
52
# a checkbutton widget allowing the color to be set to the colormap
55
frame $w.top -relief raised -border 1
56
frame $w.bot -relief raised -border 1
57
checkbutton $w.usemap -text [G_msg "use surface color"] -onvalue UseMap \
58
-offvalue 0 -variable CurrWireColor
60
Nv_mkWireColorScale $w.top.left Red $r red $w.top.color
61
Nv_mkWireColorScale $w.top.left Green $g green $w.top.color
62
Nv_mkWireColorScale $w.top.left Blue $b blue $w.top.color
64
pack $w.top.left.red $w.top.left.green $w.top.left.blue \
65
-side top -expand 1 -pady 2
67
# this is the main color panel
68
set CurrWireColor $color
69
if {"$color" != "UseMap"} then {
70
label $w.top.color -bg $color -width 20 -height 10
72
label $w.top.color -bg \#FFFFFF -width 20 -height 10
74
pack $w.top.left -side left -padx 10 -pady 10 -expand 1
75
pack $w.top.color -side left -padx 10 -pady 10 -expand yes
79
frame $w.bot.buttonframe
80
button $w.bot.buttonframe.ok -text [G_msg "Ok"] -width 6 \
81
-command "destroy $w" -bd 1
82
button $w.bot.buttonframe.cancel -bd 1 -width 6\
83
-text [G_msg "Cancel"] -command "set CurrWireColor $tmp; destroy $w"
84
pack $w.bot.buttonframe.cancel -side right -expand 0
85
pack $w.bot.buttonframe.ok -side left -expand 0
86
pack $w.bot.buttonframe -side bottom -fill x \
87
-pady 3 -padx 10 -expand 1
89
mkWireColorButtons $w.bot.bf $w.top.left $w.top.color
90
pack $w.bot.bf -pady 3 -side top -expand 1
91
bind $w <Any-Enter> [list focus $w]
95
pack $w.top $w.bot $w.usemap -side top -fill both \
101
return $CurrWireColor
104
proc mkWireColorButtons { B S L} {
109
set clist [mkWireColorList]
111
for {set i 0; set k 0} {$i < 9 } {incr i} {
112
# make frame to hold buttons in this row
114
for {set j 0} {$j < 5 } {incr j; incr k} {
115
set color [lindex $clist $k]
116
button $B.f$i.$j -bg $color \
117
-activeforeground $color \
118
-activebackground $color \
120
-highlightthickness 1 \
121
-command "setWireScales $S $color; $L config -bg $color; set CurrWireColor $color"
122
pack $B.f$i.$j -padx 1 -pady 1 -side top -expand 1
124
pack $B.f$i -side left
128
proc getWireColorfromScales {S} {
130
set r [$S.red.scale get]
131
set g [$S.green.scale get]
132
set b [$S.blue.scale get]
143
proc setWireLabelfromScales {S L args} {
146
set r [$S.red.scale get]
147
set g [$S.green.scale get]
148
set b [$S.blue.scale get]
154
$L config -bg #$r$g$b
155
set CurrWireColor #$r$g$b
158
proc setWireScales {S c} {
159
set color [tcl_to_rgb $c]
160
set r [expr ($color&0xff0000)>>16]
161
set g [expr ($color&0x00ff00)>>8]
162
set b [expr ($color&0x0000ff)]
165
$S.green.scale set $g
169
proc mkWireColorList {} {
175
for {set r 4; set i 0} {$r < 16} {incr r 5} {
176
for {set g 4} {$g < 16} {incr g 5} {
177
for {set b 4} {$b < 16 && $i < 40} {incr b 5} {
178
set tmpr [hexval [expr $r/15.0*255]]
179
set tmpg [hexval [expr $g/15.0*255]]
180
set tmpb [hexval [expr $b/15.0*255]]
181
set color #$tmpr$tmpg$tmpb
182
set colorlist [concat $colorlist $color]
186
set colorlist [concat $colorlist #ff0000 #00ffff]
189
} elseif {$ramp < 10} {
190
set tmpg [hexval [expr $ramp/9.0*255]]
191
set color #$maxval$tmpg$minval
192
set colorlist [concat $colorlist $color]
196
set tmpg [hexval [expr (1.0 - $ramp/9.0)*255]]
197
set color #$minval$tmpg$maxval
198
set colorlist [concat $colorlist $color]
202
} elseif {$ramp < 16} {
203
set tmpb [hexval [expr ($ramp-10)/7.0*255]]
204
set color #$maxval$maxval$tmpb
205
set colorlist [concat $colorlist $color]
208
set tmpb [hexval [expr (1.0 - ($ramp-10)/7.0)*255]]
209
set color #$minval$minval$tmpb
210
set colorlist [concat $colorlist $color]
216
for {set gray 0} {$gray < 5} {incr gray} {
217
set g [hexval [expr (1.0 - $gray/4.0)*255]]
219
set colorlist [concat $colorlist $color]
227
##########################################################################
228
# procedure to make sliders
229
##########################################################################
230
proc Nv_mkWireColorScale { P {name " "} {curr 200}\
231
{color ""} {chip ""}} {
237
scale $S.scale -from 0 -length 140 -showvalue 1 -orient h\
238
-tickinterval 0 -to 255 -width 13 \
239
-command "setWireLabelfromScales $P $chip" \
241
-highlightthickness 3 \
242
-highlightbackground $color
245
pack $S.scale $S.f -side top