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