1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <stdlib.h>
#include <gtk/gtk.h>
typedef struct s_display
{
GtkWidget *pWindow;
GtkWidget *pTable;
GtkWidget *pButton[5];
GdkPixbuf *pixbuf;
} t_display;
t_display win;
void resize_pixbuf(GtkWidget *window, GdkEventExpose *event, gpointer user_data)
{
static gint width = 1;
static gint height = 1;
if ((window->allocation.width != width) || (window->allocation.height != height))
{
g_object_unref(win.pixbuf);
width = window->allocation.width;
height = window->allocation.height;
printf("width %d height %d\n", width, height);
win.pixbuf = gdk_pixbuf_new_from_file("./image.jpg", NULL);
win.pixbuf = gdk_pixbuf_scale_simple(win.pixbuf, width / 3, height / 3, GDK_INTERP_BILINEAR);
gtk_widget_destroy(win.pButton[4]);
win.pButton[4] = gtk_image_new_from_pixbuf(win.pixbuf);
gtk_table_attach_defaults(GTK_TABLE(win.pTable), win.pButton[4], 2, 8, 1, 5);
}
gtk_widget_show_all(window);
}
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
// creation de la window
win.pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(win.pWindow), 500, 300);
gtk_window_set_title(GTK_WINDOW(win.pWindow), "Epicam");
// Creation et insertion de la table dans la window
win.pTable = gtk_table_new(10, 10, TRUE);
gtk_container_add(GTK_CONTAINER(win.pWindow), GTK_WIDGET(win.pTable));
// creation des boutons
win.pButton[0]= gtk_button_new_with_label("Module 1");
win.pButton[1]= gtk_button_new_with_label("Module 2");
win.pButton[2]= gtk_button_new_with_label("Module 3");
win.pButton[3]= gtk_button_new_with_label("Preferences");
// ajout du pixbuf dans la table
win.pixbuf = gdk_pixbuf_new_from_file("./image.jpg", NULL);
win.pixbuf = gdk_pixbuf_scale_simple(win.pixbuf, 300, 100, GDK_INTERP_BILINEAR);
win.pButton[4] = gtk_image_new_from_pixbuf(win.pixbuf);
gtk_table_attach_defaults(GTK_TABLE(win.pTable), win.pButton[4], 2, 8, 1, 5);
// ajout des boutons dans la table
gtk_table_attach(GTK_TABLE(win.pTable), win.pButton[0], 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(win.pTable), win.pButton[1], 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(win.pTable), win.pButton[2], 8, 9, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(win.pTable), win.pButton[3], 8, 9, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
g_signal_connect(G_OBJECT(win.pWindow), "size-request", G_CALLBACK(resize_pixbuf), &win);
g_signal_connect(G_OBJECT(win.pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(win.pWindow);
gtk_main();
return EXIT_SUCCESS;
} |
Partager