From 11dbedfaad4a9a9521ece2198a8dc491678b1902 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 29 Aug 2007 04:06:12 +0000 Subject: add tag v1_8_6_5001 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_6_5001@13304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ruby_1_8_6/ext/tk/sample/demos-en/square | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 ruby_1_8_6/ext/tk/sample/demos-en/square (limited to 'ruby_1_8_6/ext/tk/sample/demos-en/square') diff --git a/ruby_1_8_6/ext/tk/sample/demos-en/square b/ruby_1_8_6/ext/tk/sample/demos-en/square new file mode 100644 index 0000000000..00bfde59ff --- /dev/null +++ b/ruby_1_8_6/ext/tk/sample/demos-en/square @@ -0,0 +1,81 @@ +#!/usr/bin/env ruby + +# square -- +# This script generates a demo application containing only +# a "square" widget. It's only usable if Tk has been compiled +# with tkSquare.c and with the -DSQUARE_DEMO compiler switch. +# This demo arranges the following bindings for the widget: +# +# Button-1 press/drag: moves square to mouse +# "a": toggle size animation on/off +# + +require 'tk' +require 'tkafter' + +class TkSquare'yes', 'fill'=>'both') + bind('1', proc{|x,y| center(x,y)}, '%s %y') + bind('B1-Motion', proc{|x,y| center(x,y)}, '%s %y') + bind('a', proc{animate}) + focus +} +TkRoot.new.minsize(1,1) + +# The procedure below centers the square on a given position. + +def center(x,y) + a = $s.size + $s.position(x-(a/2), y-(a/2)) +end + +# The procedures below provide a simple form of animation where +# the box changes size in a pulsing pattern: larger, smaller, larger, +# and so on. + +$inc = 0 + +def timer_proc + a = $s.size + return if $inc == 0 + $inc = -3 if a >= 40 + $inc = 3 if a <= 10 + $s.size(a+$inc) +end + +$timer = TkAfter.new(30, -1, proc{timer_proc}) + +def animate + if $inc == 0 + $inc = 3 + $timer.start + else + $inc = 0 + $timer.stop + end +end + +Tk.mainloop -- cgit v1.2.3