1# vscale.rb
2#
3# This demonstration script shows an example with a vertical scale.
4
5require "tkcanvas"
6
7if defined?($vscale_demo) && $vscale_demo
8  $vscale_demo.destroy
9  $vscale_demo = nil
10end
11
12$vscale_demo = TkToplevel.new {|w|
13  title("Vertical Scale Demonstration")
14  iconname("vscale")
15}
16positionWindow($vscale_demo)
17
18base_frame = TkFrame.new($vscale_demo).pack(:fill=>:both, :expand=>true)
19
20msg = TkLabel.new(base_frame) {
21  font $font
22  wraplength '3.5i'
23  justify 'left'
24  text "An arrow and a vertical scale are displayed below.  If you click or drag mouse button 1 in the scale, you can change the size of the arrow."
25}
26msg.pack('side'=>'top', 'padx'=>'.5c')
27
28TkFrame.new(base_frame) {|frame|
29  TkButton.new(frame) {
30    text 'Dismiss'
31    command proc {
32      tmppath = $vscale_demo
33      $vscale_demo = nil
34      tmppath.destroy
35    }
36  }.pack('side'=>'left', 'expand'=>'yes')
37
38  TkButton.new(frame) {
39    text 'Show Code'
40    command proc { showCode 'vscale' }
41  }.pack('side'=>'left', 'expand'=>'yes')
42}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
43
44def setHeight(w, height)
45  height = height + 21
46  y2 = height - 30
47  if y2 < 21
48    y2 = 21
49  end
50  w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
51  w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
52end
53
54TkFrame.new(base_frame) {|frame|
55  borderwidth 10
56  canvas = TkCanvas.new(frame) {|c|
57    width 50
58    height 50
59    bd 0
60    highlightthickness 0
61    TkcPolygon.new(c, 0, 0, 1, 1, 2, 2) {
62      fill 'SeaGreen3'
63      tags 'poly'
64    }
65    TkcLine.new(c, 0, 0, 1, 1, 2, 2, 0, 0) {
66      fill 'black'
67      tags 'line'
68    }
69  }.pack('side'=>'left',  'anchor'=>'nw', 'fill'=>'y')
70  scale = TkScale.new(frame) {
71    orient 'vertical'
72    length 284
73    from 0
74    to 250
75    command proc{|value| setHeight(canvas, value)}
76    tickinterval 50
77  }.pack('side'=>'left', 'anchor'=>'ne')
78  scale.set 75
79}.pack
80