In the Reference Manual of GtkDrawingArea, it says
Draw signals are normally delivered when a drawing area first comes onscreen, or when it’s covered by another window and then uncovered. You can also force an expose event by adding to the “damage region” of the drawing area’s window;
gtk_widget_queue_draw_area()
andgdk_window_invalidate_rect()
are equally good ways to do this. You’ll then get a draw signal for the invalid region.
So how could I get the invalid region in the handler of the draw signal? Is it the clip region?
This is answered in the documentation for the draw
signal itself:
The signal handler will get a
cr
with a clip region already set to the widget's dirty region, i.e. to the area that needs repainting. Complicated widgets that want to avoid redrawing themselves completely can get the full extents of the clip region withgdk_cairo_get_clip_rectangle()
, or they can get a finer-grained representation of the dirty region withcairo_copy_clip_rectangle_list()
.
gdk_cairo_get_clip_rectangle()
is a wrapper around cairo_clip_extents()
that uses integer instead of floating-point coordinates, so you can also use the latter function if you want floating-point coordinates instead.