… | |
… | |
59 | |
59 | |
60 | =over 4 |
60 | =over 4 |
61 | |
61 | |
62 | =cut |
62 | =cut |
63 | |
63 | |
64 | our $VERSION = '1.0'; |
64 | our $VERSION = '1.01'; |
65 | |
65 | |
66 | no warnings; |
66 | no warnings; |
67 | use strict; |
67 | use strict; |
68 | |
68 | |
69 | use Scalar::Util; |
69 | use Scalar::Util; |
… | |
… | |
144 | @triangle_img, @square_img, @circle_img, @cross_img); |
144 | @triangle_img, @square_img, @circle_img, @cross_img); |
145 | |
145 | |
146 | sub load_images { |
146 | sub load_images { |
147 | $board_img = load_image "woodgrain-01.jpg"; |
147 | $board_img = load_image "woodgrain-01.jpg"; |
148 | @black_img = load_image "b-01.png"; |
148 | @black_img = load_image "b-01.png"; |
149 | @white_img = map +(load_image "w-0$_.png"), 1,2,3,4,5; |
149 | @white_img = map +(load_image "w-0$_.png"), 1 .. 5; |
150 | $shadow_img = load_image "shadow.png"; |
150 | $shadow_img = load_image "shadow.png"; # also used to fake hoshi points |
151 | @triangle_img = map +(load_image "triangle-$_.png"), qw(b w); |
151 | @triangle_img = map +(load_image "triangle-$_.png"), qw(b w); |
152 | @square_img = map +(load_image "square-$_.png" ), qw(b w); |
152 | @square_img = map +(load_image "square-$_.png" ), qw(b w); |
153 | @circle_img = map +(load_image "circle-$_.png" ), qw(b w); |
153 | @circle_img = map +(load_image "circle-$_.png" ), qw(b w); |
154 | @cross_img = map +(load_image "cross-$_.png" ), qw(b w); |
154 | @cross_img = map +(load_image "cross-$_.png" ), qw(b w); |
155 | } |
155 | } |
… | |
… | |
313 | delete $self->{backgroundpm}; |
313 | delete $self->{backgroundpm}; |
314 | delete $self->{backgroundpb}; |
314 | delete $self->{backgroundpb}; |
315 | |
315 | |
316 | my $pixmap = new Gtk2::Gdk::Pixmap $self->window, $w, $h, -1; |
316 | my $pixmap = new Gtk2::Gdk::Pixmap $self->window, $w, $h, -1; |
317 | |
317 | |
318 | #my $gridcolour = 0x88444400; # black is traditional, but only with overlapping stones |
|
|
319 | my $gridcolour = 0x44444400; # black is traditional, but only with overlapping stones |
318 | my $gridcolour = 0x44444400; # black is traditional, but only with overlapping stones |
320 | my $labelcolour = 0x88444400; |
319 | my $labelcolour = 0x88444400; |
321 | |
320 | |
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); |
321 | my $borderw = int $w / ($size + 1) * 0.5; |
325 | my $borderh = $borderw; |
322 | my $borderh = $borderw; |
326 | my $w2 = $w - $borderw * 2; |
323 | my $w2 = $w - $borderw * 2; |
327 | my $h2 = $h - $borderh * 2; |
324 | my $h2 = $h - $borderh * 2; |
328 | my $edge = ceil ($w2 / ($size + 1)); |
325 | my $edge = ceil $w2 / ($size + 1); |
329 | my $ofs = $edge * 0.5; |
326 | my $ofs = $edge * 0.5; |
330 | |
327 | |
331 | # we need a certain minimum size, and just fudge some formula here |
328 | # we need a certain minimum size, and just fudge some formula here |
332 | return if $w < $size * 5 + 2 + $borderw |
329 | return if $w < $size * 5 + 2 + $borderw |
333 | || $h < $size * 6 + 2 + $borderh; |
330 | || $h < $size * 6 + 2 + $borderh; |
… | |
… | |
344 | $board_img->copy_area (0, 0, $w, $h, $pixbuf, 0, 0); |
341 | $board_img->copy_area (0, 0, $w, $h, $pixbuf, 0, 0); |
345 | } else { |
342 | } else { |
346 | $pixbuf = scale_pixbuf $board_img, $w, $h, 'bilinear', 0; # nearest for extra speed |
343 | $pixbuf = scale_pixbuf $board_img, $w, $h, 'bilinear', 0; # nearest for extra speed |
347 | } |
344 | } |
348 | |
345 | |
349 | my $linew = int ($w / 40 / $size); |
346 | my $linew = int $w / 40 / $size; |
350 | |
347 | |
351 | # ornamental border... we have time to waste :/ |
348 | # ornamental border... we have time to waste :/ |
352 | pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $w-1, $linew, 255; |
349 | pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $w-1, $linew, 255; |
353 | pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $h-1, 255; |
350 | pixbuf_rect $pixbuf, 0xffcc7700, 0, 0, $linew, $h-1, 255; |
354 | pixbuf_rect $pixbuf, 0xffcc7700, $w-$linew-1, 0, $w-1, $h-1, 255; |
351 | pixbuf_rect $pixbuf, 0xffcc7700, $w-$linew-1, 0, $w-1, $h-1, 255; |
… | |
… | |
447 | $self->{draw_stone} = sub { |
444 | $self->{draw_stone} = sub { |
448 | my ($x, $y) = @_; |
445 | my ($x, $y) = @_; |
449 | |
446 | |
450 | @area = ($kx[$x] - $ofs, $ky[$y] - $ofs, |
447 | @area = ($kx[$x] - $ofs, $ky[$y] - $ofs, |
451 | $edge + $shadow, $edge + $shadow); |
448 | $edge + $shadow, $edge + $shadow); |
452 | @areai = ((ceil $area[0]), (ceil $area[1]), |
449 | @areai = map +(ceil $_), @area; # area, integer |
453 | (int $area[2]), (int $area[3])); # area, integer |
|
|
454 | |
450 | |
455 | $pb = new_pixbuf @areai[2,3]; |
451 | $pb = new_pixbuf @areai[2,3]; |
456 | $self->{backgroundpb}->copy_area (@areai, $pb, 0, 0); |
452 | $self->{backgroundpb}->copy_area (@areai, $pb, 0, 0); |
457 | |
453 | |
458 | $put_stack->($x-1, $y, $kx[$x-1] - $kx[$x], 0, 0, 0) if $x > 1; |
454 | $put_stack->($x-1, $y, $kx[$x-1] - $kx[$x], 0, 0, 0) if $x > 1; |
… | |
… | |
496 | my @stack; |
492 | my @stack; |
497 | my $csize = ceil $size; |
493 | my $csize = ceil $size; |
498 | my $shadow = $size * SHADOW; |
494 | my $shadow = $size * SHADOW; |
499 | |
495 | |
500 | for my $stone ($mark & MARK_W ? @white_img : @black_img) { |
496 | for my $stone ($mark & MARK_W ? @white_img : @black_img) { |
501 | my $base = new_pixbuf +(ceil $size + $shadow) x2, 1, 0x00000000; |
497 | my $base = new_pixbuf +(ceil $csize + $shadow) x2, 1, 0x00000000; |
502 | |
498 | |
503 | # zeroeth the shadow |
499 | # zeroeth the shadow |
504 | if (~$mark & MARK_GRAYED and $mark & (MARK_B | MARK_W)) { |
500 | if (~$mark & MARK_GRAYED and $mark & (MARK_B | MARK_W)) { |
505 | $shadow_img->composite ( |
501 | $shadow_img->composite ( |
506 | $base, $shadow, $shadow, $csize, $csize, $shadow, $shadow, |
502 | $base, ($shadow) x2, $csize, $csize, ($shadow) x2, |
507 | $size / $shadow_img->get_width, $size / $shadow_img->get_height, |
503 | $size / $shadow_img->get_width, $size / $shadow_img->get_height, |
508 | 'bilinear', 128 |
504 | 'bilinear', 128 |
509 | ); |
505 | ); |
510 | } |
506 | } |
511 | |
507 | |
512 | for ([MARK_B, $mark & MARK_GRAYED ? 106 : 255, 1], |
508 | for ([MARK_B, $mark & MARK_GRAYED ? 106 : 255, 1], |
513 | [MARK_W, $mark & MARK_GRAYED ? 190 : 255, TRAD_SIZE_W / TRAD_SIZE_B]) { |
509 | [MARK_W, $mark & MARK_GRAYED ? 190 : 255, TRAD_SIZE_W / TRAD_SIZE_B]) { |
514 | my ($mask, $alpha, $scale) = @$_; |
510 | my ($mask, $alpha, $scale) = @$_; |
515 | if ($mark & $mask) { |
511 | if ($mark & $mask) { |
516 | $stone->composite ( |
512 | $stone->composite ( |
517 | $base, 0, 0, $csize, $csize, ($size * (1 - $scale) * 0.5 ) x2, |
513 | $base, 0, 0, $csize, $csize, ($size * (1 - $scale) * 0.5) x2, |
518 | $size * $scale / $stone->get_width, $size * $scale / $stone->get_height, |
514 | $size * $scale / $stone->get_width, $size * $scale / $stone->get_height, |
519 | 'bilinear', $alpha |
515 | 'bilinear', $alpha |
520 | ); |
516 | ); |
521 | } |
517 | } |
522 | } |
518 | } |
523 | |
519 | |
524 | # then the small stones (always using the first image) |
520 | # then the small stones (always using the first image) |
525 | for ([MARK_SMALL_B, $black_img[0]], |
521 | for ([MARK_SMALL_B, $mark & MARK_SMALL_GRAYED ? 106 : 255, $black_img[0]], |
526 | [MARK_SMALL_W, $white_img[0]]) { |
522 | [MARK_SMALL_W, $mark & MARK_SMALL_GRAYED ? 190 : 255, $white_img[0]]) { |
527 | my ($mask, $img) = @$_; |
523 | my ($mask, $alpha, $img) = @$_; |
528 | if ($mark & $mask) { |
524 | if ($mark & $mask) { |
529 | $img->composite ( |
525 | $img->composite ( |
530 | $base, (int $size / 4) x2, (ceil $size / 2 + 1) x2, ($size / 4) x2, |
526 | $base, ($size / 4) x2, (ceil $size / 2 + 1) x2, ($size / 4) x2, |
531 | $size / $img->get_width / 2, $size / $img->get_height / 2, |
527 | $size / $img->get_width / 2, $size / $img->get_height / 2, |
532 | 'bilinear', 255 |
528 | 'bilinear', $alpha |
533 | ); |
529 | ); |
534 | } |
530 | } |
535 | } |
531 | } |
536 | |
532 | |
537 | # and lastly any markers |
533 | # and finally any markers |
538 | my $dark_bg = ! ! ($mark & MARK_B); |
534 | my $dark_bg = ! ! ($mark & MARK_B); |
539 | |
535 | |
540 | for ([MARK_CIRCLE, $circle_img[$dark_bg]], |
536 | for ([MARK_CIRCLE, $circle_img [$dark_bg]], |
541 | [MARK_TRIANGLE, $triangle_img[$dark_bg]], |
537 | [MARK_TRIANGLE, $triangle_img[$dark_bg]], |
542 | [MARK_CROSS, $cross_img[$dark_bg]], |
538 | [MARK_CROSS, $cross_img [$dark_bg]], |
543 | [MARK_SQUARE, $square_img[$dark_bg]], |
539 | [MARK_SQUARE, $square_img [$dark_bg]], |
544 | [MARK_KO, $square_img[$dark_bg]]) { |
540 | [MARK_KO, $square_img [$dark_bg]]) { |
545 | my ($mask, $img) = @$_; |
541 | my ($mask, $img) = @$_; |
546 | if ($mark & $mask) { |
542 | if ($mark & $mask) { |
547 | $img->composite ( |
543 | $img->composite ( |
548 | $base, 0, 0, $size, $size, 0, 0, |
544 | $base, 0, 0, $csize, $csize, 0, 0, |
549 | $size / $img->get_width, $size / $img->get_height, |
545 | $size / $img->get_width, $size / $img->get_height, |
550 | 'bilinear', $dark_bg ? 176 : 190 |
546 | 'bilinear', $dark_bg ? 176 : 190 |
551 | ); |
547 | ); |
552 | } |
548 | } |
553 | } |
549 | } |
… | |
… | |
639 | |
635 | |
640 | my $x = int (($x - $self->{kx}[0]) * $size / ($self->{kx}[$size] - $self->{kx}[0]) + 0.5) - 1; |
636 | 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; |
637 | my $y = int (($y - $self->{ky}[0]) * $size / ($self->{ky}[$size] - $self->{ky}[0]) + 0.5) - 1; |
642 | |
638 | |
643 | my $pos = $self->{cursorpos}; |
639 | my $pos = $self->{cursorpos}; |
644 | if ($x != $pos->[0] || $y != $pos->[1]) { |
640 | if ((not (defined $pos) && $x >= 0 && $x < $size && $y >= 0 && $y < $size) |
|
|
641 | || $x != $pos->[0] |
|
|
642 | || $y != $pos->[1]) { |
645 | |
643 | |
646 | $self->cursor (0); |
644 | $self->cursor (0); |
647 | |
645 | |
648 | if ($x >= 0 && $x < $size |
646 | if ($x >= 0 && $x < $size |
649 | && $y >= 0 && $y < $size) { |
647 | && $y >= 0 && $y < $size) { |