summaryrefslogtreecommitdiffstats
path: root/library/demos/square
diff options
context:
space:
mode:
authorrjohnson <rjohnson>1998-04-01 09:51:44 (GMT)
committerrjohnson <rjohnson>1998-04-01 09:51:44 (GMT)
commit066ea7fd88d49cb456f74da71dbe875e4fc0aabb (patch)
tree8fb30cb152c4dc191be47fa043d2e6f5ea38c7ba /library/demos/square
parent13242623d2ff3ea02ab6a62bfb48a7dbb5c27e22 (diff)
downloadtk-066ea7fd88d49cb456f74da71dbe875e4fc0aabb.zip
tk-066ea7fd88d49cb456f74da71dbe875e4fc0aabb.tar.gz
tk-066ea7fd88d49cb456f74da71dbe875e4fc0aabb.tar.bz2
Initial revision
Diffstat (limited to 'library/demos/square')
-rw-r--r--library/demos/square55
1 files changed, 55 insertions, 0 deletions
diff --git a/library/demos/square b/library/demos/square
new file mode 100644
index 0000000..743016f
--- /dev/null
+++ b/library/demos/square
@@ -0,0 +1,55 @@
+#!/bin/sh
+# the next line restarts using wish \
+exec wish "$0" "$@"
+
+# square --
+# This script generates a demo application containing only a "square"
+# widget. It's only usable in the "tktest" application or if Tk has
+# been compiled with tkSquare.c. This demo arranges the following
+# bindings for the widget:
+#
+# Button-1 press/drag: moves square to mouse
+# "a": toggle size animation on/off
+#
+# SCCS: @(#) square 1.7 97/02/24 16:42:31
+
+square .s
+pack .s -expand yes -fill both
+wm minsize . 1 1
+
+bind .s <1> {center %x %y}
+bind .s <B1-Motion> {center %x %y}
+bind .s a animate
+focus .s
+
+# The procedure below centers the square on a given position.
+
+proc center {x y} {
+ set a [.s size]
+ .s position [expr $x-($a/2)] [expr $y-($a/2)]
+}
+
+# The procedures below provide a simple form of animation where
+# the box changes size in a pulsing pattern: larger, smaller, larger,
+# and so on.
+
+set inc 0
+proc animate {} {
+ global inc
+ if {$inc == 0} {
+ set inc 3
+ timer
+ } else {
+ set inc 0
+ }
+}
+
+proc timer {} {
+ global inc
+ set s [.s size]
+ if {$inc == 0} return
+ if {$s >= 40} {set inc -3}
+ if {$s <= 10} {set inc 3}
+ .s size [expr {$s+$inc}]
+ after 30 timer
+}