[cairo] Best way to set clipping? (was Re: Dealing with drawingArea
update (refresh) for multiple drawings.)
ibaldo at adinet.com.uy
Tue Aug 29 18:33:40 PDT 2006
The code that Gustavo uses is the same as suggested in
and is exactly the same as I am using (maybe we are based from the same
Are you sure that it is better to do it with gdk_cairo_region? Can
someone else confirm too? Does Cairo perform better with it?
I tried it and it "seems" to be faster or better looking but I have done
a subjective benchmark, no actual numbers just seeing it with my eyes
live while I was dragging a window in front of my application.
Maybe we could contact the author of the tutorial above and maybe he
would like to change it, it could benefit someone in the future.
BTW, the documentation for gdk_cairo_* doesn't say much, this stuff
should have an example on the documentation using one of this methods
(the best of them), and maybe showing how to draw a simple circle while
at it. I can file a suggestion on Bugzilla for this (no, I don't want to
learn Docbook and good English writing to be able to fix it myself and
submit a patch, I think it is just overkill for a simple user to do all
that... though I would write the text that should go in there and
someone translate it to Docbook and submit in CVS/SVN).
El 25/08/06 23:24, Carlo Wood escribió:
>On Fri, Aug 25, 2006 at 05:35:07PM -0300, Gustavo Sikora wrote:
>>Some code of what I'm doing:
>>gboolean expose_event_callback (GtkWidget *widget, GdkEventExpose *event)
>> cairo_t *cr;
>> /* get a cairo_t */
>> cr = gdk_cairo_create (widget->window);
>> cairo_rectangle (cr,
>> event->area.x, event->area.y,
>> event->area.width, event->area.height);
>> cairo_clip (cr);
>> cairo_destroy (cr);
>> return TRUE;
>Note that event->area is the 'extends' *) of the region that
>was invalidated. That is, the smallest rectangle that includes
>every part that was invalidated. This can be much larger than
>what really was invalidated (think of moving another window over
>the widget - that would expose an L-shaped region, and the
>extends would thus be much larger).
>A better way to write a general expose function with cairo
>would be as follows:
>gboolean expose_event_callback (GtkWidget *widget, GdkEventExpose *event)
> /* get a cairo_t */
> cairo_t* cr = gdk_cairo_create (widget->window);
> GdkRegion* region = event->region;
> gdk_cairo_region(cr, region); // Set path equal to region
> cairo_destroy (cr);
> return TRUE;
>Of course - this would still be doing a lot of possibly
>unnecessary work inside drawHeap (you might find ways to
>only redraw what was changed blah blah), but I can't put
>that in this mail (I'm thinking about writing a tutorial
>about that though...). Anyhow, this sets the correct clipping
Ivan Baldo - ibaldo at adinet.com.uy - http://ibaldo.codigolibre.net/
ICQ 10215364 - Phone/FAX (598) (2) 613 3223.
Caldas 1781, Malvin, Montevideo, Uruguay, South America.
We believe that we are free, but in reality we are not! Are we?
Alternatives: ibaldo at codigolibre.net - http://go.to/ibaldo
More information about the cairo