1# -*- coding: utf-8 -*-
2require "tkcanvas"
3
4if defined?($hscale_demo) && $hscale_deom
5  $hscale_demo.destroy
6  $hscale_demo = nil
7end
8
9$hscale_demo = TkToplevel.new {|w|
10  title("Horizontal Scale Demonstration")
11  iconname("hscale")
12}
13positionWindow($hscale_demo)
14
15base_frame = TkFrame.new($hscale_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}
25msg.pack('side'=>'top')
26
27TkFrame.new(base_frame) {|frame|
28  TkButton.new(frame) {
29    #text '了解'
30    text '閉じる'
31    command proc {
32      tmppath = $hscale_demo
33      $hscale_demo = nil
34      tmppath.destroy
35    }
36  }.pack('side'=>'left', 'expand'=>'yes')
37
38  TkButton.new(frame) {
39    text 'コード参照'
40    command proc { showCode 'hscale' }
41  }.pack('side'=>'left', 'expand'=>'yes')
42}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
43
44def setWidth(w, width)
45  width = width + 21
46  x2 = width - 30
47  if x2 < 21
48    x2 = 21
49  end
50  w.coords 'poly',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
51  w.coords 'line',20,15,20,35,x2,35,x2,45,width,25,x2,5,x2,15,20,15
52end
53
54TkFrame.new(base_frame) {|frame|
55  canvas = TkCanvas.new(frame) {|c|
56    width 50
57    height 50
58    bd 0
59    highlightthickness 0
60    TkcPolygon.new(c, '0', '0', '1', '1', '2', '2') {
61      fill 'DeepSkyBlue'
62      tags 'poly'
63    }
64    TkcLine.new(c, '0', '0', '1', '1', '2', '2', '0', '0') {
65      fill 'black'
66      tags 'line'
67    }
68  }.pack('side'=>'top', 'expand'=>'yes', 'anchor'=>'s', 'fill'=>'x', 'padx'=>'15')
69  scale = TkScale.new(frame) {
70    orient 'horizontal'
71    length 284
72    from 0
73    to 250
74    command proc{|value| setWidth(canvas, value)}
75    tickinterval 50
76  }.pack('side'=>'bottom', 'expand'=>'yes', 'anchor'=>'n')
77  scale.set 75
78}.pack('side'=>'top', 'fill'=>'x')
79