Re: global clip for a cairo context
Uli Schlachter <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Hi, Am 02.01.2016 um 15:11 schrieb Enrico Weigelt, metux IT consult: > is it possible to set a global clip onto an cairo context, which > remains for the lifetime of the context (or until explicitly reset), > so it will never ever paint outside these boundaries ? > > I'm looking for a way to achieve clipping in my tiny widget toolkit. > The individual widget's paint callback should get passed a cairo_t*, > representing it's paint area, just like if it had its own surface. sorry, but what's the difference to a "non-global" clip? The only ways to unset the clip are through cairo_reset_clip() (the "explicit reset") and through cairo_restore() (which restores the clip of the corresponding cairo_save()). So I'd guess that something like this should work for you: cairo_rectangle(cr, widget->x, widget->y, widget->width, widget->height); cairo_clip(cr); widget->paint_callback(cr) cairo_reset_clip(cr); Cheers, Uli P.S.: Actually, I'd do something like this: cairo_save(cr); cairo_translate(cr, widget->x, widget->y); cairo_rectangle(cr, 0, 0, widget->width, widget->height); cairo_clip(cr); widget->paint_callback(cr, widget->width, widget->height); cairo_restore(cr); This "feels nicer", widget can just assume that their top-left corner is at point (0,0) and it also does the right thing when recursion occurs. -- “Cold. Cold. Cold. Cold. Cold. Cold. Cold. Cold. Cold. Cold.” – Anna -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo