ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/board.pl
(Generate patch)

Comparing kgsueme/kgsueme/board.pl (file contents):
Revision 1.1 by pcg, Sun Jun 22 20:47:12 2003 UTC vs.
Revision 1.2 by pcg, Mon Jun 23 01:14:21 2003 UTC

1use utf8; 1package Gtk2::GoBoard;
2
3package board;
4 2
5# my try at a real widget, needs the realobjects branch from Glib-CVS 3# my try at a real widget, needs the realobjects branch from Glib-CVS
6 4
7use Glib; 5use Glib;
8 6
160 158
161 $$c->[$rand % @$$c]; 159 $$c->[$rand % @$$c];
162} 160}
163 161
164sub pixbuf_text { 162sub pixbuf_text {
165 my ($pixbuf, $colour, $x, $y, $height, $text) = @_; 163 my ($self, $pixbuf, $colour, $x, $y, $height, $text) = @_;
166 164
165 #my $layout = $self->create_pango_layout ($text);
166 #my ($w, $h) = $layout->get_pixel_size;
167 #print "$w $h\n";#d#
168
167 my @c = grep $_, 169 my @c = grep $_,
168 map $::font[$colour][$::fontmap{$_}], 170 map $::font[$colour][$::fontmap{$_}],
169 split //, $text; 171 split //, $text;
170 172
171 if (@c) { 173 if (@c) {
211 213
212 # we leave enough space for the shadows.. I like smaller stones, and we 214 # we leave enough space for the shadows.. I like smaller stones, and we
213 # do no need to do the nifty recursive screen updates that goban2 does 215 # do no need to do the nifty recursive screen updates that goban2 does
214 my $border = int ($s / ($size + 3) * 0.5); 216 my $border = int ($s / ($size + 3) * 0.5);
215 my $s2 = $s - $border * 2; 217 my $s2 = $s - $border * 2;
216 my $edge = $self->{edge} = int ($s2 / ($size + 1) * 0.96) - ($::config->{randomize} ? 3 : 0); 218 my $edge = $self->{edge} = int ($s2 / ($size + 1) * 0.975);
217 my $ofs = int ($edge / 2); 219 my $ofs = int ($edge / 2);
218 220
219 my @k = map int ($s2 * $_ / ($size+1) + $border + 0.5), 0 .. $size; 221 my @k = map int ($s2 * $_ / ($size+1) + $border + 0.5), 0 .. $size;
220 222
221 $self->{k} = \@k; 223 $self->{k} = \@k;
245 247
246 # 38 max, but we allow a bit more 248 # 38 max, but we allow a bit more
247 my $label = (qw(- A B C D E F G H J K L M N O P Q R S T U V W X Y Z 249 my $label = (qw(- A B C D E F G H J K L M N O P Q R S T U V W X Y Z
248 AA BB CC DD EE FF GG HH JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ))[$i]; 250 AA BB CC DD EE FF GG HH JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ))[$i];
249 251
250 pixbuf_text $pixbuf, 0, $k[$i], $border, $ofs, $label; 252 pixbuf_text $self, $pixbuf, 0, $k[$i], $border, $ofs, $label;
251 pixbuf_text $pixbuf, 0, $k[$i], $s2 + $border, $ofs, $label; 253 pixbuf_text $self, $pixbuf, 0, $k[$i], $s2 + $border, $ofs, $label;
252 pixbuf_text $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1; 254 pixbuf_text $self, $pixbuf, 0, $border, $k[$i], $ofs, $size - $i + 1;
253 pixbuf_text $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1; 255 pixbuf_text $self, $pixbuf, 0, $s2 + $border, $k[$i], $ofs, $size - $i + 1;
254 256
255 $a++; 257 $a++;
256 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK... 258 $a++ if $a eq "I"; # not correct, instead of AA AB, we should get HH JJ KK...
257 } 259 }
258 260
291} 293}
292 294
293sub repaint_board { 295sub repaint_board {
294 my ($self, $board, $dopaint) = @_; 296 my ($self, $board, $dopaint) = @_;
295 297
298 my @areas;
299
296 my $old = $self->{board}; 300 my $old = $self->{board};
297 my $size = $self->{size}; 301 my $size = $self->{size};
298 my $edge = $self->{edge}; 302 my $edge = $self->{edge};
299 my $ofs = int ($edge * 0.5); 303 my $ofs = int ($edge * 0.5);
300 my $k = $self->{k}; 304 my $k = $self->{k};
305 my $mark = $board->{board}[$x-1][$y-1]; 309 my $mark = $board->{board}[$x-1][$y-1];
306 my $old = $old->{board}[$x-1][$y-1]; 310 my $old = $old->{board}[$x-1][$y-1];
307 311
308 if ($old != $mark) { 312 if ($old != $mark) {
309 my $rand = ($x ^ $y ^ 0x5555); 313 my $rand = ($x ^ $y ^ 0x5555);
310
311 #if ($::config->{randomize}) {
312 # $dx += ($rand % 7) - 3;
313 # $dy += ($rand / 3 % 7) - 3;
314 #}
315 314
316 my $shadow = $edge * 0.05; 315 my $shadow = $edge * 0.05;
317 my @area = ($k->[$x] - $ofs, $k->[$y] - $ofs, 316 my @area = ($k->[$x] - $ofs, $k->[$y] - $ofs,
318 $edge + $shadow, $edge + $shadow); 317 $edge + $shadow, $edge + $shadow);
319 318
340 $self->{board}{label}[$x-1][$y-1]; 339 $self->{board}{label}[$x-1][$y-1];
341 } 340 }
342 } 341 }
343 342
344 # speed none, normal, max 343 # speed none, normal, max
345 $pb->render_to_drawable ($self->{backgroundpm}, $self->style->black_gc, 344 $self->{backgroundpm}->draw_pixbuf ($self->style->black_gc, $pb,
346 0, 0, @area, 'max', 0, 0); 345 0, 0, @area, 'max', 0, 0);
347 # a single full clear_area is way faster than many single calls here 346 # a single full clear_area is way faster than many single calls here
348 $self->window->clear_area (@area) if $dopaint; 347 push @areas, \@area if $dopaint;
348 }
349 } 349 }
350 }
351
352 if (@areas) {
353 # the "cut-off" point is arbitrary
354 if (@areas > 16) {
355 # update a single rectangle only
356 my $rect = new Gtk2::Gdk::Rectangle @{pop @areas};
357 $rect = $rect->union (new Gtk2::Gdk::Rectangle @$_) for @areas;
358 $self->window->clear_area ($rect->values);
359 } else {
360 # update all the affected rectangles
361 $self->window->clear_area (@$_) for @areas;
350 } 362 }
351 } 363 }
352 364
353 $self->{board} = $board; 365 $self->{board} = $board;
354 #d# save 366 #d# save

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines