--- kgsueme/kgsueme/game.pl 2003/05/31 17:28:52 1.13 +++ kgsueme/kgsueme/game.pl 2003/06/01 06:40:15 1.21 @@ -8,6 +8,8 @@ use base gtk::widget; +use POSIX qw(ceil); + sub new { my $self = shift; $self = $self->SUPER::new(@_); @@ -50,6 +52,8 @@ my $move = int (@{$self->{path}} * $_[0]->get_value); + $self->{board_label}->set_text ("Move $move"); + $self->{board} = new KGS::Game::Board $self->{size}; $self->{board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]); @@ -59,7 +63,12 @@ }); } - $vbox->pack_start(($self->{canvas} = new Gtk2::DrawingArea), 1, 1, 0); + $vbox->pack_start((my $aspect_frame = new Gtk2::AspectFrame "", 0.5, 0.5, 1, 0), 1, 1, 0); + $aspect_frame->set (border_width => 0, shadow_type => 'none', label_xalign => 0.5); + $self->{board_label} = $aspect_frame->get_label_widget; + + $aspect_frame->add($self->{canvas} = new Gtk2::DrawingArea); + $self->{canvas}->double_buffered (0) if $::config->{conserve_memory}; $self->{canvas}->signal_connect(configure_event => \&configure_event, $self); $self->{canvas}->signal_connect(expose_event => \&expose_event, $self); @@ -71,7 +80,7 @@ $self->{vpane}->add(my $sw = new Gtk2::ScrolledWindow); $sw->set_policy("automatic", "always"); - $sw->add(($self->{userlist} = new gtk::userlist)->widget); + $sw->add(($self->{userlist} = new userlist)->widget); $self->{vpane}->add(my $vbox = new Gtk2::VBox); @@ -91,13 +100,15 @@ } sub event_update_users { - my ($self) = @_; + my ($self, $add, $update, $remove) = @_; - $self->{userlist}->update($self->{users}); + $self->{userlist}->update ($add, $update, $remove); } sub join { my ($self) = @_; + return if $self->{joined}; + $self->SUPER::join; $self->{window}->show_all; @@ -105,6 +116,7 @@ sub part { my ($self) = @_; + return unless $self->{joined}; $self->SUPER::part; $self->{window}->hide; @@ -126,12 +138,8 @@ $self->{pixbuf} or return; my $area = $event->area; - my ($ox, $oy, $s) = @{$self->{offsets}}; - $self->redraw ( - (new Gtk2::Gdk::Rectangle $area->x - $ox, $area->y - $oy, $area->width, $area->height) - ->intersect(new Gtk2::Gdk::Rectangle 0, 0, $s, $s) - ); + $self->redraw ($area); 0; } @@ -178,8 +186,8 @@ # zeroeth the shadow if ($mark & (MARK_B | MARK_W)) { - $::black_img[0]->composite ( - $base, $shadow, $shadow, $size, $size, $shadow, $shadow, + $::shadow_img->composite ( + $base, $shadow, $shadow, $size, $size, $shadow - 0.5, $shadow - 0.5, $size / $stone->get_width, $size / $stone->get_height, $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192 ); @@ -206,9 +214,9 @@ my ($mask, $img) = @$_; if ($mark & $mask) { $img->composite ( - $base, ($size / 4) x2, (int ($size / 2 + 0.5)) x2, ($size / 4) x2, + $base, (ceil ($size / 4)) x2, (ceil ($size / 2)) x2, (ceil ($size / 4)) x2, $size / $img->get_width / 2, $size / $img->get_height / 2, - $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 192 + $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 224 ); } } @@ -253,8 +261,9 @@ for (@c) { my $w = $_->get_width * $s; + # +2 == don't fight the rounding $_->composite ($pixbuf, - $x, $y, $w+1, $height+1, $x, $y, $s, $s, + $x, $y, $w+2, $height+2, $x, $y, $s, $s, $::config->{speed} ? INTERP_NEAREST : INTERP_BILINEAR, 255); $x += $w + $spacing; @@ -278,15 +287,17 @@ return $expose_area unless $self->{board}; my ($w, $h) = ($canvas->allocation->values)[2,3]; - - my $s = $w > $h ? $h : $w; - return unless $s > 128; + die "FATAL: board aspect ratio != 1" unless $w == $h; - $self->{offsets} = [int (($w - $s) / 2), int (($h - $s) / 2), $s]; + my $s = $w; + return unless $s >= 200; + my $size = $self->{size}; + # we leave enough space for the shadows.. I like smaller stones, and we + # do no need to do the nifty recursive screen updates that goban2 does my $border = int ($s / ($size + 3) * 0.5); my $s2 = $s - $border * 2; my $edge = int ($s2 / ($size + 1) * 0.96) - ($::config->{randomize} ? 3 : 0); @@ -342,7 +353,7 @@ $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... } - unless ($::config->{conserve_memory}) { + unless ($::config->{conserve_memory} > 1) { $self->{background} = $pixbuf; $pixbuf = $pixbuf->copy; } @@ -421,13 +432,12 @@ if ($area && $self->{pixbuf}) { my ($x, $y, $w, $h) = $area->values; - my ($ox, $oy, $s) = @{$self->{offsets}}; $self->{canvas}->window->draw_pixbuf ($self->{canvas}->style->white_gc, $self->{pixbuf}, - $x, $y, $x + $ox, $y + $oy, $w, $h, + $x, $y, $x, $y, $w, $h, "normal", 0, 0); $self->{canvas}->window->draw_rectangle ($self->{canvas}->style->black_gc, 0, - $x + $ox - 1, $y + $oy - 1, $w + 2, $h + 2) if $::DEBUG_EXPOSE; + $x - 1, $y - 1, $w + 2, $h + 2) if $::DEBUG_EXPOSE; } }