1 | #!/usr/bin/perl -I../lib/ |
1 | #!/usr/bin/perl -I../lib/ |
2 | |
|
|
3 | #use PApp::Util qw(dumpval); # debug only |
|
|
4 | |
2 | |
5 | use Gtk; |
3 | use Gtk; |
6 | use Gtk::Gdk; |
4 | use Gtk::Gdk; |
7 | use Gtk::Gdk::Pixbuf; |
5 | use Gtk::Gdk::Pixbuf; |
8 | #use Gtk::Gdk::ImlibImage; |
6 | #use Gtk::Gdk::ImlibImage; |
9 | |
7 | |
10 | use KGS::Protocol; |
8 | use KGS::Protocol; |
11 | use KGS::Listener::Debug; |
9 | use KGS::Listener::Debug; |
12 | |
10 | |
|
|
11 | use Audio::Data; |
|
|
12 | use Audio::Play; |
|
|
13 | |
13 | use IO::Socket::INET; |
14 | use IO::Socket::INET; |
14 | |
15 | |
15 | use Errno; |
16 | use Errno; |
16 | |
17 | |
17 | init Gtk; |
18 | init Gtk; |
18 | |
19 | |
19 | $HACK = 1; # do NEVER enable. ;) |
20 | $HACK = 1; # do NEVER enable. ;) |
20 | |
21 | |
21 | our $config; |
22 | our $config; |
|
|
23 | our $LIBDIR = "."; |
22 | our $IMGDIR = "images"; |
24 | our $IMGDIR = "$LIBDIR/images"; |
|
|
25 | our $SNDDIR = "$LIBDIR/sounds"; |
23 | |
26 | |
24 | sub load_img { |
27 | sub load_img { |
25 | new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]" |
28 | new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]" |
26 | # load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]" |
29 | # load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]" |
27 | or die "$IMGDIR/$_[0]: $!"; |
30 | or die "$IMGDIR/$_[0]: $!"; |
28 | } |
31 | } |
|
|
32 | |
|
|
33 | my @fontchars = ('A' .. 'Z', 0 .. 9); |
29 | |
34 | |
30 | our @black_img = load_img "b-01.png"; |
35 | our @black_img = load_img "b-01.png"; |
31 | our @white_img = map +(load_img "w-0$_.png"), 1,2,3,4,5; |
36 | our @white_img = map +(load_img "w-0$_.png"), 1,2,3,4,5; |
32 | our @triangle_img = map +(load_img "triangle-$_.png"), qw(b w); |
37 | our @triangle_img = map +(load_img "triangle-$_.png"), qw(b w); |
33 | our @square_img = map +(load_img "square-$_.png"), qw(b w); |
38 | our @square_img = map +(load_img "square-$_.png"), qw(b w); |
34 | our @circle_img = map +(load_img "circle-$_.png"), qw(b w); |
39 | our @circle_img = map +(load_img "circle-$_.png"), qw(b w); |
35 | our $board_img = load_img "woodgrain-01.jpg"; |
40 | our $board_img = load_img "woodgrain-01.jpg"; |
36 | |
41 | |
|
|
42 | our @font = ( |
|
|
43 | [map +(load_img "font/$_-black.png"), @fontchars], |
|
|
44 | [map +(load_img "font/$_-white.png"), @fontchars], |
|
|
45 | ); |
|
|
46 | our %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 | } |
|
|
74 | |
37 | { |
75 | { |
38 | use Storable (); |
76 | use Storable (); |
39 | use Scalar::Util (); |
77 | use Scalar::Util (); |
40 | |
78 | |
41 | my $staterc = "$ENV{HOME}/.kgsueme"; |
79 | my $staterc = "$ENV{HOME}/.kgsueme"; |
… | |
… | |
48 | # grr... more gtk+ brokenness |
86 | # grr... more gtk+ brokenness |
49 | my %get = ( |
87 | my %get = ( |
50 | hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, |
88 | hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, |
51 | vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, |
89 | vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, |
52 | window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, |
90 | window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, |
53 | #window_pos => sub { die PApp::Util::dumpval [ $_[0]->get_root_origin ] }, |
91 | #window_pos => sub { die KGS::Listener::Debug::dumpval [ $_[0]->get_root_origin ] }, |
54 | clist_column_widths => sub { |
92 | clist_column_widths => sub { |
55 | $_[0]{column_widths}; |
93 | $_[0]{column_widths}; |
56 | }, |
94 | }, |
57 | ); |
95 | ); |
58 | |
96 | |
… | |
… | |
139 | $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; |
140 | } |
178 | } |
141 | } |
179 | } |
142 | |
180 | |
143 | if (0) { |
181 | if (0) { |
|
|
182 | use KGS::Constants; |
|
|
183 | |
144 | my $board = new game size => 5; |
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; |
145 | $board->{window}->show_all; |
189 | $board->{window}->show_all; |
146 | } |
190 | } |
147 | |
191 | |
148 | main Gtk; |
192 | main Gtk; |
149 | |
193 | |
… | |
… | |
246 | if ($msg->{success}) { |
290 | if ($msg->{success}) { |
247 | for (keys %{$::config->{rooms}}) { |
291 | for (keys %{$::config->{rooms}}) { |
248 | $self->{roomlist}->join_room($_); |
292 | $self->{roomlist}->join_room($_); |
249 | } |
293 | } |
250 | } |
294 | } |
251 | |
|
|
252 | warn PApp::Util::dumpval($::config); |
|
|
253 | } |
295 | } |
254 | |
296 | |
255 | sub event_disconnect { } |
297 | sub event_disconnect { } |
256 | |
298 | |
257 | ############################################################################# |
299 | ############################################################################# |
… | |
… | |
560 | } |
602 | } |
561 | |
603 | |
562 | sub configure_event { |
604 | sub configure_event { |
563 | my ($widget, $self, $event) = @_; |
605 | my ($widget, $self, $event) = @_; |
564 | delete $self->{stack}; |
606 | delete $self->{stack}; |
|
|
607 | delete $self->{background}; |
565 | $self->repaint_board; |
608 | $self->repaint_board; |
566 | 1; |
609 | 1; |
567 | } |
610 | } |
568 | |
611 | |
569 | sub expose_event { |
612 | sub INTERP_NEAREST (){ 1 } |
570 | my ($widget, $self, $event) = @_; |
|
|
571 | |
|
|
572 | $self->{pixmap} or return; |
|
|
573 | |
|
|
574 | my ($ox, $oy, $s) = @{$self->{offsets}}; |
|
|
575 | |
|
|
576 | my ($x, $y, $w, $h) = |
|
|
577 | @{Gtk::Gdk::Rectangle->intersect( |
|
|
578 | $event->{area}, |
|
|
579 | [$ox, $oy, $s, $s] |
|
|
580 | )}; |
|
|
581 | |
|
|
582 | $self->{canvas}->window->draw_pixmap ( |
|
|
583 | $self->{canvas}->style->white_gc, |
|
|
584 | $self->{pixmap}, |
|
|
585 | $x - $ox, $y - $oy, $x, $y, $w, $h, |
|
|
586 | ); |
|
|
587 | 1; |
|
|
588 | } |
|
|
589 | |
|
|
590 | # create new, _transparent_ pixbuf |
|
|
591 | sub new_pixbuf { |
|
|
592 | my ($w, $h) = @_; |
|
|
593 | |
|
|
594 | $pixbuf; |
|
|
595 | } |
|
|
596 | |
|
|
597 | sub INTERP_TILES (){ 1 } |
613 | sub INTERP_TILES (){ 1 } |
598 | sub INTERP_BILINEAR (){ 2 } |
614 | sub INTERP_BILINEAR (){ 2 } |
599 | sub INTERP_HYPER (){ 3 } |
615 | sub INTERP_HYPER (){ 3 } |
600 | |
616 | |
601 | sub new_pixbuf { |
617 | sub new_pixbuf { |
602 | my ($w, $h, $clear) = @_; |
618 | my ($w, $h, $alpha, $clear) = @_; |
603 | |
619 | |
604 | my $pixbuf = new Gtk::Gdk::Pixbuf 'rgb', 1, 8, $w, $h; |
620 | my $pixbuf = new Gtk::Gdk::Pixbuf 'rgb', $alpha, 8, $w, $h; |
605 | |
621 | |
606 | if ($clear) { # damn, need to clear it ourselves |
622 | if ($clear) { # damn, need to clear it ourselves |
607 | my $row = "\x00\x00\x00\x00" x $w; |
623 | my $row = "\x00\x00\x00\x00" x $w; |
608 | $pixbuf->put_pixels ($row, $_, 0) for 0 .. $h - 1; |
624 | $pixbuf->put_pixels ($row, $_, 0) for 0 .. $h - 1; |
609 | } |
625 | } |
… | |
… | |
612 | } |
628 | } |
613 | |
629 | |
614 | sub scale_pixbuf { |
630 | sub scale_pixbuf { |
615 | my ($src, $w, $h, $mode) = @_; |
631 | my ($src, $w, $h, $mode) = @_; |
616 | |
632 | |
617 | my $dst = new_pixbuf $w, $h; |
633 | my $dst = new_pixbuf $w, $h, 1; |
618 | |
634 | |
619 | $src->scale( |
635 | $src->scale( |
620 | $dst, 0, 0, $w, $h, 0, 0, |
636 | $dst, 0, 0, $w, $h, 0, 0, |
621 | $w / $src->get_width, $h / $src->get_height, |
637 | $w / $src->get_width, $h / $src->get_height, |
622 | $mode, |
638 | $mode, |
623 | ); |
639 | ); |
624 | |
640 | |
625 | $dst; |
641 | $dst; |
626 | } |
642 | } |
627 | |
643 | |
628 | sub label_font { |
|
|
629 | my ($size) = @_; |
|
|
630 | |
|
|
631 | $size = int $size; |
|
|
632 | $size = 34 if $size > 34; |
|
|
633 | |
|
|
634 | # I am soo incapable |
|
|
635 | for (8, 10, 11, 12, 14, 17, 18, 20, 24, 25, 34) { |
|
|
636 | next unless $size <= $_; |
|
|
637 | my $font = Gtk::Gdk::Font->fontset_load ("-*-helvetica-bold-r-*--$_-*"); |
|
|
638 | return $font if $font; |
|
|
639 | } |
|
|
640 | |
|
|
641 | return Gtk::Gdk::Font->fontset_load ("-*-helvetica-bold-r-*--8-*"); |
|
|
642 | } |
|
|
643 | |
|
|
644 | sub center_text { |
|
|
645 | my ($drawable, $font, $gc, $x, $y, $t) = @_; |
|
|
646 | my $w = $font->string_width ($t); |
|
|
647 | my $h = $font->string_height($t) - $font->descent; |
|
|
648 | $drawable->draw_text ($font, $gc, $x - $w*0.5, $y + $h * 0.5, $t, length $t); |
|
|
649 | } |
|
|
650 | |
|
|
651 | # create a stack of stones |
644 | # create a stack of stones |
652 | sub create_stack { |
645 | sub create_stack { |
653 | my ($self, $gc, $mark, $size) = @_; |
646 | my ($self, $mark, $size, $rand) = @_; |
|
|
647 | |
|
|
648 | my $shadow = $size * 0.06; |
654 | |
649 | |
655 | my $c = \$self->{stack}{$mark}; |
650 | my $c = \$self->{stack}{$mark}; |
656 | unless ($$c) { |
651 | unless ($$c) { |
657 | for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) { |
652 | for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) { |
658 | my $base = |
653 | my $base = new_pixbuf $size + $shadow, $size + $shadow, 1, 1; |
659 | $mark & (MARK_B | MARK_GRAY_B | MARK_W | MARK_GRAY_W) |
|
|
660 | ? scale_pixbuf $stone, $size, $size, INTERP_HYPER |
|
|
661 | : new_pixbuf $size, $size, 1; |
|
|
662 | |
654 | |
663 | if ($mark & (MARK_GRAY_B | MARK_GRAY_W)) { |
655 | # zeroeth the shadow |
664 | # make transparent by stippling :( |
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 | ); |
665 | # #d# |
674 | } |
666 | } |
675 | } |
667 | |
676 | |
|
|
677 | # then the samll stones |
668 | for ([MARK_SMALL_B, $::black_img[int rand @::black_img]], |
678 | for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]], |
669 | [MARK_SMALL_W, $::white_img[int rand @::white_img]]) { |
679 | [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) { |
670 | my ($mask, $img) = @$_; |
680 | my ($mask, $img) = @$_; |
671 | if ($mark & $mask) { |
681 | if ($mark & $mask) { |
672 | $img->composite ( |
682 | $img->composite ( |
673 | $base, ($size / 3) x 6, |
683 | $base, ($size / 4) x2, (int ($size / 2 + 0.5)) x2, ($size / 4 - 0.5) x 2, |
674 | ($size - 1) / ($img->get_width - 1) / 3, ($size - 1) / ($img->get_height - 1) / 3, |
684 | $size / $img->get_width / 2, $size / $img->get_height / 2, |
675 | INTERP_HYPER, 255 |
685 | INTERP_HYPER, 192 |
676 | ); |
686 | ); |
677 | } |
687 | } |
678 | } |
688 | } |
679 | |
689 | |
|
|
690 | # and lastly any markers (labels NYI) |
680 | my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B)); |
691 | my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B)); |
681 | |
692 | |
682 | for ([MARK_CIRCLE, $::circle_img[$dark_bg]], |
693 | for ([MARK_CIRCLE, $::circle_img[$dark_bg]], |
683 | [MARK_TRIANGLE, $::triangle_img[$dark_bg]], |
694 | [MARK_TRIANGLE, $::triangle_img[$dark_bg]], |
684 | [MARK_SQUARE, $::square_img[$dark_bg]]) { |
695 | [MARK_SQUARE, $::square_img[$dark_bg]]) { |
685 | my ($mask, $img) = @$_; |
696 | my ($mask, $img) = @$_; |
686 | if ($mark & $mask) { |
697 | if ($mark & $mask) { |
687 | $img->composite ( |
698 | $img->composite ( |
688 | $base, 0, 0, $size, $size, 0, 0, |
699 | $base, 0, 0, $size, $size, -0.5, -0.5, |
689 | ($size - 1) / ($img->get_width - 1), ($size - 1) / ($img->get_height - 1), |
700 | $size / $img->get_width, $size / $img->get_height, |
690 | INTERP_HYPER, 255 |
701 | INTERP_HYPER, 255 |
691 | ); |
702 | ); |
692 | } |
703 | } |
693 | } |
704 | } |
694 | |
705 | |
695 | push @$$c, [$base->render_pixmap_and_mask (128)]; |
706 | push @$$c, $base; |
696 | } |
707 | } |
697 | } |
708 | } |
698 | |
709 | |
699 | @{$$c->[int rand @$$c]}; |
710 | $$c->[$rand % @$$c]; |
|
|
711 | } |
|
|
712 | |
|
|
713 | sub 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 | |
|
|
734 | my $black_pb; |
|
|
735 | |
|
|
736 | sub 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); |
700 | } |
745 | } |
701 | |
746 | |
702 | sub repaint_board { |
747 | sub repaint_board { |
703 | my ($self) = @_; |
748 | my ($self) = @_; |
704 | my $canvas = $self->{canvas}; |
749 | my $canvas = $self->{canvas}; |
705 | |
750 | |
706 | %cache = (); |
751 | return unless $self->{board}; |
707 | |
752 | |
708 | my ($w, $h) = @{$canvas->allocation}[2,3]; |
753 | my ($w, $h) = @{$canvas->allocation}[2,3]; |
709 | |
754 | |
710 | my $s = $w > $h ? $h : $w; |
755 | my $s = $w > $h ? $h : $w; |
711 | |
756 | |
712 | $self->{offsets} = [int (($w - $s) / 2), int (($h - $s) / 2), $s]; |
757 | $self->{offsets} = [int (($w - $s) / 2), int (($h - $s) / 2), $s]; |
713 | |
758 | |
714 | my $pixmap = $self->{pixmap} = new Gtk::Gdk::Pixmap $self->{canvas}->window, $s, $s; |
759 | my $size = $self->{size}; |
715 | |
760 | |
716 | { |
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 | |
717 | my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height); |
771 | my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height); |
718 | |
772 | |
719 | my $bg = $s < $bw && $s < $bh ? $::board_img : scale_pixbuf $::board_img, $s, $s, INTERP_TILES; |
773 | if ($s < $bw && $s < $bh) { |
720 | $bg->render_to_drawable( |
774 | $pixbuf = new_pixbuf $s, $s, 1, 0; |
721 | $pixmap, $self->{canvas}->style->white_gc, |
775 | $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0); |
722 | 0, 0, 0, 0, $s, $s, |
776 | } else { |
723 | 0, 0, 0 |
777 | $pixbuf = scale_pixbuf $::board_img, $s, $s, INTERP_TILES; |
724 | ); |
778 | } |
725 | } |
|
|
726 | |
779 | |
727 | my $gc = Gtk::Gdk::GC->new ($pixmap); |
780 | my $linew = int ($s / 300); |
728 | |
781 | |
729 | $gc->rgb_gc_set_foreground($line_colour); |
|
|
730 | $gc->set_line_attributes (int ($s / 300) + 1, 'solid', 'projecting', 'miter'); |
|
|
731 | |
|
|
732 | my $size = $self->{size}; |
|
|
733 | my $border = int ($s / $size * 0.75); |
|
|
734 | my $s2 = $s - $border * 2; |
|
|
735 | my $edge = int ($s2 / $size); |
|
|
736 | my $ofs = int ($s2 / $size * 0.5); |
|
|
737 | |
|
|
738 | my $font = label_font $ofs; |
|
|
739 | |
|
|
740 | my @k = map int ($s2 * $_ / $size - $ofs + $border + 0.5), 0 .. $size; |
|
|
741 | |
|
|
742 | my $a = "A"; |
782 | my $a = "A"; |
743 | for my $i (1 .. $size) { |
783 | for my $i (1 .. $size) { |
744 | $pixmap->draw_line ($gc, $k[$i], $k[1], $k[$i], $k[$size]); |
784 | pixbuf_rect $pixbuf, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew; |
745 | $pixmap->draw_line ($gc, $k[1], $k[$i], $k[$size], $k[$i]); |
785 | pixbuf_rect $pixbuf, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew; |
746 | |
786 | |
747 | center_text $pixmap, $font, $gc, $k[$i], ($ofs +$border) / 2, $a; |
787 | pixbuf_text $pixbuf, 0, $k[$i], ($ofs +$border) / 2, $ofs, $a; |
748 | center_text $pixmap, $font, $gc, $k[$i], $s2 + $border + $ofs / 2, $a; |
788 | pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border + $ofs / 2, $ofs, $a; |
749 | center_text $pixmap, $font, $gc, ($ofs + $border) / 2, $k[$i], $i; |
789 | pixbuf_text $pixbuf, 0, ($ofs + $border) / 2, $k[$i], $ofs, $size - $i + 1; |
750 | center_text $pixmap, $font, $gc, $s2 + $border + $ofs / 2, $k[$i], $i; |
790 | pixbuf_text $pixbuf, 0, $s2 + $border + $ofs / 2, $k[$i], $ofs, $size - $i + 1; |
751 | |
791 | |
752 | $a++; |
792 | $a++; |
753 | $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... |
793 | $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... |
|
|
794 | } |
|
|
795 | |
|
|
796 | $self->{background} = $pixbuf; |
754 | } |
797 | } |
|
|
798 | |
|
|
799 | my $pixbuf = $self->{pixbuf} = $self->{background}->copy; |
755 | |
800 | |
756 | # hoshi-points(!)#d# |
801 | # hoshi-points(!)#d# |
757 | # caching of empty board gfx(!)#d# |
802 | # caching of empty board gfx(!)#d# |
758 | |
803 | |
759 | if ($self->{board}) { |
804 | for my $x (1 .. $size) { |
760 | for my $x (1 .. $size) { |
805 | for my $y (1 .. $size) { |
761 | for my $y (1 .. $size) { |
|
|
762 | my $yk = $s2 * $x / $size - $ofs + $border; |
|
|
763 | my $mark = $self->{board}{board}[$x-1][$y-1]; |
806 | my $mark = $self->{board}{board}[$x-1][$y-1]; |
764 | |
807 | |
765 | if ($mark) { |
808 | if ($mark) { |
766 | my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs); |
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 | |
767 | my ($pm, $bm) = $self->create_stack($gc, $mark, $edge); |
815 | #my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 ); |
768 | |
816 | |
769 | $gc->set_clip_mask ($bm); |
817 | #$gc->set_clip_mask ($bm); |
770 | $gc->set_clip_origin ($dx, $dy); |
818 | #$gc->set_clip_origin ($dx, $dy); |
771 | $pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge); |
819 | #$pixmap->draw_pixmap ($gc, $pm, 0, 0, $dx, $dy, $edge, $edge); |
772 | } |
|
|
773 | } |
820 | } |
774 | } |
821 | } |
775 | } |
822 | } |
|
|
823 | } |
|
|
824 | |
|
|
825 | sub 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; |
776 | } |
848 | } |
777 | |
849 | |
778 | sub event_update_tree { |
850 | sub event_update_tree { |
779 | my ($self) = @_; |
851 | my ($self) = @_; |
780 | |
852 | |
… | |
… | |
785 | |
857 | |
786 | # force a redraw (not perfect(?)) |
858 | # force a redraw (not perfect(?)) |
787 | expose_event $self->{canvas}, $self, { area => $self->{canvas}->allocation }; |
859 | expose_event $self->{canvas}, $self, { area => $self->{canvas}->allocation }; |
788 | |
860 | |
789 | $self->{text}->backward_delete($self->{text}->get_length); |
861 | $self->{text}->backward_delete($self->{text}->get_length); |
790 | $self->{text}->insert(undef, undef, undef, $self->{board}{comment}.PApp::Util::dumpval([$self->{board}{time},$self->{board}{captures}])); |
862 | $self->{text}->insert(undef, undef, undef, KGS::Listener::Debug::dumpval([$self->{board}{time},$self->{board}{captures}]). $self->{board}{comment}); |
|
|
863 | } |
|
|
864 | |
|
|
865 | sub event_move { |
|
|
866 | ::play_sound "move"; |
791 | } |
867 | } |
792 | |
868 | |
793 | 1; |
869 | 1; |
794 | |
870 | |
795 | |
871 | |