1package Bio::Graphics::Glyph::repeating_shape;
2# DAS-compatible package to use for drawing a line of repeating shapes
3
4use strict;
5use base qw(Bio::Graphics::Glyph::generic);
6
7sub default_width
8{
9  return 10;
10}
11
12sub default_interval
13{
14  return 10;
15}
16
17sub connector { 'none' }
18
19sub draw_component {
20  my $self = shift;
21  my $gd = shift;
22  my $fg = $self->fgcolor;
23
24  my $width = defined $self->option('width') ? $self->option('width') : $self->default_width;
25  my $interval = defined $self->option('interval') ? $self->option('interval') : $self->default_interval;
26
27  # find the center and vertices
28  my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_);
29
30  my $bWidth = $x2-$x1;
31
32  if ($bWidth < $width)
33  {
34    $self->draw_repeating_shape($gd,$x1,$y1,$x2,$y2,$fg);
35    return;
36  }
37
38  if ($bWidth < $width+2*$interval)
39  {
40    my $leftoverInterval = $bWidth - $width;
41    my $halfInt = $leftoverInterval/2;
42    $halfInt = 0 unless $interval;
43
44    $gd->line($x1,$y2,$x1+$halfInt,$y2,$fg);
45    $self->draw_repeating_shape($gd,$x1+$halfInt,$y1,$x2-$halfInt,$y2,$fg);
46    $gd->line($x2-$halfInt,$y2,$x2,$y2,$fg);
47    return;
48  }
49
50  my $count = int ($bWidth / ($width+$interval));
51  my $leftoverInterval = $bWidth % ($width+$interval)+$interval;
52
53  my $halfInt = $leftoverInterval/2;
54  $halfInt = 0 unless $interval;
55  $gd->line($x1,$y2,$x1+$halfInt,$y2,$fg);
56  foreach (my $i=1; $i<=$count; $i++)
57  {
58    my $shapeStart = $x1 + $halfInt + ($i-1)*($width+$interval);
59    $self->draw_repeating_shape($gd,$shapeStart,$y1,$shapeStart+$width,$y2,$fg);
60    if ($i < $count)
61    {
62      $gd->line($shapeStart+$width,$y2,$shapeStart+$width+$interval,$y2,$fg);
63    }
64  }
65  $gd->line($x2-$halfInt,$y2,$x2,$y2,$fg);
66}
67
68sub draw_repeating_shape
69{
70	warn "Subclasses must implement 'draw_repeating_shape'!\n";
71}
72
731;
74
75__END__
76
77=head1 NAME
78
79Bio::Graphics::Glyph::repeating_shape - A glyph that draws the same shape repeatedly.
80
81=head1 SYNOPSIS
82
83  See L<Bio::Graphics::Panel> and L<Bio::Graphics::Glyph>.
84
85=head1 DESCRIPTION
86
87This glyph is a generic superclass for drawing the same shape repeatedly.
88
89=head2 OPTIONS
90
91In addition to the common options, the following glyph-specific
92options are recognized:
93
94  Option      Description                  Default
95  ------      -----------                  -------
96
97  -width      Width of one tooth            10
98
99  -interval   Interval between teeth        10
100
101=head1 BUGS
102
103Please report them.
104
105=head1 SEE ALSO
106
107L<Bio::Graphics::Panel>,
108L<Bio::Graphics::Glyph>,
109L<Bio::Graphics::Glyph::arrow>,
110L<Bio::Graphics::Glyph::cds>,
111L<Bio::Graphics::Glyph::crossbox>,
112L<Bio::Graphics::Glyph::diamond>,
113L<Bio::Graphics::Glyph::dna>,
114L<Bio::Graphics::Glyph::dot>,
115L<Bio::Graphics::Glyph::ellipse>,
116L<Bio::Graphics::Glyph::extending_arrow>,
117L<Bio::Graphics::Glyph::generic>,
118L<Bio::Graphics::Glyph::graded_segments>,
119L<Bio::Graphics::Glyph::heterogeneous_segments>,
120L<Bio::Graphics::Glyph::line>,
121L<Bio::Graphics::Glyph::pinsertion>,
122L<Bio::Graphics::Glyph::primers>,
123L<Bio::Graphics::Glyph::rndrect>,
124L<Bio::Graphics::Glyph::segments>,
125L<Bio::Graphics::Glyph::ruler_arrow>,
126L<Bio::Graphics::Glyph::toomany>,
127L<Bio::Graphics::Glyph::transcript>,
128L<Bio::Graphics::Glyph::transcript2>,
129L<Bio::Graphics::Glyph::translation>,
130L<Bio::Graphics::Glyph::triangle>,
131L<Bio::DB::GFF>,
132L<Bio::SeqI>,
133L<Bio::SeqFeatureI>,
134L<Bio::Das>,
135L<GD>
136
137=head1 AUTHOR
138
139Vsevolod (Simon) Ilyushchenko E<lt>simonf@cshl.eduE<gt>.
140
141Copyright (c) 2004 Cold Spring Harbor Laboratory
142
143This library is free software; you can redistribute it and/or modify
144it under the same terms as Perl itself.  See DISCLAIMER.txt for
145disclaimers of warranty.
146
147=cut
148