# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-sub track_text
-{
- # Given a sequence list add this to
- # a Cairo::Context object.
-
- my ( $cr, # Cairo::Context object
- $text, # List of hashrefs { txt =>, x => y => }
- $color, # Color of features
- ) = @_;
-
- # Returns nothing.
-
- $cr->set_source_rgb( color_name2rgb( $color ) );
-
- my ( $txt );
-
- $cr->set_font_size( 10 );
-
- foreach $txt ( @{ $text } )
- {
- $cr->move_to( $txt->{ 'x' }, $txt->{ 'y' } );
- $cr->show_text( $txt->{ 'txt' } );
- $cr->stroke();
- }
-}
-
-
-sub track_feature
+sub draw_feature
{
# Given a list of features add these to
# a Cairo::Context object.
my ( $cr, # Cairo::Context object
$features, # List of features
- $color, # Color of features
) = @_;
# Returns nothing.
my ( $feature );
- $cr->set_source_rgb( color_name2rgb( $color ) );
-
- $cr->set_line_width( 5 );
-
foreach $feature ( @{ $features } )
{
- $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
- $cr->line_to( $feature->{ 'x2' }, $feature->{ 'y2' } );
- $cr->stroke;
- }
-}
-
+ $cr->set_source_rgb( @{ $feature->{ 'color' } } );
+
+ if ( $feature->{ 'type' } eq 'line' )
+ {
+ $cr->set_line_width( $feature->{ 'line_width' } );
+ $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
+ $cr->line_to( $feature->{ 'x2' }, $feature->{ 'y2' } );
+ }
+ elsif ( $feature->{ 'type' } eq 'rect' )
+ {
+ $cr->rectangle(
+ $feature->{ 'x1' },
+ $feature->{ 'y1' },
+ $feature->{ 'x2' } - $feature->{ 'x1' },
+ $feature->{ 'y2' } - $feature->{ 'y1' },
+ );
+
+ $cr->fill;
+ }
+ elsif ( $feature->{ 'type' } eq 'text' )
+ {
+ $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
+ $cr->set_font_size( $feature->{ 'font_size' } );
+ $cr->show_text( $feature->{ 'txt' } );
+ }
-sub color_name2rgb
-{
- my ( $color_name
- ) = @_;
-
- my ( %color_hash, $rgb );
-
- %color_hash = (
- 'green' => [ 0, 255, 0 ],
- );
-
- if ( exists $color_hash{ $color_name } ) {
- $rgb = $color_hash{ $color_name };
- } else {
- $rgb = [ 0, 0, 0 ];
+ $cr->stroke;
}
-
- return wantarray ? @{ $rgb } : $rgb;
}