[cairo] cairo/gdk + clipping
james at jwm-art.net
Wed Aug 18 03:46:09 PDT 2010
I'm having some difficulty with understanding cairo and gtk and clipping.
I need to draw rectangles that appear and disappear over time. I've
setup a gtk timeout which calls gtk_queue_draw on the window and the
drawable in use by cairo as the surface - this provokes my expose
event handler to be called. Here I call gdk_cairo_create, do my
drawing, and then cairo_destroy.
I asked about this on gtk-app-devel and had some responses but still
seem to be stuck with erasure of what has been previously drawn each
time something new is drawn (ie a new rectangle appears after some
period of time has elapsed, drawing it erases all past rectangles).
The solution seemed to be clipping. So I clip_preserve the rectangle
and then fill it, but still everything else is erased.
It was suggested I could dispense with the timeout. I don't think so,
as the rectangles are dictated by another thread which only provides
the dimensions of a rectangle when it should appear/disappear (getting
this information in advance is not possible).
My first working approach was to store in a list all the rectangles
current in existence (and remove them when the disappear). Then on
each call to the expose event handler the surface background and every
rectangle would be drawn. With the timeout set at 33ms, and on average
200 rectangles appearing/disappearing per second, this approach proved
too expensive of CPU resources. I decided then to try GDK and
performance was a *lot* better and satisfactory, but then I discovered
the GDK drawing and GDKGC functions are deprecated, hence a return to
Can anyone advise here please?
More information about the cairo