Re: cairo-1.13 finally opens

Krzysztof Kosiński <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAFLw2WRp=CUCtgLBFjOswUpUvQT_zZNSefNcLE_XzYDx96sU_A@mail.gmail.com>
2013/9/6 Henry (Yu) Song - SISA <[email protected]>:
> Hi, Bill
>
>
> Draw a drop shadow is in the following sequence
>
> /* set up shadow spec */
> cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
> cairo_set_shadow_rgba (cr, ....);
> cairo_set_shadow_offset (cr, x, y);
> cairo_set_shadow_blur (cr, blur_x, blur_y);
>
> /* setup draw path */
> cairo_arc (cr, ......);
> cairo_set_source_rgba (cr, ......);
>
> /* draw both shadow and object */
> cairo_fill/stroke (cr);

From an application programmer perspective, I find this API really
strange. It tacks on the shadow as an extra context attribute, like
line parameters, which is not how I think about filter effects. A much
better API from my point of view would be something like this:

cairo_set_blur(cr, blur_x, blur_y);
cairo_fill(cr);

Drop / inset shadow is a "high level" effect and I don't think it has
to be implemented directly in the API, unless there are substantial
performance gains from doing so.

> cairo_set_draw_shadow_only (cr, TRUE);  // this inform cairo to draw shadow with current path without drawing the object itself */

This is a really ugly hack that should not be necessary.

> Inset shadow is a different story, inset shadow requires blur inwards instead of outwards.  so the ugly API I come up with is used for draw a custom shadow path, tells cairo to blur it inwards. and app uses clip to bound the drawing area.  This is only if you want to have a custom shadow path for inset shadow.  If you don't need a custom shadow path,  it is drawn like example above. for example

Why not:
cairo_fill_preserve(cr);
cairo_clip_preserve(cr);
cairo_set_blur(...);
cairo_set_source(...); // change shadow color
cairo_fill(cr);

This also allows patterned shadows, which are not possible under your approach.

Regards, Krzysztof
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.