| 1 | package Bio::Graphics::Glyph::flag; | ||
| 2 | |||
| 3 | # Non object-oriented utilities used here-and-there in Bio::Graphics modules | ||
| 4 | |||
| 5 | sub my_description { | ||
| 6 | return <<END; | ||
| 7 | This glyph draws a flag with text next to it. | ||
| 8 | END | ||
| 9 | } | ||
| 10 | |||
| 11 | sub my_options { | ||
| 12 | { | ||
| 13 | text => [ | ||
| 14 | 'string', | ||
| 15 | 'ori', | ||
| 16 | 'Text to draw next to the flag.'], | ||
| 17 | width => [ | ||
| 18 | 'integer', | ||
| 19 | 20, | ||
| 20 | 'Width of the flag.'], | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | =head1 NAME | ||
| 25 | |||
| 26 | Bio::Graphics::Glyph::flag - the "flag" glyph | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | use strict; | ||
| 31 | use base qw(Bio::Graphics::Glyph::generic); | ||
| 32 | |||
| 33 | sub default_text | ||
| 34 | { | ||
| 35 | return "ori"; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub default_width | ||
| 39 | { | ||
| 40 | return 20; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub draw_component { | ||
| 44 | my $self = shift; | ||
| 45 | my $gd = shift; | ||
| 46 | my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_); | ||
| 47 | |||
| 48 | my $fg = $self->fgcolor; | ||
| 49 | my $bg = $self->bgcolor; | ||
| 50 | |||
| 51 | my $width = $self->option('width') || $self->default_width; | ||
| 52 | my $text = $self->option('text') || $self->default_text; | ||
| 53 | |||
| 54 | my $oneThirdY = $y1 + ($y2-$y1) / 3; | ||
| 55 | my $twoThirdsY = $y1 + 2 * ($y2-$y1) / 3; | ||
| 56 | |||
| 57 | my $poly_pkg = $self->polygon_package; | ||
| 58 | |||
| 59 | my $polygon = $poly_pkg->new(); | ||
| 60 | $polygon->addPt($x1, $y1); | ||
| 61 | $polygon->addPt($x1+$width, $oneThirdY); | ||
| 62 | $polygon->addPt($x1, $twoThirdsY); | ||
| 63 | |||
| 64 | $gd->polygon($polygon, $fg); | ||
| 65 | |||
| 66 | $gd->fillToBorder($x1+$width/2, $oneThirdY, $fg, $bg); | ||
| 67 | |||
| 68 | $gd->line($x1, $y1, $x1, $y2, $fg); | ||
| 69 | |||
| 70 | my $font = $self->option('labelfont') || $self->font; | ||
| 71 | |||
| 72 | $gd->string($font, $x1 + 3, $twoThirdsY-3, $text, $self->fontcolor); | ||
| 73 | |||
| 74 | } | ||
| 75 | |||
| 76 | 1; | ||
| 77 | |||
| 78 | __END__ |