[cairo] Polygon fill styles?
Kalle Vahlman
kalle.vahlman at gmail.com
Wed Aug 20 09:13:53 PDT 2008
2008/8/20 Ian Britten <britten at caris.com>:
> Hi all,
> [ Disclaimer - I'm fearing that most Cairo-purists will cringe
> at this question, but I've got to ask... :( ]
Heh, all that disclaimer is going to do is *lower* your change of
getting a constructive answer (who want's to be called a "purist"?).
Fortunately for you, this place is pretty tolerant to such remarks :)
> Does cairo have any built-in support for any of the typical
> quick-and-dirty polygon fill styles that many toolkits provide?
> eg: http://docs.wxwidgets.org/stable/wx_wxbrush.html#wxbrushsetstyle
> I didn't seem to see anything.
Except for the transparent and solid ones, no such thing exists in cairo.
[snip]
> Failing any native cairo support, does anyone have any suggestions
> (Or maybe example code! :) ) for doing stuff like this? I'm
> suspect it'll be something to do with a cairo_pattern_t... (But
> that's just one of many cairo things I haven't learned yet...)
You are right on the money, patterns are exactly what is used for this.
The idea is that you first create a small surface (preferrably with
create_similar() from the surface you want to draw to) and draw
whatever it is you want to repeat to it. Then you use
cairo_pattern_create_for_surface() to create a pattern of the surface.
To get it repeated, you simply set the extend mode for the pattern
with cairo_pattern_set_extend() to CAIRO_EXTEND_REPEAT.
Then you draw your polygon, but instead of setting the source to a
color like normal solid fills, you set the previously created pattern
as the source with cairo_set_source().
Easy as pie, no?
--
Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi
More information about the cairo
mailing list