gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: CmpImg3.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "widget": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program using tixwish.
  12. # Demonstrates how to use compound images to display icons in a canvas widget.
  13. #
  14. proc RunSample {w} {
  15. set top [frame $w.f -bd 1 -relief raised]
  16. set box [tixButtonBox $w.b -bd 1 -relief raised]
  17. pack $box -side bottom -fill both
  18. pack $top -side top -fill both -expand yes
  19. label $top.lab -text "Drag the icons"
  20. pack $top.lab -anchor c -side top -pady 4
  21. # Create the canvas to display the icons
  22. #
  23. set c [canvas $top.c -relief sunken -bd 1]
  24. pack $c -side top -expand yes -fill both -padx 4 -pady 4
  25. # create several compound images in the canvas
  26. #
  27. set network [tix getimage network]
  28. set harddisk [tix getimage harddisk]
  29. set cmp_1 [image create compound -window $c -bd 1]
  30. $cmp_1 add image -image $network
  31. $cmp_1 add line
  32. $cmp_1 add text -text " Network "
  33. set cmp_2 [image create compound -window $c -bd 1]
  34. $cmp_2 add image -image $harddisk
  35. $cmp_2 add line
  36. $cmp_2 add text -text " Hard disk "
  37. set cmp_3 [image create compound -window $c -bd 1 \
  38. -background #c0c0ff -relief raised \
  39. -showbackground 1]
  40. $cmp_3 add image -image $network
  41. $cmp_3 add line
  42. $cmp_3 add text -text " Network 2 "
  43. $c create image 50 50 -image $cmp_1
  44. $c create image 150 50 -image $cmp_2
  45. $c create image 250 50 -image $cmp_3
  46. bind $c <1> "itemStartDrag $c %x %y"
  47. bind $c <B1-Motion> "itemDrag $c %x %y"
  48. # Create the buttons
  49. #
  50. $box add ok -text Ok -command "destroy $w" -width 6
  51. $box add cancel -text Cancel -command "destroy $w" -width 6
  52. }
  53. proc itemStartDrag {c x y} {
  54. global lastX lastY
  55. $c raise current
  56. set lastX [$c canvasx $x]
  57. set lastY [$c canvasy $y]
  58. }
  59. proc itemDrag {c x y} {
  60. global lastX lastY
  61. set x [$c canvasx $x]
  62. set y [$c canvasy $y]
  63. $c move current [expr $x-$lastX] [expr $y-$lastY]
  64. set lastX $x
  65. set lastY $y
  66. }
  67. if {![info exists tix_demo_running]} {
  68. wm withdraw .
  69. set w .demo
  70. toplevel $w; wm transient $w ""
  71. RunSample $w
  72. bind $w <Destroy> exit
  73. }
上海开阖软件有限公司 沪ICP备12045867号-1