I am making a Gtk2 program that renders a pre-calculated data heatmap image to a GtkDrawingArea. The procedure is generally like this:
- generate heatmap image on a Cairo image surface;
- connect expose event of the GtkDrawingArea;
- in expose callback, following functions are called:
in first function, clear previous drawing to plain grey color:
cairo_t* cr = gdk_cairo_create(widget->window);
cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
cairo_paint(cr);
cairo_destroy(cr);
in the second function, paint the pre-rendered image:
cairo_t* cr = gdk_cairo_create(widget->window);
cairo_set_source_surface(cr, buffer_surface, 0, 0);
cairo_paint(cr);
cairo_destroy(cr);
in 3rd function, plot some vector indications:
cairo_t* cr = gdk_cairo_create(widget->window);
cairo_move_to(cr, xxx, xxx);
cairo_line_to(cr, xxx, xxx);
cairo_line_to(cr, xxx, xxx);
cairo_line_to(cr, xxx, xxx);
......
cairo_stroke(cr);
cairo_destroy(cr);
However, only the 1st and 3rd function has effect, the image painting in 2nd function is not shown: resultant GtkDrawingArea only have mid-grey background with black lines.
I am sure the source image surface is filled with content, as I have exported it to png file and it does have content. Why it is not showing in GUI?