ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Gtk2-GoBoard/GoBoard.pm
(Generate patch)

Comparing Gtk2-GoBoard/GoBoard.pm (file contents):
Revision 1.6 by root, Wed Jun 25 07:07:34 2008 UTC vs.
Revision 1.15 by root, Fri May 6 17:36:36 2011 UTC

55Playing sounds required the L<Audio::Play> module. If it isn't installed, 55Playing sounds required the L<Audio::Play> module. If it isn't installed,
56sounds will silently not being played. The module intentionally doesn't 56sounds will silently not being played. The module intentionally doesn't
57depend on L<Audio::Play> as it isn't actively maintained anymore and fails 57depend on L<Audio::Play> as it isn't actively maintained anymore and fails
58to install cleanly. 58to install cleanly.
59 59
60Note that L<Audio::Play> is broken on 64-bit platforms, which the author
61knows about for half a decade now, but apparently can't be bothered to
62fix. The symptoms are that it cannot load the soundfile and will silently
63result in - silence.
64
60=over 4 65=over 4
61 66
62=cut 67=cut
63 68
64our $VERSION = '1.0'; 69our $VERSION = '1.02';
65 70
66no warnings; 71no warnings;
67use strict; 72use strict;
68 73
69use Scalar::Util; 74use Scalar::Util;
144 @triangle_img, @square_img, @circle_img, @cross_img); 149 @triangle_img, @square_img, @circle_img, @cross_img);
145 150
146sub load_images { 151sub load_images {
147 $board_img = load_image "woodgrain-01.jpg"; 152 $board_img = load_image "woodgrain-01.jpg";
148 @black_img = load_image "b-01.png"; 153 @black_img = load_image "b-01.png";
149 @white_img = map +(load_image "w-0$_.png"), 1,2,3,4,5; 154 @white_img = map +(load_image "w-0$_.png"), 1 .. 5;
150 $shadow_img = load_image "shadow.png"; 155 $shadow_img = load_image "shadow.png"; # also used to fake hoshi points
151 @triangle_img = map +(load_image "triangle-$_.png"), qw(b w); 156 @triangle_img = map +(load_image "triangle-$_.png"), qw(b w);
152 @square_img = map +(load_image "square-$_.png" ), qw(b w); 157 @square_img = map +(load_image "square-$_.png" ), qw(b w);
153 @circle_img = map +(load_image "circle-$_.png" ), qw(b w); 158 @circle_img = map +(load_image "circle-$_.png" ), qw(b w);
154 @cross_img = map +(load_image "cross-$_.png" ), qw(b w); 159 @cross_img = map +(load_image "cross-$_.png" ), qw(b w);
155} 160}
313 delete $self->{backgroundpm}; 318 delete $self->{backgroundpm};
314 delete $self->{backgroundpb}; 319 delete $self->{backgroundpb};
315 320
316 my $pixmap = new Gtk2::Gdk::Pixmap $self->window, $w, $h, -1; 321 my $pixmap = new Gtk2::Gdk::Pixmap $self->window, $w, $h, -1;
317 322
318 #my $gridcolour = 0x88444400; # black is traditional, but only with overlapping stones
319 my $gridcolour = 0x44444400; # black is traditional, but only with overlapping stones 323 my $gridcolour = 0x44444400; # black is traditional, but only with overlapping stones
320 my $labelcolour = 0x88444400; 324 my $labelcolour = 0x88444400;
321 325
322 # we leave enough space for the shadows.. I like smaller stones, and we
323 # do no need to do the nifty recursive screen updates that cgoban2 does
324 my $borderw = int ($w / ($size + 1) * 0.5); 326 my $borderw = int $w / ($size + 1) * 0.5;
325 my $borderh = $borderw; 327 my $borderh = $borderw;
326 my $w2 = $w - $borderw * 2; 328 my $w2 = $w - $borderw * 2;
327 my $h2 = $h - $borderh * 2; 329 my $h2 = $h - $borderh * 2;
328 my $edge = ceil ($w2 / ($size + 1)); 330 my $edge = ceil $w2 / ($size + 1);
329 my $ofs = $edge * 0.5; 331 my $ofs = $edge * 0.5;
330 332
331 # we need a certain minimum size, and just fudge some formula here 333 # we need a certain minimum size, and just fudge some formula here
332 return if $w < $size * 5 + 2 + $borderw 334 return if $w < $size * 5 + 2 + $borderw
333 || $h < $size * 6 + 2 + $borderh; 335 || $h < $size * 6 + 2 + $borderh;
344 $board_img->copy_area (0, 0, $w, $h, $pixbuf, 0, 0); 346 $board_img->copy_area (0, 0, $w, $h, $pixbuf, 0, 0);
345 } else { 347 } else {
346 $pixbuf = scale_pixbuf $board_img, $w, $h, 'bilinear', 0; # nearest for extra speed 348 $pixbuf = scale_pixbuf $board_img, $w, $h, 'bilinear', 0; # nearest for extra speed
347 } 349 }
348 350
349 my $linew = int ($w / 40 / $size); 351 my $linew = int $w / 40 / $size;
350 352
351 # ornamental border... we have time to waste :/ 353 # ornamental border... we have time to waste :/
352 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $w-1, $linew, 255; 354 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $w-1, $linew, 255;
353 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $h-1, 255; 355 pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $h-1, 255;
354 pixbuf_rect $pixbuf, 0xffcc7700, $w-$linew-1, 0, $w-1, $h-1, 255; 356 pixbuf_rect $pixbuf, 0xffcc7700, $w-$linew-1, 0, $w-1, $h-1, 255;
447 $self->{draw_stone} = sub { 449 $self->{draw_stone} = sub {
448 my ($x, $y) = @_; 450 my ($x, $y) = @_;
449 451
450 @area = ($kx[$x] - $ofs, $ky[$y] - $ofs, 452 @area = ($kx[$x] - $ofs, $ky[$y] - $ofs,
451 $edge + $shadow, $edge + $shadow); 453 $edge + $shadow, $edge + $shadow);
452 @areai = ((ceil $area[0]), (ceil $area[1]), 454 @areai = map +(ceil $_), @area; # area, integer
453 (int $area[2]), (int $area[3])); # area, integer
454 455
455 $pb = new_pixbuf @areai[2,3]; 456 $pb = new_pixbuf @areai[2,3];
456 $self->{backgroundpb}->copy_area (@areai, $pb, 0, 0); 457 $self->{backgroundpb}->copy_area (@areai, $pb, 0, 0);
457 458
458 $put_stack->($x-1, $y, $kx[$x-1] - $kx[$x], 0, 0, 0) if $x > 1; 459 $put_stack->($x-1, $y, $kx[$x-1] - $kx[$x], 0, 0, 0) if $x > 1;
496 my @stack; 497 my @stack;
497 my $csize = ceil $size; 498 my $csize = ceil $size;
498 my $shadow = $size * SHADOW; 499 my $shadow = $size * SHADOW;
499 500
500 for my $stone ($mark & MARK_W ? @white_img : @black_img) { 501 for my $stone ($mark & MARK_W ? @white_img : @black_img) {
501 my $base = new_pixbuf +(ceil $size + $shadow) x2, 1, 0x00000000; 502 my $base = new_pixbuf +(ceil $csize + $shadow) x2, 1, 0x00000000;
502 503
503 # zeroeth the shadow 504 # zeroeth the shadow
504 if (~$mark & MARK_GRAYED and $mark & (MARK_B | MARK_W)) { 505 if (~$mark & MARK_GRAYED and $mark & (MARK_B | MARK_W)) {
505 $shadow_img->composite ( 506 $shadow_img->composite (
506 $base, $shadow, $shadow, $csize, $csize, $shadow, $shadow, 507 $base, ($shadow) x2, $csize, $csize, ($shadow) x2,
507 $size / $shadow_img->get_width, $size / $shadow_img->get_height, 508 $size / $shadow_img->get_width, $size / $shadow_img->get_height,
508 'bilinear', 128 509 'bilinear', 128
509 ); 510 );
510 } 511 }
511 512
512 for ([MARK_B, $mark & MARK_GRAYED ? 96 : 255, 1], 513 for ([MARK_B, $mark & MARK_GRAYED ? 106 : 255, 1],
513 [MARK_W, $mark & MARK_GRAYED ? 160 : 255, TRAD_SIZE_W / TRAD_SIZE_B]) { 514 [MARK_W, $mark & MARK_GRAYED ? 190 : 255, TRAD_SIZE_W / TRAD_SIZE_B]) {
514 my ($mask, $alpha, $scale) = @$_; 515 my ($mask, $alpha, $scale) = @$_;
515 if ($mark & $mask) { 516 if ($mark & $mask) {
516 $stone->composite ( 517 $stone->composite (
517 $base, 0, 0, $csize, $csize, ($size * (1 - $scale) * 0.5 ) x2, 518 $base, 0, 0, $csize, $csize, ($size * (1 - $scale) * 0.5) x2,
518 $size * $scale / $stone->get_width, $size * $scale / $stone->get_height, 519 $size * $scale / $stone->get_width, $size * $scale / $stone->get_height,
519 'bilinear', $alpha 520 'bilinear', $alpha
520 ); 521 );
521 } 522 }
522 } 523 }
523 524
524 # then the small stones (always using the first image) 525 # then the small stones (always using the first image)
525 for ([MARK_SMALL_B, $black_img[0]], 526 for ([MARK_SMALL_B, $mark & MARK_SMALL_GRAYED ? 106 : 255, $black_img[0]],
526 [MARK_SMALL_W, $white_img[0]]) { 527 [MARK_SMALL_W, $mark & MARK_SMALL_GRAYED ? 190 : 255, $white_img[0]]) {
527 my ($mask, $img) = @$_; 528 my ($mask, $alpha, $img) = @$_;
528 if ($mark & $mask) { 529 if ($mark & $mask) {
529 $img->composite ( 530 $img->composite (
530 $base, (int $size / 4) x2, (ceil $size / 2 + 1) x2, ($size / 4) x2, 531 $base, ($size / 4) x2, (ceil $size / 2 + 1) x2, ($size / 4) x2,
531 $size / $img->get_width / 2, $size / $img->get_height / 2, 532 $size / $img->get_width / 2, $size / $img->get_height / 2,
532 'bilinear', 255 533 'bilinear', $alpha
533 ); 534 );
534 } 535 }
535 } 536 }
536 537
537 # and lastly any markers 538 # and finally any markers
538 my $dark_bg = ! ! ($mark & MARK_B); 539 my $dark_bg = ! ! ($mark & MARK_B);
539 540
540 for ([MARK_CIRCLE, $circle_img[$dark_bg]], 541 for ([MARK_CIRCLE, $circle_img [$dark_bg]],
541 [MARK_TRIANGLE, $triangle_img[$dark_bg]], 542 [MARK_TRIANGLE, $triangle_img[$dark_bg]],
543 [MARK_CROSS, $cross_img [$dark_bg]],
542 [MARK_SQUARE, $square_img[$dark_bg]], 544 [MARK_SQUARE, $square_img [$dark_bg]],
543 [MARK_CROSS, $cross_img[$dark_bg]],
544 [MARK_KO, $square_img[$dark_bg]]) { 545 [MARK_KO, $square_img [$dark_bg]]) {
545 my ($mask, $img) = @$_; 546 my ($mask, $img) = @$_;
546 if ($mark & $mask) { 547 if ($mark & $mask) {
547 $img->composite ( 548 $img->composite (
548 $base, 0, 0, $size, $size, 0, 0, 549 $base, 0, 0, $csize, $csize, 0, 0,
549 $size / $img->get_width, $size / $img->get_height, 550 $size / $img->get_width, $size / $img->get_height,
550 'bilinear', $dark_bg ? 176 : 190 551 'bilinear', $dark_bg ? 176 : 190
551 ); 552 );
552 } 553 }
553 } 554 }
639 640
640 my $x = int (($x - $self->{kx}[0]) * $size / ($self->{kx}[$size] - $self->{kx}[0]) + 0.5) - 1; 641 my $x = int (($x - $self->{kx}[0]) * $size / ($self->{kx}[$size] - $self->{kx}[0]) + 0.5) - 1;
641 my $y = int (($y - $self->{ky}[0]) * $size / ($self->{ky}[$size] - $self->{ky}[0]) + 0.5) - 1; 642 my $y = int (($y - $self->{ky}[0]) * $size / ($self->{ky}[$size] - $self->{ky}[0]) + 0.5) - 1;
642 643
643 my $pos = $self->{cursorpos}; 644 my $pos = $self->{cursorpos};
644 if ($x != $pos->[0] || $y != $pos->[1]) { 645 if ((not (defined $pos) && $x >= 0 && $x < $size && $y >= 0 && $y < $size)
646 || $x != $pos->[0]
647 || $y != $pos->[1]) {
645 648
646 $self->cursor (0); 649 $self->cursor (0);
647 650
648 if ($x >= 0 && $x < $size 651 if ($x >= 0 && $x < $size
649 && $y >= 0 && $y < $size) { 652 && $y >= 0 && $y < $size) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines