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

Comparing kgsueme/bin/kgsueme (file contents):
Revision 1.17 by pcg, Fri May 30 09:15:37 2003 UTC vs.
Revision 1.19 by pcg, Fri May 30 10:54:26 2003 UTC

62 $sound{$_}->Load($snd); 62 $sound{$_}->Load($snd);
63 } 63 }
64 64
65 sub play_sound { 65 sub play_sound {
66 if (fork == 0) { 66 if (fork == 0) {
67 my $audioserver = new Audio::Play(1); 67 if (my $audioserver = new Audio::Play(1)) {
68 $audioserver->play ($sound{$_[0]}); 68 $audioserver->play ($sound{$_[0]});
69 }
69 Gtk->_exit(0); 70 Gtk->_exit(0);
70 } 71 }
71 } 72 }
72} 73}
73 74
601} 602}
602 603
603sub configure_event { 604sub configure_event {
604 my ($widget, $self, $event) = @_; 605 my ($widget, $self, $event) = @_;
605 delete $self->{stack}; 606 delete $self->{stack};
607 delete $self->{background};
606 $self->repaint_board; 608 $self->repaint_board;
607 1; 609 1;
608} 610}
609 611
610sub INTERP_NEAREST (){ 1 } 612sub INTERP_NEAREST (){ 1 }
644 my ($self, $mark, $size, $rand) = @_; 646 my ($self, $mark, $size, $rand) = @_;
645 647
646 my $c = \$self->{stack}{$mark}; 648 my $c = \$self->{stack}{$mark};
647 unless ($$c) { 649 unless ($$c) {
648 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) { 650 for my $stone ($mark & (MARK_W | MARK_GRAY_W) ? @::white_img : @::black_img) {
649 my $base =
650 $mark & (MARK_B | MARK_GRAY_B | MARK_W | MARK_GRAY_W)
651 ? scale_pixbuf $stone, $size, $size, INTERP_HYPER
652 : new_pixbuf $size, $size, 1, 1; 651 my $base = new_pixbuf $size, $size, 1, 1;
653 652
654 if ($mark & (MARK_GRAY_B | MARK_GRAY_W)) { 653 # first the big stones
655 # make transparent by stippling :( 654 for ([MARK_B, 255],
656 # fix this to use compositing if/when we have full compositing support 655 [MARK_W, 255],
657 # in kgsueme 656 [MARK_GRAY_B, 128],
658 my @row = ( 657 [MARK_GRAY_W, 128]) {
659 "\xff\xff\xff\xff\x00\x00\x00\x00" x ($size / 2 + 1), 658 my ($mask, $alpha) = @$_;
660 "\x00\x00\x00\x00\xff\xff\xff\xff" x ($size / 2 + 1), 659 if ($mark & $mask) {
660 $stone->composite (
661 $base, 0, 0, $size, $size, -0.5, -0.5,
662 $size / $stone->get_width, $size / $stone->get_height,
663 INTERP_HYPER, $alpha
661 ); 664 );
662 $base->put_pixels ($base->get_pixels ($_) & $row[$_ & 1], $_, 0) 665 }
663 for 0 .. $size - 1;
664 } 666 }
665 667
668 # then the samll stones
666 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]], 669 for ([MARK_SMALL_B, $::black_img[$rand % @::black_img]],
667 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) { 670 [MARK_SMALL_W, $::white_img[$rand % @::white_img]]) {
668 my ($mask, $img) = @$_; 671 my ($mask, $img) = @$_;
669 if ($mark & $mask) { 672 if ($mark & $mask) {
670 $img->composite ( 673 $img->composite (
671 $base, ($size / 4) x2, (int ($size / 2 + 0.5)) x2, ($size / 4) x 2, 674 $base, ($size / 4) x2, (int ($size / 2 + 0.5)) x2, ($size / 4 - 0.5) x 2,
672 $size / $img->get_width / 2, $size / $img->get_height / 2, 675 $size / $img->get_width / 2, $size / $img->get_height / 2,
673 INTERP_HYPER, 192 676 INTERP_HYPER, 192
674 ); 677 );
675 } 678 }
676 } 679 }
677 680
681 # and lastly any markers (labels NYI)
678 my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B)); 682 my $dark_bg = ! ! ($mark & (MARK_B | MARK_GRAY_B));
679 683
680 for ([MARK_CIRCLE, $::circle_img[$dark_bg]], 684 for ([MARK_CIRCLE, $::circle_img[$dark_bg]],
681 [MARK_TRIANGLE, $::triangle_img[$dark_bg]], 685 [MARK_TRIANGLE, $::triangle_img[$dark_bg]],
682 [MARK_SQUARE, $::square_img[$dark_bg]]) { 686 [MARK_SQUARE, $::square_img[$dark_bg]]) {
683 my ($mask, $img) = @$_; 687 my ($mask, $img) = @$_;
684 if ($mark & $mask) { 688 if ($mark & $mask) {
685 $img->composite ( 689 $img->composite (
686 $base, 0, 0, $size, $size, 0, 0, 690 $base, 0, 0, $size, $size, -0.5, -0.5,
687 ($size - 1) / ($img->get_width - 1), ($size - 1) / ($img->get_height - 1), 691 $size / $img->get_width, $size / $img->get_height,
688 INTERP_HYPER, 255 692 INTERP_HYPER, 255
689 ); 693 );
690 } 694 }
691 } 695 }
692 696
693 #push @$$c, [$base->render_pixmap_and_mask (128)];
694 push @$$c, $base; 697 push @$$c, $base;
695 } 698 }
696 } 699 }
697 700
698 $$c->[$rand % @$$c]; 701 $$c->[$rand % @$$c];
703 706
704 my $c = $::font[$colour][$::fontmap{substr $text, 0, 1}]; 707 my $c = $::font[$colour][$::fontmap{substr $text, 0, 1}];
705 708
706 if ($c) { 709 if ($c) {
707 my ($w, $h) = ($c->get_width, $c->get_height); 710 my ($w, $h) = ($c->get_width, $c->get_height);
708 my $s = $height / $h; 711 my $s = ($height-1) / ($h-1);
709 712
710 $x -= $w * $s *0.5; 713 $x -= $w * $s * 0.5;
711 $y -= $height * 0.5; 714 $y -= $height * 0.5;
712 715
713 $c->composite ($pixbuf, 716 $c->composite ($pixbuf,
714 $x, $y, $w*$s+1, $height+1, $x, $y, $s, $s, 717 $x, $y, $w*$s+0.5, $height+0.5, $x-0.5, $y-0.5, $s, $s,
715 INTERP_HYPER, 128); 718 INTERP_BILINEAR, 192);
716 719
717 } else { 720 } else {
718 warn "unable to render character '$text'"; 721 warn "unable to render character '$text'";
719 } 722 }
720} 723}
727 unless ($black_pb) { 730 unless ($black_pb) {
728 $black_pb = new_pixbuf 1, 1, 0, 0; 731 $black_pb = new_pixbuf 1, 1, 0, 0;
729 $black_pb->put_pixels ("\x44\x11\x11", 0, 0); 732 $black_pb->put_pixels ("\x44\x11\x11", 0, 0);
730 } 733 }
731 734
732 $black_pb->scale ($pb, $x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1, $x1, $y1, 10000, 10000, INTERP_NEAREST); 735 $black_pb->composite ($pb, $x1, $y1, $x2 - $x1 + 1, $y2 - $y1 + 1, $x1, $y1, 1, 1, INTERP_NEAREST, 192);
733} 736}
734 737
735sub repaint_board { 738sub repaint_board {
736 my ($self) = @_; 739 my ($self) = @_;
737 my $canvas = $self->{canvas}; 740 my $canvas = $self->{canvas};
738 741
739 return unless $self->{board}; 742 return unless $self->{board};
740
741 %cache = ();
742 743
743 my ($w, $h) = @{$canvas->allocation}[2,3]; 744 my ($w, $h) = @{$canvas->allocation}[2,3];
744 745
745 my $s = $w > $h ? $h : $w; 746 my $s = $w > $h ? $h : $w;
746 747
747 $self->{offsets} = [int (($w - $s) / 2), int (($h - $s) / 2), $s]; 748 $self->{offsets} = [int (($w - $s) / 2), int (($h - $s) / 2), $s];
748 749
749 my $pixbuf;
750
751 {
752 my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height);
753
754 if ($s < $bw && $s < $bh) {
755 $pixbuf = new_pixbuf $s, $s, 0, 0;
756 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0);
757 } else {
758 $pixbuf = scale_pixbuf $::board_img, $s, $s, INTERP_TILES;
759 }
760 }
761
762 $self->{pixbuf} = $pixbuf;
763
764 my $size = $self->{size}; 750 my $size = $self->{size};
751
765 my $border = int ($s / $size); 752 my $border = int ($s / $size);
766 my $s2 = $s - $border * 2; 753 my $s2 = $s - $border * 2;
767 my $edge = int ($s2 / $size) | 1; 754 my $edge = int ($s2 / $size) | 1;
768 my $ofs = int ($edge / 2); 755 my $ofs = int ($edge / 2);
769 756
770 my @k = map int ($s2 * $_ / $size - $ofs + $border + 0.5), 0 .. $size; 757 my @k = map int ($s2 * $_ / $size - $ofs + $border + 0.5), 0 .. $size;
771 758
759 unless ($self->{background}) {
760 my $pixbuf;
761
762 my ($bw, $bh) = ($::board_img->get_width, $::board_img->get_height);
763
764 if ($s < $bw && $s < $bh) {
765 $pixbuf = new_pixbuf $s, $s, 1, 0;
766 $::board_img->copy_area (0, 0, $s, $s, $pixbuf, 0, 0);
767 } else {
768 $pixbuf = scale_pixbuf $::board_img, $s, $s, INTERP_TILES;
769 }
770
772 my $linew = int ($s / 300); 771 my $linew = int ($s / 300);
773 772
774 my $a = "A"; 773 my $a = "A";
775 for my $i (1 .. $size) { 774 for my $i (1 .. $size) {
776 pixbuf_rect $pixbuf, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew; 775 pixbuf_rect $pixbuf, $k[$i] - $linew, $k[1] - $linew, $k[$i] + $linew, $k[$size] + $linew;
777 pixbuf_rect $pixbuf, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew; 776 pixbuf_rect $pixbuf, $k[1] - $linew, $k[$i] - $linew, $k[$size] + $linew, $k[$i] + $linew;
778 777
779 pixbuf_text $pixbuf, 0, $k[$i], ($ofs +$border) / 2, $ofs, $a; 778 pixbuf_text $pixbuf, 0, $k[$i], ($ofs +$border) / 2, $ofs, $a;
780 pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border + $ofs / 2, $ofs, $a; 779 pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border + $ofs / 2, $ofs, $a;
781 pixbuf_text $pixbuf, 0, ($ofs + $border) / 2, $k[$i], $ofs, $size - $i + 1; 780 pixbuf_text $pixbuf, 0, ($ofs + $border) / 2, $k[$i], $ofs, $size - $i + 1;
782 pixbuf_text $pixbuf, 0, $s2 + $border + $ofs / 2, $k[$i], $ofs, $size - $i + 1; 781 pixbuf_text $pixbuf, 0, $s2 + $border + $ofs / 2, $k[$i], $ofs, $size - $i + 1;
783 782
784 $a++; 783 $a++;
785 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... 784 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
785 }
786
787 $self->{background} = $pixbuf;
786 } 788 }
789
790 my $pixbuf = $self->{pixbuf} = $self->{background}->copy;
787 791
788 # hoshi-points(!)#d# 792 # hoshi-points(!)#d#
789 # caching of empty board gfx(!)#d# 793 # caching of empty board gfx(!)#d#
790 794
791 for my $x (1 .. $size) { 795 for my $x (1 .. $size) {
794 798
795 if ($mark) { 799 if ($mark) {
796 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs); 800 my ($dx, $dy) = ($k[$x] - $ofs, $k[$y] - $ofs);
797 my $pb = $self->create_stack($mark, $edge, $x * 17 + $y * 11 ); 801 my $pb = $self->create_stack($mark, $edge, $x * 17 + $y * 11 );
798 802
799 $pb->composite ($pixbuf, $dx, $dy, $edge, $edge, $dx, $dy, 1, 1, INTERP_TILES, 192); 803 $pb->composite ($pixbuf, $dx, $dy, $edge, $edge, $dx, $dy, 1, 1, INTERP_NEAREST, 255);
800 804
801 #my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 ); 805 #my ($pm, $bm) = $self->create_stack($gc, $mark, $edge, $x * 17 + $y * 11 );
802 806
803 #$gc->set_clip_mask ($bm); 807 #$gc->set_clip_mask ($bm);
804 #$gc->set_clip_origin ($dx, $dy); 808 #$gc->set_clip_origin ($dx, $dy);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines