OSDN Git Service

change prefix to '/data/ruby'
[splhack/AndroidRuby.git] / lib / ruby-1.9.1-rc1 / ext / tk / sample / tkextlib / blt / winop1.rb
1 #!/usr/bin/env ruby
2 require 'tk'
3 require 'tkextlib/blt'
4
5 file = File.join(File.dirname(File.expand_path(__FILE__)), 
6                  'images', 'sample.gif')
7 if File.exist?(file)
8   src = TkPhotoImage.new(:file=>file)
9 else
10   fail RuntimeError, 'no image file'
11 end
12
13 width = src.width
14 height = src.height
15
16 TkOption.add('*Label.font', '*helvetica*10*')
17 TkOption.add('*Label.background', 'white')
18
19 l_img0 = TkLabel.new(:image=>src)
20 l_hdr0 = TkLabel.new(:text=>"#{width} x #{height}")
21 l_ftr0 = TkLabel.new(:text=>'100%')
22 Tk.root.background('white')
23
24 (2..10).each{|i|
25   iw = width/i
26   ih = height/i
27   r = '%6g'%(100.0/i)
28   dst = TkPhotoImage.new(:width=>iw, :height=>ih)
29   Tk::BLT::Winop.image_resample(src, dst, :sinc)
30   l_hdr = TkLabel.new(:text=>"#{iw} x #{ih}")
31   l_ftr = TkLabel.new(:text=>"#{r}%")
32   l_img = TkLabel.new(:image=>dst)
33   Tk::BLT::Table.add(Tk.root, 
34                      [0,i], l_hdr, 
35                      [1,i], l_img, 
36                      [2,i], l_ftr)
37   Tk.update
38 }
39
40 Tk.mainloop