ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/bin/kgsueme
(Generate patch)

Comparing kgsueme/bin/kgsueme (file contents):
Revision 1.8 by pcg, Thu May 29 08:02:31 2003 UTC vs.
Revision 1.22 by pcg, Fri May 30 11:39:56 2003 UTC

1#!/usr/bin/perl -I../lib/ 1#!/usr/bin/perl -I../lib/
2
3#use PApp::Util qw(dumpval); # debug only
4 2
5use Gtk; 3use Gtk;
6use Gtk::Gdk; 4use Gtk::Gdk;
7#use Gtk::Gdk::Pixbuf; 5use Gtk::Gdk::Pixbuf;
8use Gtk::Gdk::ImlibImage; 6#use Gtk::Gdk::ImlibImage;
9
10use Gnome;
11 7
12use KGS::Protocol; 8use KGS::Protocol;
13use KGS::Listener::Debug; 9use KGS::Listener::Debug;
14 10
11use Audio::Data;
12use Audio::Play;
13
15use IO::Socket::INET; 14use IO::Socket::INET;
16 15
17use Errno; 16use Errno;
18 17
19init Gnome "kgsueme"; 18init Gtk;
20 19
21$HACK = 1; # do NEVER enable. ;) 20$HACK = 1; # do NEVER enable. ;)
22 21
23our $config; 22our $config;
23our $LIBDIR = ".";
24our $IMGDIR = "images"; 24our $IMGDIR = "$LIBDIR/images";
25our $SNDDIR = "$LIBDIR/sounds";
25 26
26sub load_img { 27sub load_img {
27# new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]" 28 new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]"
28 load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]" 29# load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]"
29 or die "$IMGDIR/$_[0]: $!"; 30 or die "$IMGDIR/$_[0]: $!";
30} 31}
31 32
33my @fontchars = ('A' .. 'Z', 0 .. 9);
34
32our @black_img = load_img "b-01.png"; 35our @black_img = load_img "b-01.png";
33our @white_img = map +(load_img "w-0$_.png"), 1,2,3,4,5; 36our @white_img = map +(load_img "w-0$_.png"), 1,2,3,4,5;
37our @triangle_img = map +(load_img "triangle-$_.png"), qw(b w);
38our @square_img = map +(load_img "square-$_.png"), qw(b w);
39our @circle_img = map +(load_img "circle-$_.png"), qw(b w);
34our $board_img = load_img "woodgrain-01.jpg"; 40our $board_img = load_img "woodgrain-01.jpg";
41
42our @font = (
43 [map +(load_img "font/$_-black.png"), @fontchars],
44 [map +(load_img "font/$_-white.png"), @fontchars],
45 );
46our %fontmap;
47@fontmap{@fontchars} = (0..25 + 10);
48@fontmap{'a' .. 'z'} = (0..25);
49
50{
51 #my $audioserver = new Audio::Play(0);
52 my %sound;
53 $SIG{CHLD} = 'IGNORE';
54
55 for (qw(alarm warning move)) {
56 local $/;
57 open my $snd, "<", "$SNDDIR/$_"
58 or die "$SNDDIR: $!";
59 binmode $snd;
60
61 $sound{$_} = new Audio::Data;
62 $sound{$_}->Load($snd);
63 }
64
65 sub play_sound {
66 if (fork == 0) {
67 if (my $audioserver = new Audio::Play(1)) {
68 $audioserver->play ($sound{$_[0]});
69 }
70 Gtk->_exit(0);
71 }
72 }
73}
35 74
36{ 75{
37 use Storable (); 76 use Storable ();
38 use Scalar::Util (); 77 use Scalar::Util ();
39 78
47 # grr... more gtk+ brokenness 86 # grr... more gtk+ brokenness
48 my %get = ( 87 my %get = (
49 hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, 88 hpane_position => sub { ($_[0]->children)[0]->allocation->[2] },
50 vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, 89 vpane_position => sub { ($_[0]->children)[0]->allocation->[3] },
51 window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, 90 window_size => sub { [ @{$_[0]->allocation}[2,3] ] },
52 #window_pos => sub { die PApp::Util::dumpval [ $_[0]->get_root_origin ] }, 91 #window_pos => sub { die KGS::Listener::Debug::dumpval [ $_[0]->get_root_origin ] },
53 clist_column_widths => sub { 92 clist_column_widths => sub {
54 $_[0]{column_widths}; 93 $_[0]{column_widths};
55 }, 94 },
56 ); 95 );
57 96
137 $main->{status}->pop($context_id{$type}) if $context_id{$type}; 176 $main->{status}->pop($context_id{$type}) if $context_id{$type};
138 $main->{status}->push($context_id{$type} ||= $main->{status}->get_context_id($type), $text) if $text; 177 $main->{status}->push($context_id{$type} ||= $main->{status}->get_context_id($type), $text) if $text;
139 } 178 }
140} 179}
141 180
181if (0) {
182 use KGS::Constants;
183
184 my $board = new game size => 5;
185 $board->{board} = new KGS::Game::Board;
186 $board->{board}{board}[0][0] = MARK_B;
187 $board->{board}{board}[1][1] = MARK_GRAY_B | MARK_SMALL_W;
188 $board->{board}{board}[2][2] = MARK_W | MARK_TRIANGLE;
189 $board->{window}->show_all;
190}
191
142main Gtk; 192main Gtk;
143 193
144############################################################################# 194#############################################################################
145 195
146package kgsueme; 196package kgsueme;
240 if ($msg->{success}) { 290 if ($msg->{success}) {
241 for (keys %{$::config->{rooms}}) { 291 for (keys %{$::config->{rooms}}) {
242 $self->{roomlist}->join_room($_); 292 $self->{roomlist}->join_room($_);
243 } 293 }
244 } 294 }
245
246 warn PApp::Util::dumpval($::config);
247} 295}
248 296
249sub event_disconnect { } 297sub event_disconnect { }
250 298
251############################################################################# 299#############################################################################
298 346
299 $self->msg(list_rooms => group => $_) for 0..5; # fetch all room names (should not!) 347 $self->msg(list_rooms => group => $_) for 0..5; # fetch all room names (should not!)
300 $self->{window}->show_all; 348 $self->{window}->show_all;
301} 349}
302 350
303sub event_update { 351sub event_update_rooms {
304 my ($self) = @_; 352 my ($self) = @_;
305 353
306 $self->{event_update} ||= Gtk->timeout_add(200, sub { 354 $self->{event_update} ||= Gtk->timeout_add(200, sub {
307 my $l = $self->{roomlist}; 355 my $l = $self->{roomlist};
308 356
385 ::state $self->{userlist}, "room::userlist", $self->{name}, clist_column_widths => [120, 30]; 433 ::state $self->{userlist}, "room::userlist", $self->{name}, clist_column_widths => [120, 30];
386 434
387 $self; 435 $self;
388} 436}
389 437
390sub event_update { 438sub event_update_users {
391 my ($self) = @_; 439 my ($self) = @_;
392 440
393 $self->{event_update} ||= Gtk->timeout_add(200, sub { 441 $self->{event_update} ||= Gtk->timeout_add(200, sub {
394 my $l = $self->{userlist}; 442 my $l = $self->{userlist};
395 443
446 my ($self) = @_; 494 my ($self) = @_;
447 $self->SUPER::part; 495 $self->SUPER::part;
448 496
449 delete $::config->{rooms}{$self->{channel}}; 497 delete $::config->{rooms}{$self->{channel}};
450 $self->{window}->hide_all; 498 $self->{window}->hide_all;
451 $self->event_update; 499 $self->event_update_users;
452 $self->event_update_games; 500 $self->event_update_games;
453} 501}
454 502
455sub event_join { 503sub event_join {
456 my ($self) = @_; 504 my ($self) = @_;
475############################################################################# 523#############################################################################
476 524
477package game; 525package game;
478 526
479use KGS::Constants; 527use KGS::Constants;
528use KGS::Game::Board;
480 529
481use base KGS::Listener::Game; 530use base KGS::Listener::Game;
482use base KGS::Game; 531use base KGS::Game;
483 532
484sub new { 533sub new {
486 $self = $self->SUPER::new(@_); 535 $self = $self->SUPER::new(@_);
487 536
488 $self->listen($self->{conn}); 537 $self->listen($self->{conn});
489 538
490 $self->{window} = new Gtk::Window 'toplevel'; 539 $self->{window} = new Gtk::Window 'toplevel';
491 $self->{window}->set_title("KGS Game ".$self->user0." ".$self->user1); 540 $self->{window}->set_title("KGS Game ".$self->user0." ".$self->user1) if $self->{channel};#d#
492 ::state $self->{window}, "game::window", undef, window_size => [600, 500]; 541 ::state $self->{window}, "game::window", undef, window_size => [600, 500];
493 542
494 $self->{window}->signal_connect(delete_event => sub { $self->part; 1 }); 543 $self->{window}->signal_connect(delete_event => sub { $self->part; 1 });
495 544
496 $self->{window}->add(my $hpane = new Gtk::HPaned); 545 $self->{window}->add(my $hpane = new Gtk::HPaned);
497 ::state $hpane, "game::hpane", undef, hpane_position => 500; 546 ::state $hpane, "game::hpane", undef, hpane_position => 500;
498 547
499 $::config{aa} = 1; 548 Gtk::Widget->push_visual (Gtk::Gdk::Rgb->get_visual);
500 $self->{canvas} = $::config{aa} ? new_aa Gnome::Canvas : new Gnome::Canvas; 549 Gtk::Widget->push_colormap (Gtk::Gdk::Rgb->get_cmap);
501 $hpane->add($self->{canvas}); 550 $hpane->pack1(($self->{canvas} = new Gtk::DrawingArea), 1, 1);
551 Gtk::Widget->pop_colormap;
552 Gtk::Widget->pop_visual;
502 553
503 { 554 $self->{canvas}->signal_connect(configure_event => \&configure_event, $self);
504 my $line_colour = $::config{line_colour} || "darkbrown"; 555 $self->{canvas}->signal_connect(expose_event => \&expose_event, $self);
505 my $border = 0.1;
506 my $ofs = 0.5 / $self->{size};
507
508 $self->{canvas}->set_pixels_per_unit(1000);
509 $self->{canvas}->set_scroll_region(-$border,-$border,1+$border,1+$border);
510 556
511 $self->{canvas}->signal_connect(size_allocate => sub {
512 my ($w, $h) = @{$_[1]}[2,3];
513
514 $self->{canvas}->set_pixels_per_unit(($w > $h ? $h : $w)/(1+$border*2));
515
516 1;
517 });
518
519 my $croot = $self->{canvas}->root;
520 my $cgroup = $croot; #->new($croot, "Gnome::CanvasGroup");
521
522 if ($::board_img) {
523 $cgroup->new($cgroup, "Gnome::CanvasImage",
524 x => -$border, y => -$border,
525 width => 1+$border*2, height => 1+$border*2,
526 image => $::board_img,
527 anchor => "nw"
528 );
529 } else {
530 $cgroup->new($cgroup, "Gnome::CanvasRect",
531 x1 => -$border, x2 => 1+$border,
532 y1 => -$border, y2 => 1+$border,
533 outline_color => "black",
534 fill_color => "brown",
535 width_pixels => 2,
536 );
537 }
538
539 my $a = "A";
540 for my $i (1 .. $self->{size}) { # one more iteration for the last lines
541 my $k = $i / $self->{size} - $ofs;
542
543 $cgroup->new($cgroup, "Gnome::CanvasLine",
544 points => [ $k,$ofs, $k,1-$ofs ],
545 fill_color => $line_colour,
546 width_pixels => 1);
547
548 $cgroup->new($cgroup, "Gnome::CanvasLine",
549 points => [ $ofs,$k, 1-$ofs,$k ],
550 fill_color => $line_colour,
551 width_pixels => 1);
552
553 for ( [$k,-$border*0.5,$a], [$k,1+$border*0.5,$a], [-$border*0.5,$k,$i], [1+$border*0.5,$k,$i] ) {
554 my ($x, $y, $text) = @$_;
555
556 my $text = $cgroup->new($cgroup, "Gnome::CanvasText",
557 x => 0, y => 0, text => $text,
558 justification => "center",
559 anchor => "center",
560 font => $::config{aa} ? "-*-helvetica-medium-r-*--34-*" : "-*-helvetica-bold-r-*--17-*",
561 fill_color => $line_colour);
562
563 $text->affine_relative($border*0.015,0, 0,$border*0.015, $x,$y);
564 }
565
566 $a++;
567 }
568
569 my $stones = [[]];
570
571 for my $x (1 .. $self->{size}) {
572 my $xk = $x / $self->{size} - $ofs;
573 for my $y (1 .. $self->{size}) {
574 my $yk = $y / $self->{size} - $ofs;
575
576 my $col = $stones->[$x-1][$y-1] = [];
577
578 if (1) {
579 $col->[0] =
580 $cgroup->new($cgroup, "Gnome::CanvasImage",
581 x => $xk, y => $yk,
582 width => $ofs*2, height => $ofs*2,
583 image => $::black_img[int rand @::black_img],
584 anchor => "center");
585 $col->[1] =
586 $cgroup->new($cgroup, "Gnome::CanvasImage",
587 x => $xk, y => $yk,
588 width => $ofs*2, height => $ofs*2,
589 image => $::white_img[int rand @::white_img],
590 anchor => "center");
591 } else {
592 die "need pixmaps\n";
593 # too large, scale has NO effect
594 $col->[0] =
595 $cgroup->new($cgroup, "Gnome::CanvasEllipse",
596 x1 => $xk, x2 => $xk + 0.001,
597 y1 => $yk, y2 => $yk + 0.001,
598 outline_color => "black", width_pixels => 2,
599 fill_color => "black");
600 $col->[1] =
601 $cgroup->new($cgroup, "Gnome::CanvasEllipse",
602 x1 => $xk, x2 => $xk + 0.001,
603 y1 => $yk, y2 => $yk + 0.001,
604 outline_color => "black", width_pixels => 2,
605 fill_color => "white");
606 }
607 }
608 }
609
610 $self->{board_gfx}{stones} = $stones;
611 }
612
613 $hpane->add(my $vpane = new Gtk::VPaned); 557 $hpane->pack2((my $vpane = new Gtk::VPaned), 0, 0);
614 ::state $vpane, "game", $self->{name}, vpane_position => 80; 558 ::state $vpane, "game", $self->{name}, vpane_position => 80;
615 559
616 $vpane->add(my $sw = new Gtk::ScrolledWindow); 560 $vpane->add(my $sw = new Gtk::ScrolledWindow);
617 $sw->set_policy("automatic", "always"); 561 $sw->set_policy("automatic", "always");
618 562
635 }); 579 });
636 580
637 $self; 581 $self;
638} 582}
639 583
640sub event_update { 584sub event_update_users {
641 my ($self) = @_; 585 my ($self) = @_;
642 586
643 $self->{event_update} ||= Gtk->timeout_add(200, sub { 587 room::event_update_users $self;
644 my $l = $self->{userlist};
645
646 $l->freeze;
647 my $pos = $l->get_vadjustment->get_value;
648 $l->clear;
649
650 my $row = 0;
651 for (values %{$self->{users}}) {
652 $l->append($_->{name});
653 $l->set_row_data($row++, $_);
654 }
655 $l->sort;
656 $l->get_vadjustment->set_value($pos);
657 $l->thaw;
658
659 delete $self->{event_update};
660 0;
661 });
662} 588}
663 589
664sub join { 590sub join {
665 my ($self) = @_; 591 my ($self) = @_;
666 $self->SUPER::join; 592 $self->SUPER::join;
670 596
671sub part { 597sub part {
672 my ($self) = @_; 598 my ($self) = @_;
673 $self->SUPER::part; 599 $self->SUPER::part;
674 600
675 $self->{window}->hide_all; 601 $self->{window}->hide;
676 $self->event_update; 602}
603
604sub configure_event {
605 my ($widget, $self, $event) = @_;
606 delete $self->{stack};
607 delete $self->{background};
608 $self->repaint_board;
609 1;
610}
611
612sub INTERP_NEAREST (){ 1 }
613sub INTERP_TILES (){ 1 }
614sub INTERP_BILINEAR (){ 2 }
615sub INTERP_HYPER (){ 3 }
616
617sub new_pixbuf {
618 my ($w, $h, $alpha, $clear) = @_;
619
620 my $pixbuf = new Gtk::Gdk::Pixbuf 'rgb', $alpha, 8, $w, $h;
621
622 if ($clear) { # damn, need to clear it ourselves
623 my $row = "\x00\x00\x00\x00" x $w;
624 $pixbuf->put_pixels ($row, $_, 0) for 0 .. $h - 1;
625 }
626
627 $pixbuf;
628}
629
630sub scale_pixbuf {
631 my ($src, $w, $h, $mode) = @_;
632
633 my $dst = new_pixbuf $w, $h, 1;
634
635 $src->scale(
636 $dst, 0, 0, $w, $h, 0, 0,
637 $w / $src->get_width, $h / $src->get_height,
638 $mode,
639 );
640
641 $dst;
642}
643
644# create a stack of stones
645sub create_stack {
646 my ($self, $mark, $size, $rand) = @_;
647
648 my $shadow = $size * 0.06;
649
650 my $c = \$self->{stack}{$mark};
651 unless ($$c) {
652 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) {
653 my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 1;
654
655 # zeroeth the shadow
656 $::black_img[0]->composite (
657 $base, $shadow, $shadow, $size, $size, $shadow-0.5, $shadow-0.5,
658 $size / $stone->get_width, $size / $stone->get_height,
659 INTERP_TILES, 128
660 );
661
662 # first the big stones
663 for ([MARK_B, 255],
664 [MARK_W, 255],
665 [MARK_GRAY_B, 128],
666 [MARK_GRAY_W, 128]) {
667 my ($mask, $alpha) = @$_;
668 if ($mark & $mask) {
669 $stone->composite (
670 $base, 0, 0, $size, $size, -0.5, -0.5,
671 $size / $stone->get_width, $size / $stone->get_height,
672 INTERP_HYPER, $alpha
673 );
674 }
675 }
676
677 # then the samll stones
678 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]],
679 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) {
680 my ($mask, $img) = @$_;
681 if ($mark & $mask) {
682 $img->composite (
683 $base, ($size / 4) x2, (int ($size / 2 + 0.5)) x2, ($size / 4 - 0.5) x 2,
684 $size / $img->get_width / 2, $size / $img->get_height / 2,
685 INTERP_HYPER, 192
686 );
687 }
688 }
689
690 # and lastly any markers (labels NYI)
691 my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B));
692
693 for ([MARK_CIRCLE, $::circle_img[$dark_bg]],
694 [MARK_TRIANGLE, $::triangle_img[$dark_bg]],
695 [MARK_SQUARE, $::square_img[$dark_bg]]) {
696 my ($mask, $img) = @$_;
697 if ($mark & $mask) {
698 $img->composite (
699 $base, 0, 0, $size, $size, -0.5, -0.5,
700 $size / $img->get_width, $size / $img->get_height,
701 INTERP_HYPER, 255
702 );
703 }
704 }
705
706 push @$$c, $base;
707 }
708 }
709
710 $$c->[$rand % @$$c];
711}
712
713sub pixbuf_text {
714 my ($pixbuf, $colour, $x, $y, $height, $text) = @_;
715
716 my $c = $::font[$colour][$::fontmap{substr $text, 0, 1}];
717
718 if ($c) {
719 my ($w, $h) = ($c->get_width, $c->get_height);
720 my $s = ($height-1) / ($h-1);
721
722 $x -= $w * $s * 0.5;
723 $y -= $height * 0.5;
724
725 $c->composite ($pixbuf,
726 $x, $y, $w*$s+0.5, $height+0.5, $x-0.5, $y-0.5, $s, $s,
727 INTERP_BILINEAR, 192);
728
729 } else {
730 warn "unable to render character '$text'";
731 }
732}
733
734my $black_pb;
735
736sub pixbuf_rect {
737 my ($pb, $x1, $y1, $x2, $y2) = @_;
738 # we fake lines by... an unspeakable method :/
739 unless ($black_pb) {
740 $black_pb = new_pixbuf 1, 1, 0, 0;
741 $black_pb->put_pixels ("\x44\x11\x11", 0, 0);
742 }
743
744 $black_pb->composite ($pb, $x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1, $x1, $y1, 1, 1, INTERP_NEAREST, 192);
745}
746
747sub repaint_board {
748 my ($self) = @_;
749 my $canvas = $self->{canvas};
750
751 return unless $self->{board};
752
753 my ($w, $h) = @{$canvas->allocation}[2,3];
754
755 my $s = $w > $h ? $h : $w;
756
757 $self->{offsets} = [int (($w - $s) / 2), int (($h - $s) / 2), $s];
758
759 my $size = $self->{size};
760
761 my $border = int ($s / $size);
762 my $s2 = $s - $border * 2;
763 my $edge = int ($s2 / $size * 0.97);
764 my $ofs = int ($edge / 2);
765
766 my @k = map int ($s2 * $_ / $size - $ofs + $border + 0.5), 0 .. $size;
767
768 unless ($self->{background}) {
769 my $pixbuf;
770
771 my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height);
772
773 if ($s < $bw && $s < $bh) {
774 $pixbuf = new_pixbuf $s, $s, 1, 0;
775 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0);
776 } else {
777 $pixbuf = scale_pixbuf $::board_img, $s, $s, INTERP_TILES;
778 }
779
780 my $linew = int ($s / 500);
781
782 my $a = "A";
783 for my $i (1 .. $size) {
784 pixbuf_rect $pixbuf, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew;
785 pixbuf_rect $pixbuf, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew;
786
787 pixbuf_text $pixbuf, 0, $k[$i], ($ofs +$border) / 2, $ofs, $a;
788 pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border + $ofs / 2, $ofs, $a;
789 pixbuf_text $pixbuf, 0, ($ofs + $border) / 2, $k[$i], $ofs, $size - $i + 1;
790 pixbuf_text $pixbuf, 0, $s2 + $border + $ofs / 2, $k[$i], $ofs, $size - $i + 1;
791
792 $a++;
793 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
794 }
795
796 $self->{background} = $pixbuf;
797 }
798
799 my $pixbuf = $self->{pixbuf} = $self->{background}->copy;
800
801 # hoshi-points(!)#d#
802 # caching of empty board gfx(!)#d#
803
804 for my $x (1 .. $size) {
805 for my $y (1 .. $size) {
806 my $mark = $self->{board}{board}[$x-1][$y-1];
807
808 if ($mark) {
809 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs);
810 my $pb = $self->create_stack($mark, $edge, $x * 17 + $y * 11 );
811
812 $pb->composite ($pixbuf, $dx, $dy, $pb->get_width, $pb->get_height,
813 $dx, $dy, 1, 1, INTERP_NEAREST, 255);
814
815 #my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 );
816
817 #$gc->set_clip_mask ($bm);
818 #$gc->set_clip_origin ($dx, $dy);
819 #$pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge);
820 }
821 }
822 }
823}
824
825sub expose_event {
826 my ($widget, $self, $event) = @_;
827
828 $self->{pixbuf} or return;
829
830 my ($ox, $oy, $s) = @{$self->{offsets}};
831
832 my ($x, $y, $w, $h) =
833 @{Gtk::Gdk::Rectangle->intersect(
834 $event->{area},
835 [$ox, $oy, $s, $s]
836 )};
837
838 if (defined $x) {
839 $self->{pixbuf}->render_to_drawable ($self->{canvas}->window, $self->{canvas}->style->white_gc,
840 $x - $ox, $y - $oy, $x, $y, $w, $h);
841 #$self->{canvas}->window->draw_pixmap (
842 # $self->{canvas}->style->white_gc,
843 # $self->{pixmap},
844 # $x - $ox, $y - $oy, $x, $y, $w, $h,
845 #);
846 }
847 1;
677} 848}
678 849
679sub event_update_tree { 850sub event_update_tree {
680 my ($self) = @_; 851 my ($self) = @_;
681 852
682 my $board = new KGS::Game::Board $self->{size}; 853 $self->{board} = new KGS::Game::Board $self->{size};
683 $board->interpret_path ($self->get_path); 854 $self->{board}->interpret_path ($self->get_path);
684 855
685# if (not defined $self->{board_pm}) { 856 $self->repaint_board;
686# $self->{board_pm} = new Gtk::Gdk::Pixmap ($self->{board}->window, 100, 100, -1);
687# $self->{board_pm}->draw_rectangle($self->{board}->style->white_gc, 1, 0, 0, 100, 100);
688# }
689# my $red = $self->{board}->window->get_colormap->color_alloc( { red => 65000, green => 0, blue => 0 } );
690# my $red_gc = new Gtk::Gdk::GC ( $self->{board}->window );
691# $red_gc->set_foreground( $red );
692#
693# my $px = $self->{board_pm};
694 857
695 for my $x (0 .. $self->{size} - 1) { 858 # force a redraw (not perfect(?))
696 for my $y (0 .. $self->{size} - 1) { 859 expose_event $self->{canvas}, $self, { area => $self->{canvas}->allocation };
697 my $v = $board->{board}[$x][$y];
698 860
699 $v & MARK_B 861 $self->{text}->backward_delete($self->{text}->get_length);
700 ? $self->{board_gfx}->{stones}->[$x][$y][0]->show 862 $self->{text}->insert(undef, undef, undef, KGS::Listener::Debug::dumpval([$self->{board}{time},$self->{board}{captures}]). $self->{board}{comment});
701 : $self->{board_gfx}->{stones}->[$x][$y][0]->hide; 863}
702 $v & MARK_W 864
703 ? $self->{board_gfx}->{stones}->[$x][$y][1]->show 865sub event_move {
704 : $self->{board_gfx}->{stones}->[$x][$y][1]->hide; 866 ::play_sound "move";
705 }
706 }
707} 867}
708 868
7091; 8691;
710 870
711 871

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines