Re: Background image in a window
- From: "Tadej Borovšak" <tadeboro gmail com>
- To: gtk-list gnome org
- Subject: Re: Background image in a window
- Date: Sun, 7 Dec 2008 19:11:01 +0100
Hi.
I was dealing with a similar problem not so long ago and came up with
this piece of code that does what you want (plus some more, so please
ignore the commented sections - the main point of the example is the
usage of expose-event event).
----------------
#include <gtk/gtk.h>
static gboolean
cb_expose( GtkWidget *widget,
GdkEventExpose *event,
GdkPixbuf *buf )
{
gdk_draw_pixbuf( widget->window, NULL, buf, 0, 0, 0, 0, -1, -1,
GDK_RGB_DITHER_NONE, 0, 0 );
return FALSE;
}
int
main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
GdkPixbuf *buf;
GdkPixmap *map;
GdkBitmap *mask;
gtk_init (&argc, &argv);
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_container_set_border_width( GTK_CONTAINER( window ), 20 );
g_signal_connect( G_OBJECT( window ), "destroy",
G_CALLBACK( gtk_main_quit ), NULL );
/*gtk_window_set_default_size( GTK_WINDOW( window ), 300, 300 );
gtk_window_set_decorated( GTK_WINDOW( window ), FALSE );
gtk_widget_realize( window );*/
buf = gdk_pixbuf_new_from_file( "test.png", NULL );
/*gdk_pixbuf_render_pixmap_and_mask( buf, &map, &mask, 10 );
gdk_window_shape_combine_mask( window->window, mask, 0, 0 );*/
gtk_widget_set_app_paintable( window, TRUE );
g_signal_connect( G_OBJECT( window ), "expose-event",
G_CALLBACK( cb_expose ), buf );
button = gtk_button_new_with_label( "WOW" );
gtk_container_add( GTK_CONTAINER( window ), button );
gtk_widget_show_all( window );
gtk_main();
return 0;
}
--------------------
2008/12/6 zentara <zentara1 sbcglobal net>:
> On Sat, 6 Dec 2008 09:55:55 +0530
> "Harinandan S" <harinandans gmail com> wrote:
>
>>Hi All,
>>
>>How to set background image to a window? In my window there are few buttons.
>>I want to set background image to the entire window? I googled but couldnt
>>find much help.
>>
>>Regards,
>>Harinandan S
> Hi,
> I use Perl and it was tough to figure that one out, because of the theme
> engine, and the need to override it. If you use a pixmap based theme, it
> is tenacious.
>
> However, if you want a Perl clue on how to do it, see renegadex's reply
> at the bottom of
> http://perlmonks.org?node_id=530061
>
> the basics is to get the current style of the window, and reset the bg_pixmap
>
> my $back_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file($image);
> 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);
>
> it should be easy to convert to c.
>
>
> Goodluck,
> zentara
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/Remember_How_Lucky_You_Are.html
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
--
Tadej Borovšak
00386 (0)40 613 131
tadeboro gmail com
tadej borovsak gmail com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]