summaryrefslogtreecommitdiff
path: root/tix/demos/samples/CmpImg3.tcl
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2000-02-07 00:19:28 +0000
committerJason Molenda <jmolenda@apple.com>2000-02-07 00:19:28 +0000
commitb111a96ea19bde1004ecea63c7827a1d4b0b73ef (patch)
tree2b8155215201f5224d8f68ec53f9720a89dfbdd9 /tix/demos/samples/CmpImg3.tcl
parentb73e43e34794f4903b0bf2e0fc1298547ef01faf (diff)
downloadgdb-b111a96ea19bde1004ecea63c7827a1d4b0b73ef.tar.gz
import insight-2000-02-04 snapshot (2nd try)
Diffstat (limited to 'tix/demos/samples/CmpImg3.tcl')
-rw-r--r--tix/demos/samples/CmpImg3.tcl86
1 files changed, 86 insertions, 0 deletions
diff --git a/tix/demos/samples/CmpImg3.tcl b/tix/demos/samples/CmpImg3.tcl
new file mode 100644
index 00000000000..26c08032030
--- /dev/null
+++ b/tix/demos/samples/CmpImg3.tcl
@@ -0,0 +1,86 @@
+# Tix Demostration Program
+#
+# This sample program is structured in such a way so that it can be
+# executed from the Tix demo program "widget": it must have a
+# procedure called "RunSample". It should also have the "if" statment
+# at the end of this file so that it can be run as a standalone
+# program using tixwish.
+
+# Demonstrates how to use compound images to display icons in a canvas widget.
+#
+
+proc RunSample {w} {
+ set top [frame $w.f -bd 1 -relief raised]
+ set box [tixButtonBox $w.b -bd 1 -relief raised]
+
+ pack $box -side bottom -fill both
+ pack $top -side top -fill both -expand yes
+
+ label $top.lab -text "Drag the icons"
+ pack $top.lab -anchor c -side top -pady 4
+
+ # Create the canvas to display the icons
+ #
+ set c [canvas $top.c -relief sunken -bd 1]
+ pack $c -side top -expand yes -fill both -padx 4 -pady 4
+
+ # create several compound images in the canvas
+ #
+ set network [tix getimage network]
+ set harddisk [tix getimage harddisk]
+
+ set cmp_1 [image create compound -window $c -bd 1]
+ $cmp_1 add image -image $network
+ $cmp_1 add line
+ $cmp_1 add text -text " Network "
+
+ set cmp_2 [image create compound -window $c -bd 1]
+ $cmp_2 add image -image $harddisk
+ $cmp_2 add line
+ $cmp_2 add text -text " Hard disk "
+
+ set cmp_3 [image create compound -window $c -bd 1 \
+ -background #c0c0ff -relief raised \
+ -showbackground 1]
+ $cmp_3 add image -image $network
+ $cmp_3 add line
+ $cmp_3 add text -text " Network 2 "
+
+ $c create image 50 50 -image $cmp_1
+ $c create image 150 50 -image $cmp_2
+ $c create image 250 50 -image $cmp_3
+
+ bind $c <1> "itemStartDrag $c %x %y"
+ bind $c <B1-Motion> "itemDrag $c %x %y"
+
+ # Create the buttons
+ #
+ $box add ok -text Ok -command "destroy $w" -width 6
+ $box add cancel -text Cancel -command "destroy $w" -width 6
+}
+
+
+proc itemStartDrag {c x y} {
+ global lastX lastY
+ $c raise current
+
+ set lastX [$c canvasx $x]
+ set lastY [$c canvasy $y]
+}
+
+proc itemDrag {c x y} {
+ global lastX lastY
+ set x [$c canvasx $x]
+ set y [$c canvasy $y]
+ $c move current [expr $x-$lastX] [expr $y-$lastY]
+ set lastX $x
+ set lastY $y
+}
+
+if {![info exists tix_demo_running]} {
+ wm withdraw .
+ set w .demo
+ toplevel $w
+ RunSample $w
+ bind $w <Destroy> exit
+}