]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_perl/Maasha/KISS/Draw.pm
www relayout
[biopieces.git] / code_perl / Maasha / KISS / Draw.pm
index af48ac1b75ae40ffaa2c9025b2ff9dad6fd804d9..e9ae40e5f167995e29079d080644aa8a8f799798 100644 (file)
@@ -42,78 +42,49 @@ 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.
 
     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;
 }