1 package Maasha::BBrowser::Draw;
3 # Copyright (C) 2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Routines for creating Biopieces Browser graphics using Cairo and Pango.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
37 use vars qw( @ISA @EXPORT );
39 @ISA = qw( Exporter );
42 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
47 # Martin A. Hansen, November 2009
49 # Given a list of features add these to
50 # a Cairo::Context object.
52 my ( $cr, # Cairo::Context object
53 $features, # List of features
60 foreach $feature ( @{ $features } )
62 $cr->set_source_rgb( @{ $feature->{ 'color' } } );
64 if ( $feature->{ 'type' } eq 'line' )
66 $cr->set_line_width( $feature->{ 'line_width' } );
67 $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
68 $cr->line_to( $feature->{ 'x2' }, $feature->{ 'y2' } );
70 elsif ( $feature->{ 'type' } eq 'rect' )
75 $feature->{ 'x2' } - $feature->{ 'x1' },
76 $feature->{ 'y2' } - $feature->{ 'y1' },
81 elsif ( $feature->{ 'type' } eq 'text' )
83 $cr->move_to( $feature->{ 'x1' }, $feature->{ 'y1' } );
84 $cr->set_font_size( $feature->{ 'font_size' } );
85 $cr->show_text( $feature->{ 'txt' } );
95 # Martin A. Hansen, November 2009.
97 # Given a color number, pick that color from
98 # the color palette and return.
100 my ( $i, # color number
105 my ( $palette, $color );
124 $color = $palette->[ $i ];
126 map { $_ /= 255 } @{ $color };
134 # Martin A. Hansen, October 2009.
136 # Prints a Cairo::Surface object to a PNG file.
138 my ( $surface, # Cairo::Surface object
139 $file, # path to PNG file
144 $surface->write_to_png( $file );
148 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<