[cairo] Program logic for interactive usage

Carl Worth cworth at cworth.org
Wed Mar 19 15:36:46 PDT 2008


On Wed, 19 Mar 2008 13:25:39 +0200, Hakki Dogusan wrote:
> - create a stationary context in program startup
>    mastersurface = cairo_image_surface_create(CAIRO.FORMAT_ARGB32, 
> width, height)
>    mastercontext = cairo_create(mastersurface)

From your description it doesn't sound like you need mastersurface to
be an *image* surface. So your program may be more efficient if you
instead use cairo_surface_create_similar here, (and pass to it a
surface that's targeting your window system---perhaps by calling
cairo_get_target after your "create a context for paint DC").

> - HitTest in Mouse events
>    for each master-shape's path:
>      cairo_new_path(mastercontext)
>      cairo_append_path(mastercontext, path)
>      result = cairo_in_fill(mastercontext, x, y)

The cairo_in_fill call is correct, but fairly expensive. As an
optimization, you might want to add some bounding-box based bailouts
to avoid having to call cairo_in_fill when it will obviously return
false.

> Is my logic reasonable?

Seems fine to me. Is everything working well for you?

I hope you're having fun with cairo,

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080319/06af90f2/attachment.pgp 


More information about the cairo mailing list