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.18 by pcg, Fri May 30 10:40:21 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines