1# -*- coding: utf-8 -*-
2require "tkcanvas"
3
4if defined?($vscale_demo) && $vscale_demo
5  $vscale_demo.destroy
6  $vscale_demo = nil
7end
8
9$vscale_demo = TkToplevel.new {|w|
10  title("Vertical Scale Demonstration")
11  iconname("vscale")
12}
13positionWindow($vscale_demo)
14
15base_frame = TkFrame.new($vscale_demo).pack(:fill=>:both, :expand=>true)
16
17msg = TkLabel.new(base_frame) {
18  font $font
19  wraplength '3.5i'
20  justify 'left'
21#  text "下には矢印が1つと乗直なスケールが表示されています。\
22#スケール上でマウスボタン1をクリック、またはドラッグすると\
23#矢印の長さを変えることができます。"
24  text "にはバーと縦型のスケールが表示されています。スケールでマウスのボタン1 をクリックするかドラッグしてバーの高さを変えることができます。終ったら「了解」ボタンを押してください。"
25}
26msg.pack('side'=>'top', 'padx'=>'.5c')
27
28TkFrame.new(base_frame) {|frame|
29  TkButton.new(frame) {
30    #text '了解'
31    text '閉じる'
32    command proc {
33      tmppath = $vscale_demo
34      $vscale_demo = nil
35      tmppath.destroy
36    }
37  }.pack('side'=>'left', 'expand'=>'yes')
38
39  TkButton.new(frame) {
40    text 'コード参照'
41    command proc { showCode 'vscale' }
42  }.pack('side'=>'left', 'expand'=>'yes')
43}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
44
45def setHeight(w, height)
46  height = height + 21
47  y2 = height - 30
48  if y2 < 21
49    y2 = 21
50  end
51  w.coords 'poly',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
52  w.coords 'line',15,20,35,20,35,y2,45,y2,25,height,5,y2,15,y2,15,20
53end
54
55TkFrame.new(base_frame) {|frame|
56  borderwidth 10
57  canvas = TkCanvas.new(frame) {|c|
58    width 50
59    height 50
60    bd 0
61    highlightthickness 0
62    TkcPolygon.new(c, 0, 0, 1, 1, 2, 2) {
63      fill 'SeaGreen3'
64      tags 'poly'
65    }
66    TkcLine.new(c, 0, 0, 1, 1, 2, 2, 0, 0) {
67      fill 'black'
68      tags 'line'
69    }
70  }.pack('side'=>'left',  'anchor'=>'nw', 'fill'=>'y')
71  scale = TkScale.new(frame) {
72    orient 'vertical'
73    length 284
74    from 0
75    to 250
76    command proc{|value| setHeight(canvas, value)}
77    tickinterval 50
78  }.pack('side'=>'left', 'anchor'=>'ne')
79  scale.set 75
80}.pack
81