Code:
#include <gtk/gtk.h>
/*********************************************//**
*
*************************************************
*/
gboolean mygtk2_window_set_bgimage_from_file(
GtkWidget *window, /* the window to host the background image */
const gchar *bgfname, /* filename of image to be used as bgpixmap */
GdkPixbuf **bgpixbuf /* pixbuf to load from file & return to caller */
)
{
GdkPixmap *bgpixmap = NULL; /* pixmap to be created from pixbuf */
GtkStyle *style = NULL;
GError *error = NULL;
/* sanity check */
if ( NULL == window || NULL == bgfname || NULL == bgpixbuf ) {
return FALSE;
}
/* load image from file to bgpixbuf */
*bgpixbuf = gdk_pixbuf_new_from_file( bgfname, &error );
if ( error ) {
if ( GDK_PIXBUF_ERROR == error->domain ) {
g_print( "Pixbuf Related Error:\n" );
}
if ( G_FILE_ERROR == error->domain ) {
g_print( "File Error: Check file permissions and state:\n" );
}
g_printerr ("%s\n", error[0].message );
return FALSE;
}
/*
* Create bgpixmap from *bgpixbuf, apply it to a new gtk_style
* and finally apply the new style to the window.
*/
gdk_pixbuf_render_pixmap_and_mask( *bgpixbuf, &bgpixmap, NULL, 0 );
style = gtk_style_new();
style->bg_pixmap[0] = bgpixmap;
gtk_widget_set_style( window, style );
/* schedule window for redraw */
gtk_widget_show( window );
return TRUE;
}
/*************************************************//**
*
*****************************************************
*/
int main( int argc, char *argv[] )
{
GtkWidget *w; /* our main window */
GdkPixbuf *bgpixbuf; /* background image */
gtk_init( &argc, &argv );
/* create main window, set a background image & prepare some visuals */
w = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_default_size( GTK_WINDOW(w), 768, 383 );
gtk_window_set_position( GTK_WINDOW(w), GTK_WIN_POS_CENTER );
gtk_window_set_decorated( GTK_WINDOW(w), FALSE );
mygtk2_window_set_bgimage_from_file(
w,
"diablo/shield.png",
&bgpixbuf
);
/* create a vbox as the main container of the window */
GtkWidget *vbox = gtk_vbox_new( FALSE, 0 );
gtk_container_add( GTK_CONTAINER(w), vbox );
/* create an image for the logo and pack it as vbox's 1st child */
GtkWidget *imglogo = GTK_WIDGET(
gtk_image_new_from_file("diablo/logo_370x189.png")
);
gtk_box_pack_start( GTK_BOX(vbox), imglogo, FALSE, FALSE, 0 );
/* create an image for the blizzard stripe & pack it as vbox's last child */
GtkWidget *imgbliz = GTK_WIDGET(
gtk_image_new_from_file("diablo/bliz_768x41.png")
);
gtk_box_pack_end( GTK_BOX(vbox), imgbliz, FALSE, FALSE, 0 );
/* create an hbox to host the play-image and
pack it as vbox's one-before-the-last child */
GtkWidget *hboxplay = gtk_hbox_new( FALSE, 0 );
gtk_box_pack_end( GTK_BOX(vbox), hboxplay, FALSE, FALSE, 0 );
/* create the play-image, wrap it inside an event-box
and make invisible the window of the event-box */
GtkWidget *imgplay = GTK_WIDGET(
gtk_image_new_from_file("diablo/play.png")
);
GtkWidget *ebplay = gtk_event_box_new();
gtk_container_add( GTK_CONTAINER(ebplay), imgplay );
gtk_event_box_set_visible_window( GTK_EVENT_BOX(ebplay), FALSE );
/* pack the event-box as hbox's last (and only) child */
gtk_box_pack_end( GTK_BOX(hboxplay), ebplay, FALSE, FALSE, 0 );
/* connect signal handlers for the main window */
g_signal_connect(
G_OBJECT(w),
"delete-event", G_CALLBACK(gtk_main_quit),
NULL
);
g_signal_connect(
G_OBJECT(w),
"destroy",
G_CALLBACK(gtk_main_quit),
NULL
);
/* connect signal handlers for the event-box that holds the play-image*/
g_signal_connect(
G_OBJECT( ebplay ),
"button-release-event",
G_CALLBACK( gtk_main_quit ),
NULL
);
/* all set, go */
gtk_widget_show_all( w );
gtk_main();
g_object_unref( bgpixbuf );
return 0;
}
I've also attached a .7z file, that additionally contains the pictures and a Win32 executable (to close the window, click on the play-image with either mouse-button).