2
# 2-D plot widget demo (called by 'widget')
5
# toplevel widget ��¸�ߤ���к������
6
if defined?($plot_demo) && $plot_demo
11
# demo �Ѥ� toplevel widget ������
12
$plot_demo = TkToplevel.new {|w|
13
title("Plot Demonstration")
19
TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left',
20
'text'=>"���Υ�����ɥ��ϴ�ñ��2�����Υץ��åȤ�ޤ�������Х� widget�Ǥ���ɽ�����줿����ޥ����ܥ���1�ǥɥ�å����ƥǡ������뤳�Ȥ��Ǥ��ޤ���"){
25
$plot_buttons = TkFrame.new($plot_demo) {|frame|
34
}.pack('side'=>'left', 'expand'=>'yes')
38
command proc{showCode 'plot'}
39
}.pack('side'=>'left', 'expand'=>'yes')
41
$plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
44
plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
47
$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300)
48
$plot_canvas.pack('side'=>'top', 'fill'=>'x')
51
TkcLine.new($plot_canvas, 100, 250, 400, 250, 'width'=>2)
52
TkcLine.new($plot_canvas, 100, 250, 100, 50, 'width'=>2)
53
TkcText.new($plot_canvas, 225, 20,
54
'text'=>"��ñ�ʥץ��å�", 'font'=>plotFont, 'fill'=>'brown')
58
TkcLine.new($plot_canvas, x, 250, x, 245, 'width'=>2)
59
TkcText.new($plot_canvas, x, 254,
60
'text'=>10*i, 'font'=>plotFont, 'anchor'=>'n')
64
TkcLine.new($plot_canvas, 100, y, 105, y, 'width'=>2)
65
TkcText.new($plot_canvas, 96, y,
66
'text'=>"#{i*50}.0", 'font'=>plotFont, 'anchor'=>'e')
69
for xx, yy in [[12,56],[20,94],[33,98],[32,120],[61,180],[75,160],[98,223]]
72
item = TkcOval.new($plot_canvas, x-6, y-6, x+6, y+6,
73
'width'=>1, 'outline'=>'black', 'fill'=>'SkyBlue2')
77
$plot_canvas.itembind('point', 'Any-Enter',
78
proc{$plot_canvas.itemconfigure 'current','fill','red'})
79
$plot_canvas.itembind('point', 'Any-Leave',
80
proc{$plot_canvas.itemconfigure 'current','fill','SkyBlue2'})
81
$plot_canvas.itembind('point', '1',
82
proc{|x,y| plotDown $plot_canvas,x,y}, "%x %y")
83
$plot_canvas.itembind('point', 'ButtonRelease-1',
84
proc{$plot_canvas.dtag 'selected'})
85
$plot_canvas.bind('B1-Motion',
86
proc{|x,y| plotMove $plot_canvas,x,y}, "%x %y")
88
$plot = {'lastX'=>0, 'lastY'=>0}
91
# This method is invoked when the mouse is pressed over one of the
92
# data points. It sets up state to allow the point to be dragged.
95
# w - The canvas window.
96
# x, y - The coordinates of the mouse press.
98
def plotDown (w, x, y)
100
w.addtag_withtag 'selected', 'current'
107
# This method is invoked during mouse motion events. It drags the
111
# w - The canvas window.
112
# x, y - The coordinates of the mouse.
114
def plotMove (w, x, y)
115
w.move 'selected', x - $plot['lastX'], y - $plot['lastY']