Re: PixbufWidget.pm



On 01/27/01 Jens Luedicke wrote:
I wasted my time to hack this little module. 
It's based on test.pl in GdkPixbuf/samples 

I hope someone likes it and/or uses it... 

Just a few quick comments...

sub new {
      shift;
      my ($file) = @_;

      die "Usage: PixbufWidget->new(\"file\")\;"
              if($file eq "");

You should check with a simple 'if $file', since it can be undef and
spew warnings.

      my $box = new Gtk::VBox(0,0);
      $box->set_app_paintable(1);

As the base widget for drawing Gtk::DrawingArea fits way better
and doesn't need the paintavle hack.

      my $pixbuf = new_from_file Gtk::Gdk::Pixbuf($file);

      $box->signal_connect('expose_event', sub {
              $pixbuf->render_to_drawable_alpha(
                      $box->window,
                      0, 0, 0, 0,
                      $pixbuf->get_width(), $pixbuf->get_height(),
                      0, 50, 0, 0, 0
              );

You should really draw only the exposed area:
$darea->signal_connect('expose_event', sub {
        my ($w, $e) = @_;
        my ($x, $y, $wi, $h) = @{$e->{'area'}};
        $w->window->draw_pixmap($gc, $bp, $x, $y, $x, $y, $wi, $h);
        return 0;
});

where $bp is a backing pixmap you create with $pixbuf->render_to_drawable().
Note that this example doesan't handle the alpha channel.
You should be able to do it even without the backing pixmap, with the
right params to render_to_drawable_alpha().

The GdkPixbuf/sample/test.pl code should really be rewritten to
match my own comments, I agree:-)

lupus

-- 
-----------------------------------------------------------------
lupus debian org                                     debian/rules
lupus ximian com                             Monkeys do it better




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]