home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activetcltk / ActiveTcl8.3.4.1-8.win32-ix86.exe / ActiveTcl8.3.4.1-win32-ix86 / demos / Tk / square < prev    next >
Encoding:
Text File  |  2001-10-22  |  1.2 KB  |  59 lines

  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" "$@"
  4.  
  5. # square --
  6. # This script generates a demo application containing only a "square"
  7. # widget.  It's only usable in the "tktest" application or if Tk has
  8. # been compiled with tkSquare.c. This demo arranges the following
  9. # bindings for the widget:
  10. # Button-1 press/drag:        moves square to mouse
  11. # "a":                toggle size animation on/off
  12. #
  13. # RCS: @(#) $Id: square,v 1.2.18.1 2001/10/12 10:56:13 dkf Exp $
  14.  
  15. square .s
  16. pack .s -expand yes -fill both
  17. wm minsize . 1 1
  18.  
  19. bind .s <1> {center %x %y}
  20. bind .s <B1-Motion> {center %x %y}
  21. bind .s a animate
  22. focus .s
  23.  
  24. # The procedure below centers the square on a given position.
  25.  
  26. proc center {x y} {
  27.     set a [.s size]
  28.     .s position [expr {$x-($a/2)}] [expr {$y-($a/2)}]
  29. }
  30.  
  31. # The procedures below provide a simple form of animation where
  32. # the box changes size in a pulsing pattern: larger, smaller, larger,
  33. # and so on.
  34.  
  35. set inc 0
  36. proc animate {} {
  37.     global inc
  38.     if {$inc == 0} {
  39.     set inc 3
  40.     timer
  41.     } else {
  42.     set inc 0
  43.     }
  44. }
  45.  
  46. proc timer {} {
  47.     global inc
  48.     set s [.s size]
  49.     if {$inc == 0} return
  50.     if {$s >= 40} {set inc -3} elseif {$s <= 10} {set inc 3}
  51.     .s size [expr {$s+$inc}]
  52.     after 30 timer
  53. }
  54.  
  55. # Local Variables:
  56. # mode: tcl
  57. # End:
  58.