GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 7:55 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Resize Gtkimage when resize window (Gnome screensaver)
PostPosted: Sat Aug 29, 2009 2:09 am 
Offline

Joined: Fri Aug 28, 2009 3:58 pm
Posts: 4
Hello, I'm programming my first GTK+ app, is a Gnome screen-saver. I will try to explain my problem but I think that you will understand it better if you see a picture of my program.

Image

The fishes are animated gif and the background is a .png image. When I resize the window by clicking the "maximize window" title bar button the background image keeps the same size.

Image

How can solve it? What is the event name of click that button? The background image have to be fit to the window border. This is the source code of my app.

[code=]
#include <gtk/gtk.h>
#include <glade/glade.h>
//#include "callbacks.h"
//#define GLADE_FILE "src/gquarium.glade"

int
main (int argc, char *argv[])
{
/* Declare Widgets */
GtkWidget *window;
GtkWidget *fixed_layout;
GtkWidget *image_bg;
GtkWidget *image_fish_1;
GtkWidget *image_fish_2;
GtkWidget *image_fish_3;
GtkWidget *image_fish_4;

/* Initialize */
gtk_init(&argc, &argv);

/* Build window Widget */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(window), "Gquarium");
gtk_window_set_default_icon_from_file ("gquarium_icon.png", NULL);
gtk_widget_set_size_request(window, 1024, 768);

/* Build fixed_layout */
fixed_layout = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed_layout);

/* Build images */
image_bg = gtk_image_new_from_file(argv[1]);
if (image_bg == NULL){
printf("Could not open \"%s\"\n", argv[1]);
return 1;
}
gtk_fixed_put(GTK_FIXED(fixed_layout), image_bg, 0, 0);

image_fish_1 = gtk_image_new_from_file(argv[2]);
if (image_fish_1 == NULL){
printf("Could not open \"%s\"\n", argv[2]);
return 1;
}
gtk_fixed_put(GTK_FIXED(fixed_layout), image_fish_1, 100, 100);

image_fish_2 = gtk_image_new_from_file(argv[3]);
if (image_fish_2 == NULL){
printf("Could not open \"%s\"\n", argv[3]);
return 1;
}
gtk_fixed_put(GTK_FIXED(fixed_layout), image_fish_2, 400, 400);

image_fish_3 = gtk_image_new_from_file(argv[4]);
if (image_fish_3 == NULL){
printf("Could not open\"%s\"\n", argv[4]);
return 1;
}
gtk_fixed_put(GTK_FIXED(fixed_layout), image_fish_3, 250, 250);

image_fish_4 = gtk_image_new_from_file(argv[5]);
if (image_fish_4 == NULL){
printf("Could not open\"%s\"\n", argv[5]);
return 1;
}
gtk_fixed_put(GTK_FIXED(fixed_layout), image_fish_4, 250, 550);

/* Attach standard event handlers */
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));

//g_signal_connect(G_OBJECT(window), "event",
// G_CALLBACK(resize_window), G_OBJECT(window));

/*Show the window*/
gtk_widget_show_all(window);

/*Moving the fish*/

/* Enter the event loop */
gtk_main();
return 0;
}
[/code]

NOTE: remember that the gnome screen-saver can't use keyboard events or mouse events I only can use window manager or xwindow system events.

I'm waiting for your help. Thanks and sorry for my little English.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 30, 2009 9:35 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

Signal that will be triggered when window is resized is "configure-event". You'll probably need to scale your images to get them fit into your window.

Tadej


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 30, 2009 4:13 pm 
Offline

Joined: Fri Aug 28, 2009 3:58 pm
Posts: 4
Thanks for the help, I will try to resolve it this week and I will let you know the results of that.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 13, 2009 11:27 am 
Offline
GTK+ Guru

Joined: Thu Jun 21, 2007 1:52 pm
Posts: 198
Location: Wilkes Barre Pa
Nice ill be keeping an eye on your project. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group