| 1 | package Bio::Graphics::Glyph::two_bolts; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw(Bio::Graphics::Glyph::generic); | ||
| 5 | |||
| 6 | sub default_bolt_height | ||
| 7 | { | ||
| 8 | return 10; | ||
| 9 | } | ||
| 10 | |||
| 11 | sub default_bolt_length | ||
| 12 | { | ||
| 13 | return 20; | ||
| 14 | } | ||
| 15 | |||
| 16 | sub default_remainder_length | ||
| 17 | { | ||
| 18 | return 10; | ||
| 19 | } | ||
| 20 | |||
| 21 | sub default_bolt_color | ||
| 22 | { | ||
| 23 | return 'red'; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub draw_component { | ||
| 27 | my $self = shift; | ||
| 28 | my $gd = shift; | ||
| 29 | my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_); | ||
| 30 | |||
| 31 | my $fg = $self->fgcolor; | ||
| 32 | |||
| 33 | my $midY1 = $y1+($y2-$y1) / 3; | ||
| 34 | my $midY2 = $y1 + 2*($y2-$y1) / 3; | ||
| 35 | |||
| 36 | my $bolt_color = defined $self->option('bolt_color') ? $self->option('bolt_color') : $self->default_bolt_color(); | ||
| 37 | $bolt_color = $self->factory->translate_color($bolt_color); | ||
| 38 | |||
| 39 | my $bolt_height = defined $self->option('bolt_height') ? $self->option('bolt_height') : $self->default_bolt_height(); | ||
| 40 | my $bolt_length = defined $self->option('bolt_length') ? $self->option('bolt_length') : $self->default_bolt_length(); | ||
| 41 | my $remainder_length = defined $self->option('remainder_length') ? $self->option('remaindert_length') : $self->default_remainder_length(); | ||
| 42 | |||
| 43 | if ($x2-$x1 < $bolt_length+$remainder_length) | ||
| 44 | { | ||
| 45 | $gd->line($x1, $y1, $x2, $y2, $bolt_color); | ||
| 46 | return; | ||
| 47 | } | ||
| 48 | |||
| 49 | my $bolt_start = $x2-$bolt_length-$remainder_length; | ||
| 50 | my $step = $bolt_length / 8; | ||
| 51 | my $shift = $bolt_height/2; | ||
| 52 | $gd->line($x1, $midY1, $bolt_start, $midY1, $fg); | ||
| 53 | $self->draw_bolt($gd, $bolt_start, $step, $midY1, $shift, $bolt_color); | ||
| 54 | $gd->line($x2-$remainder_length, $midY1, $x2, $midY1, $fg); | ||
| 55 | |||
| 56 | $bolt_start = $x1+$remainder_length; | ||
| 57 | $gd->line($x1, $midY2, $bolt_start, $midY2, $fg); | ||
| 58 | $self->draw_bolt($gd, $bolt_start, $step, $midY2, $shift, $bolt_color); | ||
| 59 | $gd->line($x1+$bolt_length+$remainder_length, $midY2, $x2, $midY2, $fg); | ||
| 60 | |||
| 61 | |||
| 62 | } | ||
| 63 | |||
| 64 | sub draw_bolt | ||
| 65 | { | ||
| 66 | my ($self, $gd, $bolt_start, $step, $y, $shift, $bolt_color) = @_; | ||
| 67 | $gd->line($bolt_start, $y, $bolt_start+$step, $y-$shift, $bolt_color); | ||
| 68 | $gd->line($bolt_start+$step, $y-$shift, $bolt_start+3*$step, $y+$shift, $bolt_color); | ||
| 69 | $gd->line($bolt_start+3*$step, $y+$shift, $bolt_start+5*$step, $y-$shift, $bolt_color); | ||
| 70 | $gd->line($bolt_start+5*$step, $y-$shift, $bolt_start+7*$step, $y+$shift, $bolt_color); | ||
| 71 | $gd->line($bolt_start+7*$step, $y+$shift, $bolt_start+8*$step, $y, $bolt_color); | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | 1; | ||
| 76 | |||
| 77 | __END__ |