… | |
… | |
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; |
… | |
… | |
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; |
… | |
… | |
519 | ); |
516 | ); |
520 | } |
517 | } |
521 | } |
518 | } |
522 | |
519 | |
523 | # then the small stones (always using the first image) |
520 | # then the small stones (always using the first image) |
524 | for ([MARK_SMALL_B, $black_img[0]], |
521 | for ([MARK_SMALL_B, $mark & MARK_SMALL_GRAYED ? 106 : 255, $black_img[0]], |
525 | [MARK_SMALL_W, $white_img[0]]) { |
522 | [MARK_SMALL_W, $mark & MARK_SMALL_GRAYED ? 190 : 255, $white_img[0]]) { |
526 | my ($mask, $img) = @$_; |
523 | my ($mask, $alpha, $img) = @$_; |
527 | if ($mark & $mask) { |
524 | if ($mark & $mask) { |
528 | $img->composite ( |
525 | $img->composite ( |
529 | $base, ($size / 4) x2, (ceil $size / 2 + 1) x2, ($size / 4) x2, |
526 | $base, ($size / 4) x2, (ceil $size / 2 + 1) x2, ($size / 4) x2, |
530 | $size / $img->get_width / 2, $size / $img->get_height / 2, |
527 | $size / $img->get_width / 2, $size / $img->get_height / 2, |
531 | 'bilinear', 255 |
528 | 'bilinear', $alpha |
532 | ); |
529 | ); |
533 | } |
530 | } |
534 | } |
531 | } |
535 | |
532 | |
536 | # and finally any markers |
533 | # and finally any markers |
… | |
… | |
638 | |
635 | |
639 | 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; |
640 | 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; |
641 | |
638 | |
642 | my $pos = $self->{cursorpos}; |
639 | my $pos = $self->{cursorpos}; |
643 | 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]) { |
644 | |
643 | |
645 | $self->cursor (0); |
644 | $self->cursor (0); |
646 | |
645 | |
647 | if ($x >= 0 && $x < $size |
646 | if ($x >= 0 && $x < $size |
648 | && $y >= 0 && $y < $size) { |
647 | && $y >= 0 && $y < $size) { |