]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/KISS/Draw.pm
www relayout
[biopieces.git] / code_perl / Maasha / KISS / Draw.pm
index 90ed4f66d53a95a6e9d0650a0a1fae74b78b0041..e9ae40e5f167995e29079d080644aa8a8f799798 100644 (file)
@@ -42,41 +42,13 @@ use vars qw( @ISA @EXPORT );
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-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.
@@ -85,16 +57,28 @@ sub track_feature
 
     foreach $feature ( @{ $features } )
     {
-        $cr->set_source_rgb( color_name2rgb( $feature->{ 'color' } ) );
-        $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
+        $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' } );
         }
@@ -104,30 +88,6 @@ sub track_feature
 }
 
 
-sub color_name2rgb
-{
-    my ( $color_name
-       ) = @_;
-
-    my ( %color_hash, $rgb );
-
-    %color_hash = (
-        'black' => [   0,   0,   0 ],
-        'red'   => [ 255,   0,   0 ],
-        'green' => [   0, 255,   0 ],
-        'blue'  => [   0,   0, 255 ],
-    );
-
-    if ( exists $color_hash{ $color_name } ) {
-        $rgb = $color_hash{ $color_name };
-    } else {
-        $rgb = [ 0, 0, 0 ];
-    }
-
-    return wantarray ? @{ $rgb } : $rgb;
-}
-
-
 sub file_png
 {
     # Martin A. Hansen, October 2009.