Bonjour,

J'aimerais savoir comment dessiner du texte avec GTK.
Je n'ai pas trouvé grand chose là dessus.
Bien sur il y a la fonction gdk_draw_text () mais je n'ai pas vu d'exemples d'utilisation.
Certain disent qu'il faut utiliser la librairie Pango pour dessiner du texte mais là encore trés peu d'information.

Voici une application ultra simple:
Une fenêtre et une drawing area avec un fond blanc:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#define WIDTH 500
#define HEIGHT 300
 
 
static GdkPixmap *pixmap = NULL;
 
void refresh_cb(GtkWidget *draw_area, gpointer data)
{
   if (pixmap == NULL)
   {
    pixmap = gdk_pixmap_new(draw_area->window, 500, HEIGHT, -1);
    gdk_draw_rectangle(pixmap, draw_area->style->white_gc, TRUE, 0, 0, WIDTH, HEIGHT);
   }
   gdk_draw_pixmap(draw_area->window, draw_area->style->black_gc, pixmap, 0,0,0,0, WIDTH, HEIGHT);
}
 
 
int main(int argc, char **argv)
{
    GtkWidget *pWin;
    GtkWidget *pDrawArea;
    GtkWidget *pVBox;
    gtk_init(&argc, &argv);
 
 
    pWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(pWin), WIDTH, HEIGHT);
    g_signal_connect(G_OBJECT(pWin), "destroy", G_CALLBACK(gtk_main_quit), NULL);
 
    pVBox = gtk_vbox_new(FALSE, 4);
    gtk_container_add(GTK_CONTAINER(pWin), pVBox);
    pDrawArea = gtk_drawing_area_new ();
    gtk_widget_set_size_request (pDrawArea, WIDTH, HEIGHT);
    g_signal_connect(G_OBJECT(pDrawArea),"event",G_CALLBACK(refresh_cb), NULL);
    gtk_box_pack_start(GTK_BOX(pVBox), pDrawArea, TRUE, TRUE, 0);
 
    gtk_window_set_title(GTK_WINDOW(pWin), "GTK-Win");
    gtk_widget_show_all(pWin);
    gtk_main();
    return EXIT_SUCCESS;
}
Est ce que quelqu'un pourrait me montrer comment utiliser gdk_draw_text () afin d'afficher un texte (hello world par ex) au milieu de la fenêtre ?

D'avance merci