| 1 | package Bio::Graphics::Glyph::dashed_line; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw(Bio::Graphics::Glyph::generic); | ||
| 5 | |||
| 6 | sub my_description { | ||
| 7 | return <<END; | ||
| 8 | This glyph draws a dashed line. The lengths of the dash and the space are configurable. | ||
| 9 | The space can be filled with a different color, thus making a two-colored line. | ||
| 10 | The junction of the two colors can be "sheared" creating an interlocking effect. | ||
| 11 | END | ||
| 12 | } | ||
| 13 | |||
| 14 | sub my_options { | ||
| 15 | { | ||
| 16 | dash_size => [ | ||
| 17 | 'integer', | ||
| 18 | 6, | ||
| 19 | 'Width of the dash.'], | ||
| 20 | space_size => [ | ||
| 21 | 'integer', | ||
| 22 | 3, | ||
| 23 | 'Width of the space between dashes.'], | ||
| 24 | space_color => [ | ||
| 25 | 'color', | ||
| 26 | undef, | ||
| 27 | 'Color of the interval between dashes.', | ||
| 28 | 'Nothing will be drawn between dashes if undef.'], | ||
| 29 | shear => [ | ||
| 30 | 'boolean', | ||
| 31 | undef, | ||
| 32 | 'Whether to offset the dash and space to create an interlocking effect.'], | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | sub default_linewidth | ||
| 37 | { | ||
| 38 | return 1; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub default_dash_size | ||
| 42 | { | ||
| 43 | return 6; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub default_space_size | ||
| 47 | { | ||
| 48 | return 3; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub draw_component { | ||
| 52 | my $self = shift; | ||
| 53 | my $gd = shift; | ||
| 54 | my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_); | ||
| 55 | |||
| 56 | my $fg = $self->fgcolor; | ||
| 57 | |||
| 58 | my $midY = ($y1+$y2) / 2; | ||
| 59 | |||
| 60 | my $linewidth = defined $self->option('linewidth') ? $self->option('linewidth') : $self->default_linewidth(); | ||
| 61 | my $dash_size = defined $self->option('dash_size') ? $self->option('dash_size') : $self->default_dash_size(); | ||
| 62 | my $space_size = defined $self->option('space_size') ? $self->option('space_size') : $self->default_space_size(); | ||
| 63 | my $space_color = $self->option('space_color'); | ||
| 64 | my $shear = $self->option('shear') || ""; | ||
| 65 | $space_color = $self->factory->translate_color($space_color) if $space_color; | ||
| 66 | |||
| 67 | my ($x, $_y1, $_y2); | ||
| 68 | $x = $x1; | ||
| 69 | while ($x<$x2) | ||
| 70 | { | ||
| 71 | my $newX = $x+$dash_size; | ||
| 72 | $newX = $x2 if $newX > $x2; | ||
| 73 | if ($shear == 1) | ||
| 74 | { | ||
| 75 | $_y1 = $midY-$linewidth; | ||
| 76 | $_y2 = $midY; | ||
| 77 | } | ||
| 78 | else | ||
| 79 | { | ||
| 80 | $_y1 = $midY - $linewidth/2; | ||
| 81 | $_y2 = $midY + $linewidth/2; | ||
| 82 | } | ||
| 83 | $self->filled_box($gd,$x,$_y1,$newX,$_y2,$fg,$fg); | ||
| 84 | last if $newX >= $x2; | ||
| 85 | |||
| 86 | $x = $newX; | ||
| 87 | $newX = $x+$space_size; | ||
| 88 | $newX = $x2 if $newX > $x2; | ||
| 89 | if ($space_color) | ||
| 90 | { | ||
| 91 | if ($shear == 1) | ||
| 92 | { | ||
| 93 | $_y1 = $midY; | ||
| 94 | $_y2 = $midY+$linewidth; | ||
| 95 | } | ||
| 96 | else | ||
| 97 | { | ||
| 98 | $_y1 = $midY - $linewidth/2; | ||
| 99 | $_y2 = $midY + $linewidth/2; | ||
| 100 | } | ||
| 101 | $self->filled_box($gd, $x,$_y1,$newX,$_y2,$space_color,$space_color); | ||
| 102 | } | ||
| 103 | $x = $newX; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | 1; | ||
| 108 | |||
| 109 | __END__ |