From c91d953548557f7c82396498ea8d33821afba5ed Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 22 Dec 2010 16:00:16 +0000 Subject: center in color runs --- lib/GridFiller.pm | 6 +++--- lib/GridFiller/Chooser/Random.pm | 4 ++-- lib/GridFiller/Chooser/Smarter.pm | 2 -- lib/GridFiller/Result/Pango.pm | 8 ++++---- lib/GridFiller/Result/Text.pm | 2 +- lib/GridFiller/Status.pm | 6 +++--- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/GridFiller.pm b/lib/GridFiller.pm index f88d94f..3932f0d 100644 --- a/lib/GridFiller.pm +++ b/lib/GridFiller.pm @@ -79,7 +79,7 @@ sub fill { $self->log->debug("Placing $word"); - my ($x,$y,$dir) = $chooser->find_place_for($word); + my ($space,$x,$y,$dir) = $chooser->find_place_for($word); if (! defined $x) { $self->log->debug("No place for $word"); @@ -87,8 +87,8 @@ sub fill { next; }; - $result->place_word_at($word,$x,$y,$dir); - $status->place_word_at($word,$x,$y,$dir); + $result->place_word_at($word,$space,$x,$y,$dir); + $status->place_word_at($word,$space,$x,$y,$dir); if ($self->log->is_debug) { $self->log->debug($status->to_string); diff --git a/lib/GridFiller/Chooser/Random.pm b/lib/GridFiller/Chooser/Random.pm index 7fefbf6..f949c4d 100644 --- a/lib/GridFiller/Chooser/Random.pm +++ b/lib/GridFiller/Chooser/Random.pm @@ -35,7 +35,7 @@ sub _find_place_horiz { for my $row (0..$rows-1) { $col = $self->_find_in_row($row,$length); - return ($col,$row,$HORIZONTAL) if defined $col; + return (0,$col,$row,$HORIZONTAL) if defined $col; } return; } @@ -48,7 +48,7 @@ sub _find_place_vert { for my $col (0..$cols-1) { $row = $self->_find_in_col($col,$length); - return ($col,$row,$VERTICAL) if defined $row; + return (0,$col,$row,$VERTICAL) if defined $row; } return; } diff --git a/lib/GridFiller/Chooser/Smarter.pm b/lib/GridFiller/Chooser/Smarter.pm index 43ad530..0abd088 100644 --- a/lib/GridFiller/Chooser/Smarter.pm +++ b/lib/GridFiller/Chooser/Smarter.pm @@ -27,8 +27,6 @@ sub find_place_for { my $ret = maxfirst @candidates; - shift @$ret; - return @$ret; } diff --git a/lib/GridFiller/Result/Pango.pm b/lib/GridFiller/Result/Pango.pm index 47a08c0..1172848 100644 --- a/lib/GridFiller/Result/Pango.pm +++ b/lib/GridFiller/Result/Pango.pm @@ -190,13 +190,13 @@ sub string_height { } sub _center_adj { - my ($self,$p) = @_; + my ($self,$p,$space) = @_; my ($w,$h) = $p->get_pixel_size; my $size = $self->cell_size; my $w_rounded = ceil($w/$size)*$size; - my $w_adj = ceil(($w_rounded-$w)/2); + my $w_adj = ceil(($space*$size+$w_rounded-$w)/2); my $h_adj = ceil(($size - $h)/2); return $w_adj,$h_adj; @@ -216,7 +216,7 @@ sub colour_for_string { my $PI=3.1415926; sub place_word_at { - my ($self, $word, $x, $y, $dir) = @_; + my ($self, $word, $space, $x, $y, $dir) = @_; $self->log->debug("Placing $word at ${x}:${y} ($dir)"); @@ -226,7 +226,7 @@ sub place_word_at { my $cr = $self->_cairo_c; $x*=$size;$y*=$size; - my ($w_adjustment,$h_adjustment) = $self->_center_adj($p); + my ($w_adjustment,$h_adjustment) = $self->_center_adj($p,$space); $cr->save; if ($dir == $HORIZONTAL) { diff --git a/lib/GridFiller/Result/Text.pm b/lib/GridFiller/Result/Text.pm index fb72ccb..03e7f8f 100644 --- a/lib/GridFiller/Result/Text.pm +++ b/lib/GridFiller/Result/Text.pm @@ -78,7 +78,7 @@ sub _find_colour_for { } sub place_word_at { - my ($self, $word, $x, $y, $dir) = @_; + my ($self, $word, $space, $x, $y, $dir) = @_; my $colour = $self->_find_colour_for($x,$y,$dir); diff --git a/lib/GridFiller/Status.pm b/lib/GridFiller/Status.pm index 6e457b6..bf5e9e6 100644 --- a/lib/GridFiller/Status.pm +++ b/lib/GridFiller/Status.pm @@ -82,17 +82,17 @@ sub _build_grid_status { } sub place_word_at { - my ($self, $word, $x, $y, $dir) = @_; + my ($self, $word, $space, $x, $y, $dir) = @_; $self->log->debug("Marking <$word> occupied at ${x}:${y} ($dir)"); if ($dir == $HORIZONTAL) { - for my $i (0..$self->length->($word)-1) { + for my $i (0..$self->length->($word)+$space-1) { $self->_mark_occupied($x+$i,$y); } } elsif ($dir == $VERTICAL) { - for my $i (0..$self->length->($word)-1) { + for my $i (0..$self->length->($word)+$space-1) { $self->_mark_occupied($x,$y+$i); } } -- cgit v1.2.3