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
| #include <stdlib.h>
#include <gtk/gtk.h>
gboolean drawing_draw_CB (GtkWidget *drawing, cairo_t *cr, gpointer userdata)
{
g_print ("appel du callback drawing_draw_CB ();\n");
return FALSE;
}
void button_clicked_CB (GtkButton *button, GtkWidget *drawing)
{
g_print ("appel du callback button_clicked_CB ();\n");
gtk_widget_queue_draw_area (drawing, 10, 10, 50, 50);
}
gint
main (gint argc, gchar *argv[])
{
GtkWidget *window = NULL;
GtkWidget *box = NULL;
GtkWidget *drawing = NULL;
GtkWidget *button = NULL;
/* init gtk */
gtk_init(&argc, &argv);
/* Création de la fenêtre principale */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
gtk_container_add (GTK_CONTAINER (window), box);
/* Création du drawingarea */
drawing = gtk_drawing_area_new ();
gtk_widget_set_size_request (drawing, 200, 200);
g_signal_connect (G_OBJECT (drawing), "draw", G_CALLBACK (drawing_draw_CB), NULL);
gtk_box_pack_start (GTK_BOX (box), drawing, FALSE, FALSE, 4);
/* Création d'un bouton. À chaque clique on lance gtk_widget_queue_draw_area ();
* sur le drawing */
button = gtk_button_new_with_label ("Active queue_draw");
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (button_clicked_CB), drawing);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 4);
/* Signaux */
g_signal_connect (G_OBJECT(window) , "destroy", G_CALLBACK (gtk_main_quit) , NULL);
/* Affichage de la fenêtre */
gtk_widget_show_all (window);
gtk_main ();
return EXIT_SUCCESS;
} |
Partager