2
# ruler widget demo (called by 'widget')
6
# This method creates a new triangular polygon in a canvas to
7
# represent a tab stop.
10
# c - The canvas window.
11
# x, y - Coordinates at which to create the tab stop.
15
TkcPolygon.new(c, x, y, x+v.size, y+v.size, x-v.size, y+v.size)
18
# toplevel widget ��¸�ߤ���к������
19
if defined?($ruler_demo) && $ruler_demo
24
# demo �Ѥ� toplevel widget ������
25
$ruler_demo = TkToplevel.new {|w|
26
title("Ruler Demonstration")
32
TkLabel.new($ruler_demo, 'font'=>$font, 'wraplength'=>'5i', 'justify'=>'left',
33
'text'=>"���Υ����Х�widget�ϥ롼�顼���Ϸ��Ǥ����롼�顼�α��ˤ���Τϥ��֥��ȥåפΰ�ͤǡ������������ĥ�äƤ��뤳�Ȥˤ�äƥ��֥��ȥåפ��뤳�Ȥ��Ǥ��ޤ����ޤ������Ǥˤ��륿�֥��ȥåפ�ư�������Ȥ�Ǥ��ޤ������֥��ȥåפ�����ޤ��ϲ����ˤ������ɽ�������ޤǥɥ�å�����ȡ��ޥ����ܥ����Υ�������ˤ��Υ��֥��ȥåפϾä��ޤ���"){
38
$ruler_buttons = TkFrame.new($ruler_demo) {|frame|
47
}.pack('side'=>'left', 'expand'=>'yes')
51
command proc{showCode 'ruler'}
52
}.pack('side'=>'left', 'expand'=>'yes')
54
$ruler_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
57
$ruler_canvas = TkCanvas.new($ruler_demo, 'width'=>'14.8c', 'height'=>'2.5c')
58
$ruler_canvas.pack('side'=>'top', 'fill'=>'x')
61
unless Struct.const_defined?("RulerInfo")
62
$demo_rulerInfo = Struct.new("RulerInfo", :grid, :left, :right, :x, :y,
63
:top, :bottom, :size, :normalStyle,
64
:activeStyle, :deleteStyle).new
66
$demo_rulerInfo.grid = '.25c'
67
$demo_rulerInfo.left = TkWinfo.fpixels($ruler_canvas, '1c')
68
$demo_rulerInfo.right = TkWinfo.fpixels($ruler_canvas, '13c')
69
$demo_rulerInfo.top = TkWinfo.fpixels($ruler_canvas, '1c')
70
$demo_rulerInfo.bottom = TkWinfo.fpixels($ruler_canvas, '1.5c')
71
$demo_rulerInfo.size = TkWinfo.fpixels($ruler_canvas, '.2c')
72
$demo_rulerInfo.normalStyle = {'fill'=>'black'}
73
if TkWinfo.depth($ruler_canvas) > 1
74
$demo_rulerInfo.activeStyle = {'fill'=>'red', 'stipple'=>''}
75
$demo_rulerInfo.deleteStyle = {'fill'=>'red',
76
'stipple'=>'@'+[$demo_dir, '..',
77
'images', 'gray25.xbm'].join(File::Separator)}
79
$demo_rulerInfo.activeStyle = {'fill'=>'black', 'stipple'=>''}
80
$demo_rulerInfo.deleteStyle = {'fill'=>'black',
81
'stipple'=>'@'+[$demo_dir, '..',
82
'images', 'gray25.xbm'].join(File::Separator)}
85
TkcLine.new($ruler_canvas,
86
'1c', '0.5c', '1c', '1c', '13c', '1c', '13c', '0.5c', 'width'=>1)
89
TkcLine.new($ruler_canvas, "#{x}c", '1c', "#{x}c", '0.6c', 'width'=>1)
90
TkcLine.new($ruler_canvas, "#{x}.25c", '1c', "#{x}.25c", '0.8c', 'width'=>1)
91
TkcLine.new($ruler_canvas, "#{x}.5c", '1c', "#{x}.5c", '0.7c', 'width'=>1)
92
TkcLine.new($ruler_canvas, "#{x}.75c", '1c', "#{x}.75c", '0.8c', 'width'=>1)
93
TkcText.new($ruler_canvas, "#{x}.15c", '0.75c', 'text'=>i, 'anchor'=>'sw')
96
$rulerTag_well = TkcTag.new($ruler_canvas)
98
.addtag_withtag($rulerTag_well,
99
TkcRectangle.new($ruler_canvas,
100
'13.2c', '1c', '13.8c', '0.5c',
102
'fill'=>($ruler_canvas\
103
.configinfo('background'))[4]) )
105
.addtag_withtag($rulerTag_well,
106
rulerMkTab($ruler_canvas,
107
TkWinfo.pixels($ruler_canvas, '13.5c'),
108
TkWinfo.pixels($ruler_canvas, '.65c') ) )
110
$rulerTag_well.bind('1', proc{|x,y| rulerNewTab($ruler_canvas,x,y)}, '%x %y')
111
$ruler_canvas.itembind('tab', '1',
112
proc{|x,y| rulerSelectTab($ruler_canvas,x,y)}, '%x %y')
113
$ruler_canvas.bind('B1-Motion',
114
proc{|x,y| rulerMoveTab($ruler_canvas,x,y)}, '%x %y')
115
$ruler_canvas.bind('Any-ButtonRelease-1', proc{rulerReleaseTab($ruler_canvas)})
118
# Does all the work of creating a tab stop, including creating the
119
# triangle object and adding tags to it to give it tab behavior.
122
# c - The canvas window.
123
# x, y - The coordinates of the tab stop.
125
def rulerNewTab(c,x,y)
127
c.addtag_withtag('active', rulerMkTab(c,x,y))
128
c.addtag_withtag('tab', 'active')
135
# This method is invoked when mouse button 1 is pressed over
136
# a tab. It remembers information about the tab so that it can
137
# be dragged interactively.
140
# c - The canvas widget.
141
# x, y - The coordinates of the mouse (identifies the point by
142
# which the tab was picked up for dragging).
144
def rulerSelectTab(c,x,y)
146
v.x = c.canvasx(x, v.grid)
148
c.addtag_withtag('active', 'current')
149
c.itemconfigure('active', v.activeStyle)
154
# This method is invoked during mouse motion events to drag a tab.
155
# It adjusts the position of the tab, and changes its appearance if
156
# it is about to be dragged out of the ruler.
159
# c - The canvas widget.
160
# x, y - The coordinates of the mouse.
162
def rulerMoveTab(c,x,y)
164
return if c.find_withtag('active') == []
165
cx = c.canvasx(x,v.grid)
167
cx = v.left if cx < v.left
168
cx = v.right if cx > v.right
169
if (cy >= v.top && cy <= v.bottom)
171
c.itemconfigure('active', v.activeStyle)
174
c.itemconfigure('active', v.deleteStyle)
176
c.move('active', cx-v.x, cy-v.y)
182
# This method is invoked during button release events that end
183
# a tab drag operation. It deselects the tab and deletes the tab if
184
# it was dragged out of the ruler.
187
# c - The canvas widget.
188
# x, y - The coordinates of the mouse.
190
def rulerReleaseTab(c)
192
return if c.find_withtag('active') == []
196
c.itemconfigure('active', v.normalStyle)