1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/sample/demos-jp/puzzle.rb

116 lines
2.9 KiB
Ruby
Raw Normal View History

#
# widet demo 'puzzle' (called by 'widget')
#
# toplevel widget <20><>¸<EFBFBD>ߤ<EFBFBD><DFA4><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if defined?($puzzle_demo) && $puzzle_demo
$puzzle_demo.destroy
$puzzle_demo = nil
end
# demo <20>Ѥ<EFBFBD> toplevel widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
$puzzle_demo = TkToplevel.new {|w|
title("15-Puzzle Demonstration")
iconname("15-Puzzle")
positionWindow(w)
}
# label <20><><EFBFBD><EFBFBD>
msg = TkLabel.new($puzzle_demo) {
font $font
wraplength '4i'
justify 'left'
text "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>15-<2D>ѥ<EFBFBD><D1A5><EFBFBD><EFBFBD>ϥܥ<CFA5><DCA5><EFBFBD><EFBFBD>򽸤<EFBFBD><F2BDB8A4>ƤǤ<C6A4><C7A4>Ƥ<EFBFBD><C6A4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>٤Υԡ<CEA5><D4A1><EFBFBD><EFBFBD>򥯥<EFBFBD><F2A5AFA5>å<EFBFBD><C3A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Υԡ<CEA5><D4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><CEB6><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˥<EFBFBD><CBA5><EFBFBD>ɤ<EFBFBD><C9A4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD>ԡ<EFBFBD><D4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><CEBF>ν<EFBFBD><CEBD>˾夫<CBBE><EFBFBD><E9B2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9B1A6><EFBFBD>¤֤褦<D6A4>ˤ<EFBFBD><CBA4>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
}
msg.pack('side'=>'top')
# frame <20><><EFBFBD><EFBFBD>
TkFrame.new($puzzle_demo) {|frame|
TkButton.new(frame) {
text <><CEBB>'
command proc{
tmppath = $puzzle_demo
$puzzle_demo = nil
tmppath.destroy
}
}.pack('side'=>'left', 'expand'=>'yes')
TkButton.new(frame) {
text '<27><><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>'
command proc{showCode 'puzzle'}
}.pack('side'=>'left', 'expand'=>'yes')
}.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
# frame <20><><EFBFBD><EFBFBD>
#
# Special trick: scrollbar widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD> trough color <20><><EFBFBD>Ѥ<EFBFBD><D1A4><EFBFBD>Ȥ<EFBFBD>
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʬ<EFBFBD>Τ<EFBFBD><CEA4><EFBFBD><EFBFBD>ΰſ<CEB0><C5BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򤷡<EFBFBD><F2A4B7A1><EFBFBD><EFBFBD><EFBFBD><EAA4B9>
#
begin
if Tk.windowingsystem() == 'aqua'
frameSize = 160
else
frameSize = 120
end
rescue
frameSize = 120
end
s = TkScrollbar.new($puzzle_demo)
base = TkFrame.new($puzzle_demo) {
width frameSize
height frameSize
borderwidth 2
relief 'sunken'
bg s['troughcolor']
}
s.destroy
base.pack('side'=>'top', 'padx'=>'1c', 'pady'=>'1c')
# proc <20>Υ<EFBFBD><CEA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>פ<EFBFBD><D7A4>Ĥ<EFBFBD><C4A4>뤿<EFBFBD>ᡤproc <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>åɤ<C3A5><C9A4>Ѱ<EFBFBD>
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD>ͤС<CDA4><D0A1><EFBFBD><EBA1BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͤ<EFBFBD><CDA4>Ѳ<EFBFBD><D1B2><EFBFBD><EFBFBD><EFBFBD> num <20>αƶ<CEB1><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
# puzzleSwitch <20><><EFBFBD><EFBFBD> 2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѳ<EFBFBD><D1B2><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4>ޤ<EFBFBD><DEA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̤<EFBFBD><CCA4>ˤϤʤ<CFA4><CAA4>ʤ<EFBFBD><CAA4><EFBFBD>
def def_puzzleswitch_proc(w, num)
proc{puzzleSwitch w, num}
end
$xpos = {}
$ypos = {}
order = [3,1,6,2,5,7,15,13,4,11,8,9,14,10,12]
(0..14).each{|i|
num = order[i]
$xpos[num] = (i % 4) * 0.25
$ypos[num] = (i / 4) * 0.25
TkButton.new(base) {|w|
relief 'raised'
text num
highlightthickness 0
command def_puzzleswitch_proc(w, num)
}.place('relx'=>$xpos[num], 'rely'=>$ypos[num],
'relwidth'=>0.25, 'relheight'=>0.25)
}
$xpos['space'] = 0.75
$ypos['space'] = 0.75
############
def puzzleSwitch(w, num)
if ( ($ypos[num] >= ($ypos['space'] - 0.01)) \
&& ($ypos[num] <= ($ypos['space'] + 0.01)) \
&& ($xpos[num] >= ($xpos['space'] - 0.26)) \
&& ($xpos[num] <= ($xpos['space'] + 0.26))) \
|| (($xpos[num] >= ($xpos['space'] - 0.01)) \
&& ($xpos[num] <= ($xpos['space'] + 0.01)) \
&& ($ypos[num] >= ($ypos['space'] - 0.26)) \
&& ($ypos[num] <= ($ypos['space'] + 0.26)))
tmp = $xpos['space']
$xpos['space'] = $xpos[num]
$xpos[num] = tmp
tmp = $ypos['space']
$ypos['space'] = $ypos[num]
$ypos[num] = tmp
w.place('relx'=>$xpos[num], 'rely'=>$ypos[num])
end
end