[cairo] Layered stroke / fill

Lockert Fredrick lockert.fredrick at gmail.com
Sun Aug 19 06:22:47 PDT 2012


On 19 August 2012 21:51, Uli Schlachter <psychon at znc.in> wrote:
> Try swapping the calls to stroke and fill:
>
>     cr->fill_preserve();
>     cr->set_source_rgb(1.0, 1.0, 1.0);
>     cr->stroke();
>
> The fill() will otherweise erase part of the earlier stroke().

Swapping the two calls, results in the stroke not being drawn (or
filled over, since the stroke does not appear), thus that would give
an undesired effect.

The original problem was solved by drawing the rectangles individually
(which is quite obvious), as suggested by Chris Wilson.

cr->save();
    if(mMouseDown)
    {
        cr->rectangle(mRect.left, mRect.top, mRect.right, mRect.bottom);
        cr->set_source_rgb(0.0, 0.0, 0.0);
        cr->stroke_preserve();
        cr->set_source_rgb(1.0, 1.0, 1.0);
        cr->fill();
    }

    for(int i = 0; (unsigned)i < mRects.size(); ++i)
    {
        cr->rectangle(mRects[i].left, mRects[i].top, mRects[i].right,
mRects[i].bottom);
        cr->set_source_rgb(0.0, 0.0, 0.0);
        cr->stroke_preserve();
        cr->set_source_rgb(1.0, 1.0, 1.0);
        cr->fill();
    }
    cr->restore();

Thus they no longer "merge" into each other and give the desired effect.

Thanks for your suggestion though, Uli. I really do appreciate it.

- Fredrick


More information about the cairo mailing list