… | |
… | |
27 | # new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]" |
27 | # new_from_file Gtk::Gdk::Pixbuf "$IMGDIR/$_[0]" |
28 | load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]" |
28 | load_image Gtk::Gdk::ImlibImage "$IMGDIR/$_[0]" |
29 | or die "$IMGDIR/$_[0]: $!"; |
29 | or die "$IMGDIR/$_[0]: $!"; |
30 | } |
30 | } |
31 | |
31 | |
32 | our @black_img = load_img "b01-100x102.png"; |
32 | our @black_img = load_img "b-01.png"; |
33 | our @white_img = map +(load_img "w0$_-100x102_retouched.png"), 1,2,3; |
33 | our @white_img = map +(load_img "w-0$_.png"), 1,2,3,4,5; |
34 | our $board_img = load_img "woodgrain-01.jpg"; |
34 | our $board_img = load_img "woodgrain-01.jpg"; |
35 | |
35 | |
36 | { |
36 | { |
37 | use Storable (); |
37 | use Storable (); |
38 | use Scalar::Util (); |
38 | use Scalar::Util (); |
… | |
… | |
44 | |
44 | |
45 | $config = $state->{config} ||= {}; |
45 | $config = $state->{config} ||= {}; |
46 | |
46 | |
47 | # grr... more gtk+ brokenness |
47 | # grr... more gtk+ brokenness |
48 | my %get = ( |
48 | my %get = ( |
|
|
49 | hpane_position => sub { ($_[0]->children)[0]->allocation->[2] }, |
|
|
50 | vpane_position => sub { ($_[0]->children)[0]->allocation->[3] }, |
49 | window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, |
51 | window_size => sub { [ @{$_[0]->allocation}[2,3] ] }, |
50 | #window_pos => sub { die PApp::Util::dumpval [ $_[0]->get_root_origin ] }, |
52 | #window_pos => sub { die PApp::Util::dumpval [ $_[0]->get_root_origin ] }, |
51 | clist_column_widths => sub { |
53 | clist_column_widths => sub { |
52 | $_[0]{column_widths}; |
54 | $_[0]{column_widths}; |
53 | }, |
55 | }, |
… | |
… | |
492 | $self->{window}->signal_connect(delete_event => sub { $self->part; 1 }); |
494 | $self->{window}->signal_connect(delete_event => sub { $self->part; 1 }); |
493 | |
495 | |
494 | $self->{window}->add(my $hpane = new Gtk::HPaned); |
496 | $self->{window}->add(my $hpane = new Gtk::HPaned); |
495 | ::state $hpane, "game::hpane", undef, hpane_position => 500; |
497 | ::state $hpane, "game::hpane", undef, hpane_position => 500; |
496 | |
498 | |
497 | $::config{aa}++; |
499 | $::config{aa} = 1; |
498 | $self->{canvas} = $::config{aa} ? new_aa Gnome::Canvas : new Gnome::Canvas; |
500 | $self->{canvas} = $::config{aa} ? new_aa Gnome::Canvas : new Gnome::Canvas; |
499 | $hpane->add($self->{canvas}); |
501 | $hpane->add($self->{canvas}); |
500 | |
502 | |
501 | $self->{canvas}->signal_connect(size_allocate => sub { |
503 | { |
502 | warn "@_ @{$_[1]}"; |
|
|
503 | #$self->{canvas}->set_pixels_per_unit( |
|
|
504 | }); |
|
|
505 | |
|
|
506 | my $line_colour = $::config{line_colour} || "darkbrown"; |
504 | my $line_colour = $::config{line_colour} || "darkbrown"; |
507 | my $border = 0.1; |
505 | my $border = 0.1; |
508 | |
506 | my $ofs = 0.5 / $self->{size}; |
509 | $self->{canvas}->set_pixels_per_unit(300); |
|
|
510 | $self->{canvas}->set_scroll_region(-$border,-$border,1+$border,1+$border); |
|
|
511 | |
507 | |
512 | { |
508 | $self->{canvas}->set_pixels_per_unit(1000); |
|
|
509 | $self->{canvas}->set_scroll_region(-$border,-$border,1+$border,1+$border); |
|
|
510 | |
|
|
511 | $self->{canvas}->signal_connect(size_allocate => sub { |
|
|
512 | my ($w, $h) = @{$_[1]}[2,3]; |
|
|
513 | |
|
|
514 | $self->{canvas}->set_pixels_per_unit(($w > $h ? $h : $w)/(1+$border*2)); |
|
|
515 | |
|
|
516 | 1; |
|
|
517 | }); |
|
|
518 | |
513 | my $croot = $self->{canvas}->root; |
519 | my $croot = $self->{canvas}->root; |
514 | my $cgroup = $croot; #->new($croot, "Gnome::CanvasGroup"); |
520 | my $cgroup = $croot; #->new($croot, "Gnome::CanvasGroup"); |
515 | |
521 | |
516 | if ($::board_img) { |
522 | if ($::board_img) { |
517 | $cgroup->new($cgroup, "Gnome::CanvasImage", |
523 | $cgroup->new($cgroup, "Gnome::CanvasImage", |
… | |
… | |
519 | width => 1+$border*2, height => 1+$border*2, |
525 | width => 1+$border*2, height => 1+$border*2, |
520 | image => $::board_img, |
526 | image => $::board_img, |
521 | anchor => "nw" |
527 | anchor => "nw" |
522 | ); |
528 | ); |
523 | } else { |
529 | } else { |
524 | die; |
|
|
525 | $cgroup->new($cgroup, "Gnome::CanvasRect", |
530 | $cgroup->new($cgroup, "Gnome::CanvasRect", |
526 | x1 => -$border, x2 => 1+$border, |
531 | x1 => -$border, x2 => 1+$border, |
527 | y1 => -$border, y2 => 1+$border, |
532 | y1 => -$border, y2 => 1+$border, |
528 | outline_color => "black", |
533 | outline_color => "black", |
529 | fill_color => "brown", |
534 | fill_color => "brown", |
530 | width_pixels => 2, |
535 | width_pixels => 2, |
531 | ); |
536 | ); |
532 | } |
537 | } |
533 | |
538 | |
534 | my $x1 = $pad * 2; # == my $y1 = 30; |
|
|
535 | my $x2 = $w - ($pad * 2); # == my $y2 = 270; |
|
|
536 | my $w = $x2 - $x1; |
|
|
537 | my $s = $self->{size} - 1; |
|
|
538 | my $ofs = 0.5 / $self->{size}; |
|
|
539 | |
|
|
540 | my $a = "A"; |
539 | my $a = "A"; |
541 | for my $i (1 .. $self->{size}) { # one more iteration for the last lines |
540 | for my $i (1 .. $self->{size}) { # one more iteration for the last lines |
542 | my $k = $i / $self->{size} - $ofs; |
541 | my $k = $i / $self->{size} - $ofs; |
543 | |
542 | |
544 | $cgroup->new($cgroup, "Gnome::CanvasLine", |
543 | $cgroup->new($cgroup, "Gnome::CanvasLine", |
… | |
… | |
556 | |
555 | |
557 | my $text = $cgroup->new($cgroup, "Gnome::CanvasText", |
556 | my $text = $cgroup->new($cgroup, "Gnome::CanvasText", |
558 | x => 0, y => 0, text => $text, |
557 | x => 0, y => 0, text => $text, |
559 | justification => "center", |
558 | justification => "center", |
560 | anchor => "center", |
559 | anchor => "center", |
561 | font => "-*-helvetica-medium-r-*--34-*", |
560 | font => $::config{aa} ? "-*-helvetica-medium-r-*--34-*" : "-*-helvetica-bold-r-*--17-*", |
562 | fill_color => $line_colour); |
561 | fill_color => $line_colour); |
563 | |
562 | |
564 | $text->affine_relative($border*0.015,0, 0,$border*0.015, $x,$y); |
563 | $text->affine_relative($border*0.015,0, 0,$border*0.015, $x,$y); |
565 | } |
564 | } |
566 | |
565 | |
… | |
… | |
588 | x => $xk, y => $yk, |
587 | x => $xk, y => $yk, |
589 | width => $ofs*2, height => $ofs*2, |
588 | width => $ofs*2, height => $ofs*2, |
590 | image => $::white_img[int rand @::white_img], |
589 | image => $::white_img[int rand @::white_img], |
591 | anchor => "center"); |
590 | anchor => "center"); |
592 | } else { |
591 | } else { |
|
|
592 | die "need pixmaps\n"; |
593 | # too large, scale has NO effect |
593 | # too large, scale has NO effect |
594 | $col->[0] = |
594 | $col->[0] = |
595 | $cgroup->new($cgroup, "Gnome::CanvasEllipse", |
595 | $cgroup->new($cgroup, "Gnome::CanvasEllipse", |
596 | x1 => $xk, x2 => $xk + 0.001, |
596 | x1 => $xk, x2 => $xk + 0.001, |
597 | y1 => $yk, y2 => $yk + 0.001, |
597 | y1 => $yk, y2 => $yk + 0.001, |
… | |
… | |
605 | fill_color => "white"); |
605 | fill_color => "white"); |
606 | } |
606 | } |
607 | } |
607 | } |
608 | } |
608 | } |
609 | |
609 | |
610 | $self->{board_gfx}->{stones} = $stones; |
610 | $self->{board_gfx}{stones} = $stones; |
611 | } |
611 | } |
612 | |
612 | |
613 | $hpane->add(my $vpane = new Gtk::VPaned); |
613 | $hpane->add(my $vpane = new Gtk::VPaned); |
614 | ::state $vpane, "game", $self->{name}, vpane_position => 80; |
614 | ::state $vpane, "game", $self->{name}, vpane_position => 80; |
615 | |
615 | |