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

Comparing kgsueme/bin/kgsueme (file contents):
Revision 1.7 by pcg, Thu May 29 07:30:17 2003 UTC vs.
Revision 1.20 by pcg, Fri May 30 11:25:02 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 "b01-100x102.png"; 35our @black_img = load_img "b-01.png";
33our @white_img = map +(load_img "w0$_-100x102_retouched.png"), 1,2,3; 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
44 83
45 $config = $state->{config} ||= {}; 84 $config = $state->{config} ||= {};
46 85
47 # grr... more gtk+ brokenness 86 # grr... more gtk+ brokenness
48 my %get = ( 87 my %get = (
88 hpane_position => sub { ($_[0]->children)[0]->allocation->[2] },
89 vpane_position => sub { ($_[0]->children)[0]->allocation->[3] },
49 window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, 90 window_size => sub { [ @{$_[0]->allocation}[2,3] ] },
50 #window_pos => sub { die PApp::Util::dumpval [ $_[0]->get_root_origin ] }, 91 #window_pos => sub { die KGS::Listener::Debug::dumpval [ $_[0]->get_root_origin ] },
51 clist_column_widths => sub { 92 clist_column_widths => sub {
52 $_[0]{column_widths}; 93 $_[0]{column_widths};
53 }, 94 },
54 ); 95 );
55 96
135 $main->{status}->pop($context_id{$type}) if $context_id{$type}; 176 $main->{status}->pop($context_id{$type}) if $context_id{$type};
136 $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;
137 } 178 }
138} 179}
139 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
140main Gtk; 192main Gtk;
141 193
142############################################################################# 194#############################################################################
143 195
144package kgsueme; 196package kgsueme;
238 if ($msg->{success}) { 290 if ($msg->{success}) {
239 for (keys %{$::config->{rooms}}) { 291 for (keys %{$::config->{rooms}}) {
240 $self->{roomlist}->join_room($_); 292 $self->{roomlist}->join_room($_);
241 } 293 }
242 } 294 }
243
244 warn PApp::Util::dumpval($::config);
245} 295}
246 296
247sub event_disconnect { } 297sub event_disconnect { }
248 298
249############################################################################# 299#############################################################################
296 346
297 $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!)
298 $self->{window}->show_all; 348 $self->{window}->show_all;
299} 349}
300 350
301sub event_update { 351sub event_update_rooms {
302 my ($self) = @_; 352 my ($self) = @_;
303 353
304 $self->{event_update} ||= Gtk->timeout_add(200, sub { 354 $self->{event_update} ||= Gtk->timeout_add(200, sub {
305 my $l = $self->{roomlist}; 355 my $l = $self->{roomlist};
306 356
383 ::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];
384 434
385 $self; 435 $self;
386} 436}
387 437
388sub event_update { 438sub event_update_users {
389 my ($self) = @_; 439 my ($self) = @_;
390 440
391 $self->{event_update} ||= Gtk->timeout_add(200, sub { 441 $self->{event_update} ||= Gtk->timeout_add(200, sub {
392 my $l = $self->{userlist}; 442 my $l = $self->{userlist};
393 443
444 my ($self) = @_; 494 my ($self) = @_;
445 $self->SUPER::part; 495 $self->SUPER::part;
446 496
447 delete $::config->{rooms}{$self->{channel}}; 497 delete $::config->{rooms}{$self->{channel}};
448 $self->{window}->hide_all; 498 $self->{window}->hide_all;
449 $self->event_update; 499 $self->event_update_users;
450 $self->event_update_games; 500 $self->event_update_games;
451} 501}
452 502
453sub event_join { 503sub event_join {
454 my ($self) = @_; 504 my ($self) = @_;
473############################################################################# 523#############################################################################
474 524
475package game; 525package game;
476 526
477use KGS::Constants; 527use KGS::Constants;
528use KGS::Game::Board;
478 529
479use base KGS::Listener::Game; 530use base KGS::Listener::Game;
480use base KGS::Game; 531use base KGS::Game;
481 532
482sub new { 533sub new {
484 $self = $self->SUPER::new(@_); 535 $self = $self->SUPER::new(@_);
485 536
486 $self->listen($self->{conn}); 537 $self->listen($self->{conn});
487 538
488 $self->{window} = new Gtk::Window 'toplevel'; 539 $self->{window} = new Gtk::Window 'toplevel';
489 $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#
490 ::state $self->{window}, "game::window", undef, window_size => [600, 500]; 541 ::state $self->{window}, "game::window", undef, window_size => [600, 500];
491 542
492 $self->{window}->signal_connect(delete_event => sub { $self->part; 1 }); 543 $self->{window}->signal_connect(delete_event => sub { $self->part; 1 });
493 544
494 $self->{window}->add(my $hpane = new Gtk::HPaned); 545 $self->{window}->add(my $hpane = new Gtk::HPaned);
495 ::state $hpane, "game::hpane", undef, hpane_position => 500; 546 ::state $hpane, "game::hpane", undef, hpane_position => 500;
496 547
497 $::config{aa}++; 548 Gtk::Widget->push_visual (Gtk::Gdk::Rgb->get_visual);
498 $self->{canvas} = $::config{aa} ? new_aa Gnome::Canvas : new Gnome::Canvas; 549 Gtk::Widget->push_colormap (Gtk::Gdk::Rgb->get_cmap);
499 $hpane->add($self->{canvas}); 550 $hpane->pack1(($self->{canvas} = new Gtk::DrawingArea), 1, 1);
551 Gtk::Widget->pop_colormap;
552 Gtk::Widget->pop_visual;
500 553
501 $self->{canvas}->signal_connect(size_allocate => sub { 554 $self->{canvas}->signal_connect(configure_event => \&configure_event, $self);
502 warn "@_ @{$_[1]}"; 555 $self->{canvas}->signal_connect(expose_event => \&expose_event, $self);
503 #$self->{canvas}->set_pixels_per_unit(
504 });
505 556
506 my $line_colour = $::config{line_colour} || "darkbrown";
507 my $border = 0.1;
508
509 $self->{canvas}->set_pixels_per_unit(300);
510 $self->{canvas}->set_scroll_region(-$border,-$border,1+$border,1+$border);
511
512 {
513 my $croot = $self->{canvas}->root;
514 my $cgroup = $croot; #->new($croot, "Gnome::CanvasGroup");
515
516 if ($::board_img) {
517 $cgroup->new($cgroup, "Gnome::CanvasImage",
518 x => -$border, y => -$border,
519 width => 1+$border*2, height => 1+$border*2,
520 image => $::board_img,
521 anchor => "nw"
522 );
523 } else {
524 die;
525 $cgroup->new($cgroup, "Gnome::CanvasRect",
526 x1 => -$border, x2 => 1+$border,
527 y1 => -$border, y2 => 1+$border,
528 outline_color => "black",
529 fill_color => "brown",
530 width_pixels => 2,
531 );
532 }
533
534 my $x1 = $pad * 2; # == my $y1 = 30;
535 my $x2 = $w - ($pad * 2); # == my $y2 = 270;
536 my $w = $x2 - $x1;
537 my $s = $self->{size} - 1;
538 my $ofs = 0.5 / $self->{size};
539
540 my $a = "A";
541 for my $i (1 .. $self->{size}) { # one more iteration for the last lines
542 my $k = $i / $self->{size} - $ofs;
543
544 $cgroup->new($cgroup, "Gnome::CanvasLine",
545 points => [ $k,$ofs, $k,1-$ofs ],
546 fill_color => $line_colour,
547 width_pixels => 1);
548
549 $cgroup->new($cgroup, "Gnome::CanvasLine",
550 points => [ $ofs,$k, 1-$ofs,$k ],
551 fill_color => $line_colour,
552 width_pixels => 1);
553
554 for ( [$k,-$border*0.5,$a], [$k,1+$border*0.5,$a], [-$border*0.5,$k,$i], [1+$border*0.5,$k,$i] ) {
555 my ($x, $y, $text) = @$_;
556
557 my $text = $cgroup->new($cgroup, "Gnome::CanvasText",
558 x => 0, y => 0, text => $text,
559 justification => "center",
560 anchor => "center",
561 font => "-*-helvetica-medium-r-*--34-*",
562 fill_color => $line_colour);
563
564 $text->affine_relative($border*0.015,0, 0,$border*0.015, $x,$y);
565 }
566
567 $a++;
568 }
569
570 my $stones = [[]];
571
572 for my $x (1 .. $self->{size}) {
573 my $xk = $x / $self->{size} - $ofs;
574 for my $y (1 .. $self->{size}) {
575 my $yk = $y / $self->{size} - $ofs;
576
577 my $col = $stones->[$x-1][$y-1] = [];
578
579 if (1) {
580 $col->[0] =
581 $cgroup->new($cgroup, "Gnome::CanvasImage",
582 x => $xk, y => $yk,
583 width => $ofs*2, height => $ofs*2,
584 image => $::black_img[int rand @::black_img],
585 anchor => "center");
586 $col->[1] =
587 $cgroup->new($cgroup, "Gnome::CanvasImage",
588 x => $xk, y => $yk,
589 width => $ofs*2, height => $ofs*2,
590 image => $::white_img[int rand @::white_img],
591 anchor => "center");
592 } else {
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) | 1;
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 / 300);
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