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 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#define LONGUEUR 650
#define LARGEUR 300
//GdkPixmap *pixmap = NULL;;
gboolean Affichage(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
{
GdkColor rouge;
GdkColormap *colormap;
rouge.red=0xFFFF;
rouge.green=0;
rouge.blue=0;
printf("Affichage\n");
GdkGC *kontext = gdk_gc_new (widget->window);
colormap = gdk_drawable_get_colormap (widget->window);
gdk_colormap_alloc_color (colormap, &rouge, FALSE, FALSE);
gdk_gc_set_foreground (kontext, &rouge);
// pixmap = gdk_pixmap_new(widget->window,widget->allocation.width,widget->allocation.height,-1);
gdk_draw_rectangle(widget->window, kontext,TRUE,50,50,50,50);
gtk_widget_queue_draw(widget);
return FALSE;
}
static gboolean realisation(GtkWidget *dessin, GdkEventConfigure *event)
{
GdkColor rouge;
rouge.pixel=0;
rouge.red=0xFFFF;
rouge.green=0;
rouge.blue=0;
printf("realisation\n");
GdkGC *kontext = gdk_gc_new (dessin->window);
gdk_gc_set_foreground (kontext, &rouge);
/*
pixmap = gdk_pixmap_new(dessin->window,dessin->allocation.width,dessin->allocation.height,-1);
gdk_draw_rectangle(pixmap,kontext,TRUE,50,50,50,50);
gtk_widget_queue_draw(dessin);
*/
return FALSE;
}
void start_gtk(int argc,char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (win), 0);
gtk_window_set_title (GTK_WINDOW (win), "rectangle");
gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(win), LONGUEUR, LARGEUR);
g_signal_connect (win, "destroy", gtk_main_quit, NULL);
gtk_widget_realize (win);
GtkWidget *box = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (win), box);
GtkWidget *dessin = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA(dessin),200, 400);
gtk_container_add (GTK_CONTAINER (box), dessin);
g_signal_connect(G_OBJECT(dessin), "realize", G_CALLBACK(realisation), NULL);
g_signal_connect(G_OBJECT(dessin), "expose-event", G_CALLBACK(Affichage), NULL);
gtk_widget_show_all (win);
gtk_main ();
}
int main(int argc,char **argv)
{
start_gtk(argc,argv);
return 0;
} |
Partager