diff options
| author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-07-31 20:52:40 +0000 |
|---|---|---|
| committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-07-31 20:52:40 +0000 |
| commit | 9521e7d91d8d3341ba9694491c8fba3f55f0d020 (patch) | |
| tree | 33e458bfb8dcf84face1eb34acede77b68ff5d8d /ext/tk/sample/demos-jp/square | |
| parent | 13fc32aac2a54126b98d23e79e4a2aa47e8c7506 (diff) | |
| download | ruby-9521e7d91d8d3341ba9694491c8fba3f55f0d020.tar.gz ruby-9521e7d91d8d3341ba9694491c8fba3f55f0d020.tar.xz ruby-9521e7d91d8d3341ba9694491c8fba3f55f0d020.zip | |
* (IMPORTANT BUG FIX) scan of event keywords doesn't work on recent
versions of Tck/Tk
* (bug fix) initialize error of instance variable on TkComposite
* (bug fix) initialize error on encoding-system on MultiTkIp
* (bug fix) trouble on destroying widgets
* (new) add JP and EN version of Ruby/Tk widget demos
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/demos-jp/square')
| -rw-r--r-- | ext/tk/sample/demos-jp/square | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ext/tk/sample/demos-jp/square b/ext/tk/sample/demos-jp/square new file mode 100644 index 000000000..b914b735b --- /dev/null +++ b/ext/tk/sample/demos-jp/square @@ -0,0 +1,74 @@ +#!/usr/local/bin/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<TkWindow + def create_self + tk_call 'square', path + end + def size(amount=nil) + if amount + tk_send 'size', amount + else + number(tk_send 'size') + end + end + def position(x,y) + tk_send 'position', x, y + end +end + +$s = TkSquare.new{ + pack('expand'=>'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 |
