[cairo] Program logic for interactive usage

Hakki Dogusan dogusanh at tr.net
Wed Mar 19 04:25:39 PDT 2008


Hi,

I'm working on an interactive drawing program.
There are some master-shapes -needing hittest- drawn outside of 
OnPaint/OnExpose etc. event and some temporary-shapes to be drawn on 
master-shapes on each OnPaint event.

To be able to draw and have path data outside of OnPaint I used 
following logic.

---------------------------------------------------------------------------
- create a stationary context in program startup
   mastersurface = cairo_image_surface_create(CAIRO.FORMAT_ARGB32, 
width, height)
   mastercontext = cairo_create(mastersurface)

- use master context to draw master-shapes (could be anywhere/anytime)
   save paths with cairo_copy_path_flat

- 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)

- OnPaint event
   cr = create a context for paint DC
   cairo_push_group_with_content(cr, CAIRO_CONTENT_COLOR)
   -- put master-shapes
   cairo_set_source_surface(cr, mastersurface, 0, 0)
   cairo_paint(cr)
   -- paint temporary-shapes here
   cairo_pop_group_to_source(cr)
   cairo_paint(cr)
   cairo_destroy(cr)
---------------------------------------------------------------------------


Is my logic reasonable?



--
Regards,
Hakki Dogusan


More information about the cairo mailing list