Solak has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use constant WIDTH => 1000; use constant HEIGHT => 100; use constant SPEED => 15; use Cairo; use Glib qw(TRUE FALSE); use Gtk2 -init; use Gtk2::Pango; my ($text,$ticks); sub draw_text { my ($cr) = @_; my $layout = Gtk2::Pango::Cairo::create_layout($cr); $cr->push_group; $layout->set_text($text); my $desc = Gtk2::Pango::FontDescription -> from_string("Sans Bold +57"); $layout -> set_font_description($desc); $layout->set_alignment("PANGO_ALIGN_LEFT"); Gtk2::Pango::Cairo::update_layout($cr, $layout); my @size = $layout->get_pixel_size; $cr -> translate(-($ticks*SPEED)%$size[0],0); $cr->set_source_rgb(1.0,1.0,1.0); $cr->fill(); $cr -> set_source_rgb(0.0,0.0,0.0); my $count = int(WIDTH/$size[0]); $cr->translate(-$size[0]*2,0); for(my $i = 0; $i<=$count+1; $i++){ $cr->translate($size[0],0); Gtk2::Pango::Cairo::show_layout($cr,$layout); } $cr->pop_group_to_source; $cr->paint; undef $cr; undef $layout; } my $window = Gtk2::Window->new(); $window -> signal_connect(delete_event => sub { Gtk2 -> main_quit(); }); my $area = Gtk2::DrawingArea -> new(); sub draw { my $widget = $area; my $cr = Gtk2::Gdk::Cairo::Context -> create($widget->window()); $cr->rectangle(0,0,WIDTH,HEIGHT); draw_text($cr,$ticks); } sub timer { $ticks ++; draw(); return 1; } $text = 'Please specify your input file'; if($ARGV[0]){ open(INPUT_FILE, "$ARGV[0]"); $text = <INPUT_FILE>; } $ticks = 0; $window -> set_default_size(WIDTH,HEIGHT); $window -> add($area); $window->show_all(); my $timer = Glib::Timeout->add(1000/24,\&timer,'',); Gtk2->main();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bad, bad memory leaks in simple script
by bruceb3 (Pilgrim) on Sep 08, 2007 at 05:12 UTC | |
|
Re: Bad, bad memory leaks in simple script
by erroneousBollock (Curate) on Sep 08, 2007 at 04:04 UTC | |
|
Re: Bad, bad memory leaks in simple script [solved]
by zentara (Cardinal) on Sep 08, 2007 at 14:38 UTC | |
|
Re: Bad, bad memory leaks in simple script
by Solak (Novice) on Sep 08, 2007 at 13:42 UTC |