| 1 | package Bio::Graphics::Glyph::primers; | ||
| 2 | # package to use for drawing something that looks like | ||
| 3 | # primer pairs. | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use base qw(Bio::Graphics::Glyph::generic); | ||
| 7 | |||
| 8 | use constant HEIGHT => 8; | ||
| 9 | |||
| 10 | # override draw method | ||
| 11 | sub draw_component { | ||
| 12 | my $self = shift; | ||
| 13 | my $gd = shift; | ||
| 14 | my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_); | ||
| 15 | my $height = $self->option('height') || $self->option('size') || HEIGHT; | ||
| 16 | |||
| 17 | my $fg = $self->fgcolor; | ||
| 18 | my $a2 = $height/2; | ||
| 19 | my $center = $y1 + $a2; | ||
| 20 | |||
| 21 | |||
| 22 | # just draw us as a solid line -- very simple | ||
| 23 | if ($x2-$x1 < $height*2) { | ||
| 24 | $gd->line($x1,$center,$x2,$center,$fg); | ||
| 25 | return; | ||
| 26 | } | ||
| 27 | |||
| 28 | # otherwise draw two pairs of arrows | ||
| 29 | # --> <-- | ||
| 30 | my $trunc_left = $x1 < $self->panel->left; | ||
| 31 | my $trunc_right = $x2 > $self->panel->right; | ||
| 32 | |||
| 33 | unless ($trunc_left) { | ||
| 34 | $gd->setThickness(2) if $height > 6; | ||
| 35 | $gd->line($x1,$center,$x1 + $height,$center,$fg); | ||
| 36 | $gd->line($x1 + $height,$center,$x1 + $height - $a2,$center-$a2,$fg); | ||
| 37 | $gd->line($x1 + $height,$center,$x1 + $height - $a2,$center+$a2,$fg); | ||
| 38 | $gd->setThickness(1); | ||
| 39 | } | ||
| 40 | |||
| 41 | unless ($trunc_right) { | ||
| 42 | $gd->setThickness(2) if $height > 6; | ||
| 43 | $gd->line($x2,$center,$x2 - $height,$center,$fg); | ||
| 44 | $gd->line($x2 - $height,$center,$x2 - $height + $a2,$center+$a2,$fg); | ||
| 45 | $gd->line($x2 - $height,$center,$x2 - $height + $a2,$center-$a2,$fg); | ||
| 46 | $gd->setThickness(1); | ||
| 47 | } | ||
| 48 | |||
| 49 | # connect the dots if requested | ||
| 50 | if ($self->connect) { | ||
| 51 | my $c = $self->color('connect_color') || $self->bgcolor; | ||
| 52 | $gd->line($x1 + ($trunc_left ? 0 : $height + 2),$center, | ||
| 53 | $x2 - ($trunc_right ? 0 : $height + 2),$center, | ||
| 54 | $c); | ||
| 55 | } | ||
| 56 | |||
| 57 | # add a label if requested | ||
| 58 | $self->draw_label($gd,@_) if $self->option('label'); | ||
| 59 | $self->draw_description($gd,@_) if $self->option('description'); | ||
| 60 | |||
| 61 | } | ||
| 62 | |||
| 63 | sub connect { | ||
| 64 | my $self = shift; | ||
| 65 | return $self->option('connect') if defined $self->option('connect'); | ||
| 66 | 1; # default | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; | ||
| 70 | |||
| 71 | __END__ |