in reply to Re: Perl-Gtk2::How to set a window background image.
in thread Perl-Gtk2::How to set a window background image.

zentara i need time to digest this ... I suposse, i must read a gtk2 tutorial in C, and then read seriusly the Gtk2-perl docs (maybe this weekend)...

For what i wanted to do, i finally use xpm images, preload them onto a pixmap, and then use the Gtk2::RcStyle for change my style everytime i want to...
But, this invitation to master the Gtk2, calls me like the Dark Power ... (Gtk2 for perl is the simplest (forgetting our problems) API for programming user graphics interfaces ... but now ... now Gtk2 will be as powerfull for us like programming over X11 with the Xlibs ... )

Forgetting my delirium; I've changed your "set_bg" version. It works fine, but i've simplified it:

sub set_bg{ my $pixbuff = Gtk2::Gdk::Pixbuf->new_from_file("1Zen16.png"); #set the new pixbuff in a vbox my $gdkwindow = $vbox1->window; my $gc = Gtk2::Gdk::GC->new ($gdkwindow, undef); $pixbuff->render_to_drawable($gdkwindow, $gc, 0,0,0,0,500,430,'normal',0,0); return FALSE; }
When you paint over a drawable, you only need to Sync the window, but this is a job for the Gtk2::main, no?

I'm anxious for the weekend to come!

turo

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Replies are listed 'Best First'.
Re^3: Perl-Gtk2::How to set a window background image.
by zentara (Cardinal) on Feb 15, 2006 at 13:04 UTC
    i need time to digest this

    I agree. There are some complications which set in, when you reset the background of a window that is already mapped to the screen. I noticed that if the dimensions of the render_to_drawable is not exactly the same as pixbuf dimensions, x-y errors would occur. These can be avoided by some logic to get the pixbuf x and y size, etc. But that brings up the problem of what happens if you resize the window? Will the image resize? How would you tile the image? etc.

    I was thinking about it last night, and the gtk c-libs developers probably didn't want to bloat the code with all the logic it would take to enable swappable background images. So we see it can be done, but the provided methods of using the styles and xpm files, is easier, and will probably work well for most applications.


    I'm not really a human, but I play one on earth. flash japh
      Hi! I think this is my first contribution hehe... I Got this code from the php cookbook, and converted it to Perl. It worked for me :)
      my $back_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file("apple.png"); my ($pixmap,$mask) = $back_pixbuf->render_pixmap_and_mask(255); my $style = $window->get_style(); $style=$style->copy(); $style->bg_pixmap("normal",$pixmap); $window->set_style($style);
      NOTE: apple.png NOT INCLUDED.