1 |
package game::goclock; |
2 |
|
3 |
use Time::HiRes (); |
4 |
|
5 |
use KGS::Constants; |
6 |
|
7 |
use base gtk::widget; |
8 |
|
9 |
sub new { |
10 |
my $class = shift; |
11 |
my $self = $class->SUPER::new(@_); |
12 |
|
13 |
$self->{widget} = new Gtk2::Label; |
14 |
|
15 |
$self->{set} = sub { }; |
16 |
$self->{format} = sub { "ERROR" }; |
17 |
|
18 |
$self; |
19 |
} |
20 |
|
21 |
sub append_text { |
22 |
my ($self, $text) = @_; |
23 |
|
24 |
$self->{buffer}->insert ($self->{buffer}->get_end_iter, $text); |
25 |
} |
26 |
|
27 |
sub format_time { |
28 |
my ($time) = @_; |
29 |
|
30 |
$time > 60*60 |
31 |
? sprintf "%d:%02d:%02d", $time / (60 * 60), $time / 60 % 60, $time % 60 |
32 |
: sprintf "%d:%02d", $time / 60 % 60, $time % 60; |
33 |
} |
34 |
|
35 |
sub set_rules { |
36 |
my ($self, $timesys, $main, $interval, $count) = @_; |
37 |
|
38 |
if ($timesys == TIMESYS_ABSOLUTE) { |
39 |
$self->{set} = sub { $self->{time} = $_[0] }; |
40 |
$self->{format} = sub { format_time $_[0] }; |
41 |
|
42 |
} elsif ($timesys == TIMESYS_BYO_YOMI) { |
43 |
my $low = $interval * $count; |
44 |
|
45 |
$self->{set} = sub { $self->{time} = $_[0] }; |
46 |
|
47 |
$self->{format} = sub { |
48 |
if ($_[0] > $low) { |
49 |
format_time $_[0]; |
50 |
} else { |
51 |
sprintf "%s (%d)", (format_time int ($_[0] % $interval) || $interval), $_[0] / $interval; |
52 |
} |
53 |
}; |
54 |
|
55 |
} elsif ($timesys == TIMESYS_CANADIAN) { |
56 |
my $low = $interval; |
57 |
|
58 |
$self->{set} = sub { $self->{time} = $_[0]; $self->{moves} = $_[1] }; |
59 |
|
60 |
$self->{format} = sub { |
61 |
if ($_[0] > $low) { |
62 |
format_time $_[0]; |
63 |
} else { |
64 |
sprintf "%s / %d", (format_time int($_[0] % $interval) || $interval), $self->{moves}; |
65 |
} |
66 |
}; |
67 |
|
68 |
} else { |
69 |
# none, or unknown |
70 |
$self->{set} = sub { }; |
71 |
$self->{format} = sub { "---" } |
72 |
} |
73 |
} |
74 |
|
75 |
sub refresh { |
76 |
my ($self, $timestamp) = @_; |
77 |
my $timer = $self->{time} + $self->{start} - $timestamp; |
78 |
$self->{widget}->set_text ($self->{format}->($timer)); |
79 |
|
80 |
warn "Timer $timer\n"; |
81 |
$timer - int $timer; |
82 |
} |
83 |
|
84 |
sub set_time { |
85 |
my ($self, $time) = @_; |
86 |
|
87 |
$self->{start} = $time->[0]; |
88 |
$self->{set}->($time->[1], $time->[2]); |
89 |
|
90 |
$self->refresh ($time->[0]); |
91 |
} |
92 |
|
93 |
sub start { |
94 |
my ($self) = @_; |
95 |
|
96 |
return if $self->{timeout}; |
97 |
|
98 |
my $timeout; $timeout = sub { |
99 |
my $next = int ($self->refresh (Time::HiRes::time) * 1000); |
100 |
warn "next $next\n"; |
101 |
$self->{timeout} = add Glib::Timeout $next, $timeout; |
102 |
0; |
103 |
}; |
104 |
|
105 |
$timeout->(); |
106 |
} |
107 |
|
108 |
sub stop { |
109 |
my ($self) = @_; |
110 |
|
111 |
remove Glib::Source delete $self->{timeout} if $self->{timeout}; |
112 |
} |
113 |
|
114 |
package game::userpanel; |
115 |
|
116 |
use base gtk::widget; |
117 |
|
118 |
sub new { |
119 |
my $class = shift; |
120 |
my $self = $class->SUPER::new(@_); |
121 |
|
122 |
$self->{widget} = new Gtk2::VBox; |
123 |
|
124 |
$self->{widget}->add ($self->{name} = new Gtk2::Label $self->{name}); |
125 |
$self->{widget}->add ($self->{info} = new Gtk2::Label ""); |
126 |
$self->{widget}->add (($self->{clock} = new game::goclock)->widget); |
127 |
|
128 |
$self; |
129 |
} |
130 |
|
131 |
sub set_rules { |
132 |
my ($self, $rules) = @_; |
133 |
|
134 |
$self->{name}->set_text ($rules->{player}[$self->{colour}]); |
135 |
$self->{clock}->set_rules (@{$rules->{rules}}{qw(timesys time interval count)}); |
136 |
} |
137 |
|
138 |
sub set_state { |
139 |
my ($self, $captures, $timer, $running) = @_; |
140 |
|
141 |
$self->{clock}->set_time ($timer); |
142 |
$running ? $self->{clock}->start : $self->{clock}->stop; |
143 |
$self->{info}->set_text ("$captures pris."); |
144 |
} |
145 |
|
146 |
package game; |
147 |
|
148 |
use KGS::Constants; |
149 |
use KGS::Game::Board; |
150 |
|
151 |
use base KGS::Listener::Game; |
152 |
use base KGS::Game; |
153 |
|
154 |
use base gtk::widget; |
155 |
|
156 |
use POSIX qw(ceil); |
157 |
|
158 |
sub new { |
159 |
my $self = shift; |
160 |
$self = $self->SUPER::new(@_); |
161 |
|
162 |
$self->listen($self->{conn}); |
163 |
|
164 |
$self->{window} = new Gtk2::Window 'toplevel'; |
165 |
my $title = $self->{channel} ? $self->owner->as_string." ".$self->opponent_string : "Game Window"; |
166 |
$self->{window}->set_title("KGS Game $title"); |
167 |
gtk::state $self->{window}, "game::window", undef, window_size => [600, 500]; |
168 |
|
169 |
$self->{window}->signal_connect(delete_event => sub { |
170 |
$self->part; |
171 |
1; |
172 |
}); |
173 |
|
174 |
$self->{window}->add($self->{hpane} = new Gtk2::HPaned); |
175 |
gtk::state $self->{hpane}, "game::hpane", undef, position => 500; |
176 |
|
177 |
$self->{hpane}->pack1((my $vbox = new Gtk2::VBox), 1, 1); |
178 |
|
179 |
$vbox->pack_start((my $frame = new Gtk2::Frame), 0, 1, 0); |
180 |
|
181 |
{ |
182 |
# grrr... |
183 |
$frame->add(my $vbox = new Gtk2::VBox); |
184 |
$vbox->add($self->{title} = new Gtk2::Label $title); |
185 |
|
186 |
$self->{moveadj} = new Gtk2::Adjustment 1, 0, 1, 0.001, 0.05, 0; |
187 |
|
188 |
$vbox->add(my $scale = new Gtk2::HScale $self->{moveadj}); |
189 |
$scale->set_draw_value (0); |
190 |
|
191 |
$self->{moveadj}->signal_connect (value_changed => sub { $self->update_board }); |
192 |
} |
193 |
|
194 |
$vbox->pack_start((my $aspect_frame = new Gtk2::AspectFrame "", 0.5, 0.5, 1, 0), 1, 1, 0); |
195 |
$aspect_frame->set (border_width => 0, shadow_type => 'none', label_xalign => 0.5); |
196 |
$self->{board_label} = $aspect_frame->get_label_widget; |
197 |
|
198 |
$aspect_frame->add($self->{canvas} = new Gtk2::DrawingArea); |
199 |
$self->{canvas}->double_buffered (0) if $::config->{conserve_memory}; |
200 |
|
201 |
$self->{canvas}->signal_connect(configure_event => \&configure_event, $self); |
202 |
$self->{canvas}->signal_connect(expose_event => \&expose_event, $self); |
203 |
|
204 |
# RIGHT PANE |
205 |
|
206 |
$self->{hpane}->pack2(($self->{vpane} = new Gtk2::VPaned), 0, 0); |
207 |
$self->{hpane}->set(position_set => 1); |
208 |
gtk::state $self->{vpane}, "game::vpane", $self->{name}, position => 80; |
209 |
|
210 |
$self->{vpane}->add(my $sw = new Gtk2::ScrolledWindow); |
211 |
$sw->set_policy("automatic", "always"); |
212 |
|
213 |
$sw->add(($self->{userlist} = new userlist)->widget); |
214 |
|
215 |
$self->{vpane}->add(my $vbox = new Gtk2::VBox); |
216 |
|
217 |
$vbox->pack_start((my $hbox = new Gtk2::HBox 1), 0, 1, 0); |
218 |
$hbox->add (($self->{user0} = new game::userpanel colour => WHITE)->widget); |
219 |
$hbox->add (($self->{user1} = new game::userpanel colour => BLACK)->widget); |
220 |
|
221 |
$vbox->pack_start((my $sw = new Gtk2::ScrolledWindow), 1, 1, 0); |
222 |
$sw->set_policy("never", "always"); |
223 |
|
224 |
$sw->add(($self->{text} = new gtk::text)->widget); |
225 |
|
226 |
$vbox->pack_start(($self->{entry} = new Gtk2::Entry), 0, 1, 0); |
227 |
$self->{entry}->signal_connect(activate => sub { |
228 |
my $text = $self->{entry}->get_text; |
229 |
$self->say($text) if $text =~ /\S/; |
230 |
$self->{entry}->set_text(""); |
231 |
}); |
232 |
|
233 |
$self; |
234 |
} |
235 |
|
236 |
sub event_update_users { |
237 |
my ($self, $add, $update, $remove) = @_; |
238 |
|
239 |
$self->{userlist}->update ($add, $update, $remove); |
240 |
} |
241 |
|
242 |
sub join { |
243 |
my ($self) = @_; |
244 |
return if $self->{joined}; |
245 |
|
246 |
$self->SUPER::join; |
247 |
|
248 |
$self->{window}->show_all; |
249 |
} |
250 |
|
251 |
sub part { |
252 |
my ($self) = @_; |
253 |
|
254 |
$self->SUPER::part; |
255 |
$self->destroy; |
256 |
} |
257 |
|
258 |
sub configure_event { |
259 |
my ($widget, $event, $self) = @_; |
260 |
delete $self->{stack}; |
261 |
delete $self->{pixbuf}; |
262 |
delete $self->{board_shown}; |
263 |
delete $self->{background}; |
264 |
$self->repaint_board; |
265 |
0; |
266 |
} |
267 |
|
268 |
sub expose_event { |
269 |
my ($widget, $event, $self) = @_; |
270 |
|
271 |
$self->{pixbuf} or return; |
272 |
|
273 |
my $area = $event->area; |
274 |
|
275 |
$self->redraw ($area); |
276 |
|
277 |
0; |
278 |
} |
279 |
|
280 |
# something Gtk2 fixed |
281 |
sub INTERP_NEAREST (){ 'nearest' } |
282 |
sub INTERP_TILES (){ 'tiles' } |
283 |
sub INTERP_BILINEAR (){ 'bilinear' } |
284 |
sub INTERP_HYPER (){ 'hyper' } |
285 |
|
286 |
sub new_pixbuf { |
287 |
my ($w, $h, $alpha, $fill) = @_; |
288 |
|
289 |
my $pixbuf = new Gtk2::Gdk::Pixbuf 'rgb', $alpha, 8, $w, $h; |
290 |
$pixbuf->fill ($fill) if defined $fill; |
291 |
|
292 |
$pixbuf; |
293 |
} |
294 |
|
295 |
sub scale_pixbuf { |
296 |
my ($src, $w, $h, $mode) = @_; |
297 |
|
298 |
my $dst = new_pixbuf $w, $h, 1; |
299 |
|
300 |
$src->scale( |
301 |
$dst, 0, 0, $w, $h, 0, 0, |
302 |
$w / $src->get_width, $h / $src->get_height, |
303 |
$mode, |
304 |
); |
305 |
|
306 |
$dst; |
307 |
} |
308 |
|
309 |
# create a stack of stones |
310 |
sub create_stack { |
311 |
my ($self, $mark, $size, $rand) = @_; |
312 |
|
313 |
my $shadow = $size * 0.05; |
314 |
|
315 |
my $c = \$self->{stack}{$mark}; |
316 |
unless ($$c) { |
317 |
for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) { |
318 |
my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 0x00000000; |
319 |
|
320 |
# zeroeth the shadow |
321 |
if ($mark & (MARK_B | MARK_W)) { |
322 |
$::shadow_img->composite ( |
323 |
$base, $shadow, $shadow, $size, $size, $shadow - 0.5, $shadow - 0.5, |
324 |
$size / $stone->get_width, $size / $stone->get_height, |
325 |
$::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192 |
326 |
); |
327 |
} |
328 |
|
329 |
# first the big stones (handicap stones different for effect) |
330 |
for ([MARK_B, $mark & MARK_MOVE ? 255 : 192], |
331 |
[MARK_W, $mark & MARK_MOVE ? 255 : 192], |
332 |
[MARK_GRAY_B, 128], |
333 |
[MARK_GRAY_W, 128]) { |
334 |
my ($mask, $alpha) = @$_; |
335 |
if ($mark & $mask) { |
336 |
$stone->composite ( |
337 |
$base, 0, 0, $size, $size, 0, 0, |
338 |
$size / $stone->get_width, $size / $stone->get_height, |
339 |
$::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, $alpha |
340 |
); |
341 |
} |
342 |
} |
343 |
|
344 |
# then the small stones |
345 |
for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]], |
346 |
[MARK_SMALL_W, $::white_img[$rand % @::white_img]]) { |
347 |
my ($mask, $img) = @$_; |
348 |
if ($mark & $mask) { |
349 |
$img->composite ( |
350 |
$base, (ceil ($size / 4)) x2, (ceil ($size / 2)) x2, (ceil ($size / 4)) x2, |
351 |
$size / $img->get_width / 2, $size / $img->get_height / 2, |
352 |
$::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 224 |
353 |
); |
354 |
} |
355 |
} |
356 |
|
357 |
# and lastly any markers |
358 |
my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B)); |
359 |
|
360 |
for ([MARK_CIRCLE, $::circle_img[$dark_bg]], |
361 |
[MARK_TRIANGLE, $::triangle_img[$dark_bg]], |
362 |
[MARK_SQUARE, $::square_img[$dark_bg]]) { |
363 |
my ($mask, $img) = @$_; |
364 |
if ($mark & $mask) { |
365 |
$img->composite ( |
366 |
$base, 0, 0, $size, $size, -0.5, -0.5, |
367 |
$size / $img->get_width, $size / $img->get_height, |
368 |
$::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255 |
369 |
); |
370 |
} |
371 |
} |
372 |
|
373 |
push @$$c, $base; |
374 |
} |
375 |
} |
376 |
|
377 |
$$c->[$rand % @$$c]; |
378 |
} |
379 |
|
380 |
sub pixbuf_text { |
381 |
my ($pixbuf, $colour, $x, $y, $height, $text) = @_; |
382 |
|
383 |
my @c = grep $_, |
384 |
map $::font[$colour][$::fontmap{$_}], |
385 |
split //, $text; |
386 |
|
387 |
if (@c) { |
388 |
my $spacing = $height * 0.1; |
389 |
my $s = $height / List::Util::max map $_->get_height, @c; |
390 |
my $W = List::Util::sum map $_->get_width, @c; |
391 |
|
392 |
$x -= ($W * $s + $spacing * (@c - 1)) * 0.5; |
393 |
$y -= $height * 0.5; |
394 |
|
395 |
for (@c) { |
396 |
my $w = $_->get_width * $s; |
397 |
# +2 == don't fight the rounding |
398 |
$_->composite ($pixbuf, |
399 |
$x, $y, $w+2, $height+2, $x, $y, $s, $s, |
400 |
$::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255); |
401 |
|
402 |
$x += $w + $spacing; |
403 |
} |
404 |
} |
405 |
} |
406 |
|
407 |
sub pixbuf_rect { |
408 |
my ($pb, $colour, $x1, $y1, $x2, $y2, $alpha) = @_; |
409 |
# we fake lines by... a horrible method :/ |
410 |
my $colour_pb = new_pixbuf 1, 1, 0, $colour; |
411 |
$colour_pb->composite ($pb, $x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1, $x1, $y1, $x2 + 1, $y2 + 1, |
412 |
INTERP_NEAREST, $alpha); |
413 |
} |
414 |
|
415 |
sub repaint_board { |
416 |
my ($self) = @_; |
417 |
my $canvas = $self->{canvas}; |
418 |
my $expose_area = undef; |
419 |
|
420 |
return $expose_area unless $self->{board}; |
421 |
|
422 |
my ($w, $h) = ($canvas->allocation->values)[2,3]; |
423 |
|
424 |
die "FATAL: board aspect ratio != 1" unless $w == $h; |
425 |
|
426 |
my $s = $w; |
427 |
|
428 |
return unless $s >= 200; |
429 |
|
430 |
my $size = $self->{size}; |
431 |
|
432 |
# we leave enough space for the shadows.. I like smaller stones, and we |
433 |
# do no need to do the nifty recursive screen updates that goban2 does |
434 |
my $border = int ($s / ($size + 3) * 0.5); |
435 |
my $s2 = $s - $border * 2; |
436 |
my $edge = int ($s2 / ($size + 1) * 0.96) - ($::config->{randomize} ? 3 : 0); |
437 |
my $ofs = int ($edge / 2); |
438 |
|
439 |
my @k = map int ($s2 * $_ / ($size+1) + $border + 0.5), 0 .. $size; |
440 |
|
441 |
my $pixbuf; |
442 |
|
443 |
my $oldboard; |
444 |
|
445 |
if ($self->{background}) { |
446 |
if ($oldboard = $self->{board_shown}) { |
447 |
$pixbuf = $self->{pixbuf}; |
448 |
} else { |
449 |
$pixbuf = $self->{background}->copy; |
450 |
$expose_area = new Gtk2::Gdk::Rectangle 0, 0, $s, $s; |
451 |
} |
452 |
} else { |
453 |
$expose_area = new Gtk2::Gdk::Rectangle 0, 0, $s, $s; |
454 |
|
455 |
my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height); |
456 |
|
457 |
if ($s < $bw && $s < $bh) { |
458 |
$pixbuf = new_pixbuf $s, $s, 0; |
459 |
$::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0); |
460 |
} else { |
461 |
$pixbuf = scale_pixbuf $::board_img, $s, $s, $::config->{speed} ? INTERP_NEAREST : INTERP_TILES; |
462 |
} |
463 |
|
464 |
my $linew = int ($s / 25 / $size); |
465 |
|
466 |
# ornamental border... we have time to waste :/ |
467 |
pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $s-1, $linew, 255; |
468 |
pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $s-1, 255; |
469 |
pixbuf_rect $pixbuf,0xffcc7700, $s-$linew-1, 0, $s-1, $s-1, 255; |
470 |
pixbuf_rect $pixbuf,0xffcc7700, 0, $s-$linew-1, $s-1, $s-1, 255; |
471 |
|
472 |
for my $i (1 .. $size) { |
473 |
pixbuf_rect $pixbuf, 0x44111100, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew, 192; |
474 |
pixbuf_rect $pixbuf, 0x44111100, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew, 192; |
475 |
|
476 |
# 38 max, but we allow a bit more |
477 |
my $label = (qw(- A B C D E F G H J K L M N O P Q R S T U V W X Y Z |
478 |
AA BB CC DD EE FF GG HH JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ))[$i]; |
479 |
|
480 |
pixbuf_text $pixbuf, 0, $k[$i], $border, $ofs, $label; |
481 |
pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border, $ofs, $label; |
482 |
pixbuf_text $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1; |
483 |
pixbuf_text $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1; |
484 |
|
485 |
$a++; |
486 |
$a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... |
487 |
} |
488 |
|
489 |
unless ($::config->{conserve_memory} > 1) { |
490 |
$self->{background} = $pixbuf; |
491 |
$pixbuf = $pixbuf->copy; |
492 |
} |
493 |
} |
494 |
|
495 |
$self->{pixbuf} = $pixbuf; |
496 |
|
497 |
# hoshi-points(!)#d# |
498 |
# caching of empty board gfx(!)#d# |
499 |
|
500 |
for my $x (1 .. $size) { |
501 |
for my $y (1 .. $size) { |
502 |
my $rand = ($x ^ $y ^ 0x5555); |
503 |
|
504 |
my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs); |
505 |
|
506 |
if ($::config->{randomize}) { |
507 |
$dx += ($rand % 7) - 3; |
508 |
$dy += ($rand / 3 % 7) - 3; |
509 |
} |
510 |
|
511 |
my $shadow = $edge * 0.05; |
512 |
my $area = [$dx, $dy, $edge + $shadow, $edge + $shadow]; |
513 |
|
514 |
my $mark = $self->{board}{board}[$x-1][$y-1]; |
515 |
my $old = $oldboard ? $oldboard->{board}[$x-1][$y-1] : 0; |
516 |
|
517 |
if ($oldboard) { |
518 |
next if $old == $mark; # no change |
519 |
|
520 |
$self->{background}->copy_area (@$area, $pixbuf, $dx, $dy); |
521 |
$expose_area = $expose_area |
522 |
? $expose_area->union (new Gtk2::Gdk::Rectangle @$area) |
523 |
: new Gtk2::Gdk::Rectangle @$area; |
524 |
} |
525 |
|
526 |
if ($mark) { |
527 |
my $pb = $self->create_stack($mark, $edge, $rand); |
528 |
|
529 |
$pb->composite ($pixbuf, @$area, |
530 |
$dx, $dy, 1, 1, $::config->{speed} ? INTERP_NEAREST : INTERP_NEAREST, 255); |
531 |
|
532 |
# labels are handled here because they are quite rare |
533 |
if ($mark & MARK_LABEL) { |
534 |
my $white = $mark & (MARK_W | MARK_GRAY_W) ? 0 : 1; |
535 |
|
536 |
if ($white) { |
537 |
pixbuf_text $pixbuf, 0, |
538 |
$k[$x] + $ofs * 0.1, $k[$y] + $ofs * 0.1, $ofs * 0.7, |
539 |
$self->{board}{label}[$x-1][$y-1]; |
540 |
} |
541 |
pixbuf_text $pixbuf, $white, |
542 |
$k[$x], $k[$y], $ofs * 0.7, |
543 |
$self->{board}{label}[$x-1][$y-1]; |
544 |
} |
545 |
|
546 |
# old pixmap&mask-way. that was fast ;( |
547 |
#my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 ); |
548 |
|
549 |
#$gc->set_clip_mask ($bm); |
550 |
#$gc->set_clip_origin ($dx, $dy); |
551 |
#$pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge); |
552 |
} |
553 |
} |
554 |
} |
555 |
|
556 |
$self->{board_shown} = Storable::dclone $self->{board}; |
557 |
#d# save |
558 |
#Storable::nstore { board => $self->{board}, size => $self->{size}, path => $self->{path}}, "testboard.storable"; |
559 |
|
560 |
$expose_area; |
561 |
} |
562 |
|
563 |
sub redraw { |
564 |
my ($self, $area) = @_; |
565 |
|
566 |
if ($area && $self->{pixbuf}) { |
567 |
my ($x, $y, $w, $h) = $area->values; |
568 |
|
569 |
$self->{canvas}->window->draw_pixbuf ($self->{canvas}->style->white_gc, $self->{pixbuf}, |
570 |
$x, $y, $x, $y, $w, $h, |
571 |
"normal", 0, 0); |
572 |
$self->{canvas}->window->draw_rectangle ($self->{canvas}->style->black_gc, 0, |
573 |
$x - 1, $y - 1, $w + 2, $h + 2) if $::DEBUG_EXPOSE; |
574 |
} |
575 |
} |
576 |
|
577 |
sub update_board { |
578 |
my ($self) = @_; |
579 |
return unless $self->{path}; |
580 |
|
581 |
$self->{NOW} = Time::HiRes::time; #d# get from msg(!) |
582 |
|
583 |
my $move = int (@{$self->{path}} * $self->{moveadj}->get_value); |
584 |
|
585 |
my $running = $move == @{$self->{path}}; |
586 |
|
587 |
$self->{board_label}->set_text ("Move $move"); |
588 |
|
589 |
$self->{board} = new KGS::Game::Board $self->{size}; |
590 |
$self->{board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]); |
591 |
|
592 |
$self->{user0}->set_state ($self->{board}{captures}[0], |
593 |
$self->{board}{timer}[0], |
594 |
$running && $self->{board}{last} == WHITE); |
595 |
$self->{user1}->set_state ($self->{board}{captures}[1], |
596 |
$self->{board}{timer}[1], |
597 |
$running && $self->{board}{last} == BLACK); |
598 |
|
599 |
$self->redraw ($self->repaint_board); |
600 |
|
601 |
$self->{text}->set_text(KGS::Listener::Debug::dumpval([$self->{board}{time},$self->{board}{captures}]). $self->{board}{comment}); |
602 |
} |
603 |
|
604 |
sub event_update_tree { |
605 |
my ($self) = @_; |
606 |
|
607 |
$self->{path} = $self->get_path; |
608 |
$self->{user0}->set_rules ($self->{path}[0]); |
609 |
$self->{user1}->set_rules ($self->{path}[0]); |
610 |
|
611 |
$self->{moveadj}->value_changed if $self->{moveadj}; |
612 |
} |
613 |
|
614 |
sub event_part { |
615 |
my ($self) = @_; |
616 |
$self->SUPER::event_part; |
617 |
delete $appwin::gamelist->{game}{$self->{channel}}; |
618 |
$self->destroy; |
619 |
} |
620 |
|
621 |
sub event_move { |
622 |
my ($self, $pass) = @_; |
623 |
sound::play 1, $pass ? "pass" : "move"; |
624 |
} |
625 |
|
626 |
1; |
627 |
|