Bonjour,
Je programme sous gdk et je n'arrive pas a changer la couleur des lignes.J'en ai 10 differentes a faire donc un peu de couleur c'est pratique.
Merci de votre aide.Code:#include <pango/pango.h> #include <gtk/gtk.h> #include <stdlib.h> #include <stdio.h> void cb_expose_event (GtkWidget *, gpointer); int main (int argc, char **argv) { GtkWidget *p_main_window = NULL; GtkWidget *p_drawing_area = NULL; gtk_init (&argc, &argv); p_main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(p_main_window), 640, 480); p_drawing_area = gtk_drawing_area_new (); g_signal_connect (G_OBJECT (p_drawing_area), "expose_event",G_CALLBACK (cb_expose_event), NULL); gtk_container_add (GTK_CONTAINER (p_main_window), p_drawing_area); gtk_widget_show_all (p_main_window); gtk_main (); return 0; } void cb_expose_event (GtkWidget *p_widget, gpointer user_data) { GdkGC *gc; GdkPoint points[3]; GdkPoint points2[3]; GdkColor color; color.red=65000; color.green=0; color.blue=100; // points = (GdkPoint*) malloc(sizeof( GdkPoint ) ) ; // if ( points != NULL ) // { // points->x=(GdkPoint *)malloc(3); // points->y=(GdkPoint *)malloc(3); // } // points->x=0; // points->y=0; points[0].x=0; points[0].y=0; points[1].x=200; points[1].y=200; points[2].x=200; points[2].y=300; points2[0].x=0; points2[0].y=0; points2[1].x=200; points2[1].y=300; points2[2].x=100; points2[2].y=300; gc=p_widget->style->fg_gc[GTK_WIDGET_STATE (p_widget)]; gdk_gc_set_rgb_bg_color(gc,&color); PangoContext *p_context = NULL; PangoLayout *p_layout = NULL; p_context = gtk_widget_get_pango_context (p_widget); p_layout = pango_layout_new (p_context); pango_layout_set_text (p_layout, "Hello World !", -1); gdk_draw_layout (p_widget->window,p_widget->style->fg_gc[GTK_WIDGET_STATE (p_widget)],0,0,p_layout); // gdk_draw_line(p_widget->window,gc,(points[0].x),(points[0].y),(points[1].x),(points[1].y)); // gdk_draw_line(p_widget->window,gc,0,0,200,200); gdk_draw_lines(p_widget->window,gc,points,3); gdk_draw_lines(p_widget->window,gc,points2,3); g_object_unref (p_layout); (void)user_data; }
-----