Blt provides the winop command
(manpage)
which has sub-commands for window and image manipulation.
This can be used in conjunction with the photo copy
extensions.
2. The image sub-commands
The winop image sub-commands provide
image manipulation.
2.1 gradient
Gradient images are widely used in application and web pages
for enhancing the appearance of user interfaces.
2.2 merge
merge allows on-the-fly composting of sophisticated
images.
For example, the following screenshot displays:
A "lines" gradient
A "rectangle" gradient
A gradient with skew
Merging a gradient with a tile.
Merging a picture with tile.
Here is the source for producing the above
images (which also requires downloading
beach.jpg).
For the image 1 run wize grad.tcl 1, etc.
#!/usr/bin/env wize
#
# grad.tcl: a script demonstrate use of two winop commands:
# gradient and merge.
#
# In all tests, an image is created and used to setup
# the background tile. Then a couple of widgets are created.
#
set tst [lindex $argv 0]
wm title . "Winop test: $tst"
switch -- $tst {
1 - 2 - 3 {
set img [image create photo -width 400 -height 300]
if {$tst == "1"} {
winop image gradient $img Red DarkBlue lines
} elseif {$tst == "2"} {
winop image gradient $img Red DarkBlue rectangular
} else {
winop image gradient $img DarkBlue Red lines .3
}
set img2 [image create photo]
$img2 copy $img
. conf -tile $img2
wm geom . [image width $img2]x[image height $img2]
option add *tile $img2
place [button .b -text Begin] -relx .3 -rely .3
place [text .t -width 20 -height 5] -relx .3 -rely .4
.t insert end " Enter info..."
}
4 - 5 {
set i [image create photo -file /zvfs/img/tile/tile-swirl.gif]
set i2 [image create photo -file beach.jpg]
set i3 [image create photo]
set img [image create photo]
if {$tst != 4} {
$img copy $i -to 0 0 [image width $i2] [image height $i2]
winop merge $i2 $img $i3 .25
} else {
$img copy $i -to 0 0 [image width $i2] [image height $i]
set i4 [image create photo -width [image width $i2] -height [image height $i]]
winop image gradient $i4 Cyan Purple lines
winop image merge $i4 $img $i3 .25
}
option add *tile $i3
. conf -tile $i3
wm geom . [image width $i2]x[image height $i2]
pack [set t [Tabset new . -slant right]] -padx 20 -pady 20 -fill both -expand y
set tf [Frame new $t.]
pack [set t1 [Text new $tf.]] -fill both -expand y
Text insert $t1 end [join [info commands *] \n]
Tabset insert $t end Main -window $tf
pack [set t1 [Button new $tf. -text Done]] -pady 10
set t2 [Text new $t.]
Tabset insert $t end Secondary -window $t2 -fill both
}
default {
puts "usage: $argv0 1 | 2 | 3 | 4 | 5"
exit 0
}
}
2.3 resample and subsample
These commands are used to resize and optionally filter
images. eg.
The alpha sub-command is used to make
one color transparent in an image. This can be useful for
making
shaped toplevel windows (which
take their shape from
the transparency) or shaped buttons like this:
The following script demonstrates using a canvas to
draw an arbitrary polygon upon a white background.
This is saved to an image and
the White converted to transparent.
This image could then be used as a shaped button or
toplevel window.
#!/usr/bin/env wize
pack [frame .f] -fill both -expand 1
canvas [set c .f.c] -bg White -bd 0 -width 100 -height 100
pack $c -s top -e 0 -f none -padx 0 -pady 0
set tfile /zvfs/img/tile/blueplasma.gif
if {![file exists $tfile]} {
$c create polygon "10 10 10 100 50 50" -smooth 1 -fill red
} else {
set tile [image create photo -file $tfile]
$c create polygon "10 10 10 100 50 50" -smooth 1 -tile $tile -outline black
}
update
after 1000
set image [image create photo -format window -data .]
set img2 [image create photo]
winop image alpha $image $img2 White
$img2 write -format gif transimg.gif
pack [button .b -bg green -image $img2]
Note that an alternative approach is to use a pixmap.