square revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber#!/bin/sh
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# the next line restarts using wish \
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberexec wish "$0" "$@"
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# square --
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# This script generates a demo application containing only
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# a "square" widget. It's only usable if Tk has been compiled
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# with tkSquare.c and with the -DSQUARE_DEMO compiler switch.
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# This demo arranges the following bindings for the widget:
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber#
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# Button-1 press/drag: moves square to mouse
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# "a": toggle size animation on/off
4845c17aff570c25e05c5347dfdcd577cb108d47Serge Hallyn#
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# SCCS: @(#) square 1.6 96/02/16 10:49:21
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Grabersquare .s
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberpack .s -expand yes -fill both
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberwm minsize . 1 1
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberbind .s <1> {center %x %y}
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberbind .s <B1-Motion> {center %x %y}
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberbind .s a animate
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graberfocus .s
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber# The procedure below centers the square on a given position.
5b99af0079813347d90c935ea540ed7f96dcea38Stéphane Graber
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graberproc center {x y} {
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber set a [.s size]
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber .s position [expr $x-($a/2)] [expr $y-($a/2)]
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber}
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber# The procedures below provide a simple form of animation where
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber# the box changes size in a pulsing pattern: larger, smaller, larger,
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber# and so on.
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graberset inc 0
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graberproc animate {} {
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber global inc
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber if {$inc == 0} {
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber set inc 3
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber timer
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber } else {
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber set inc 0
de9a4bfc2c488aef0055a25af834be9b22738cf0Stéphane Graber }
a38e3e325d651200b0aac77ef5287f36e8c46a63brauner}
a38e3e325d651200b0aac77ef5287f36e8c46a63brauner
6e39e4cbff5d49b4a66451696aa87b9884f58a6eStéphane Graberproc timer {} {
f24a52d5f588ff4e4575046903fb9498c376d833Stéphane Graber global inc
f24a52d5f588ff4e4575046903fb9498c376d833Stéphane Graber set s [.s size]
a38e3e325d651200b0aac77ef5287f36e8c46a63brauner if {$inc == 0} return
f24a52d5f588ff4e4575046903fb9498c376d833Stéphane Graber if {$s >= 40} {set inc -3}
6e39e4cbff5d49b4a66451696aa87b9884f58a6eStéphane Graber if {$s <= 10} {set inc 3}
6e39e4cbff5d49b4a66451696aa87b9884f58a6eStéphane Graber .s size [expr {$s+$inc}]
6e39e4cbff5d49b4a66451696aa87b9884f58a6eStéphane Graber after 30 timer
4662c6dee0b2f3ee065897aac616b6a8ad02b67eStéphane Graber}
4662c6dee0b2f3ee065897aac616b6a8ad02b67eStéphane Graber