[cairo] Layered stroke / fill

Chris Wilson chris at chris-wilson.co.uk
Sun Aug 19 04:56:02 PDT 2012


On Sun, 19 Aug 2012 20:44:28 +0900, Lockert Fredrick <lockert.fredrick at gmail.com> wrote:
> Greetings,
> 
> I'm currently programming a very simple gtkmm/cairo application, where
> the user can draw lines, circles, rectangles, etc, in real time.
> 
> There's one problem I've got though, and I can't quite figure out how
> to fix it. When the user draws out rectangles, they "merge" into each
> other, rather then being painted on top of each other. I'm sure this
> is an easy fix, but I couldn't find an answer after searching the web
> and the documentation (probably used the wrong keywords...)

Just stroke and fill each rectangle individually. Adding all rectangles
to the path then calling stroke/fill operates on the union of that path.
So,
  foreach (rect) {
    cr->rectangle(*rect)
    cr->set_source_rgb(*stroke_color)
    cr->stroke_preserve()
    cr->set_source_rgb(*fill_color)
    cr->fill()
  }
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the cairo mailing list