[cairo] Gradient Transformation Problems
Me Myself
radracer59 at inbox.com
Wed Dec 12 14:24:55 PST 2007
Perhaps what I'm trying to do won't be possible then. But I'd like to have any arbitrary path (filled with a gradient) and give the user the option to shrink or expand the path (and the gradient fill) while maintaining the same look, only bigger or smaller (but not necessarily the same scale for both X and Y).
The user will be able to directly edit the points of the path, so it would not make sense to present the user with untransformed points.
Although, I don't think I understand exactly why it isn't possible to do this (but I'm no math guru). Given the slope of a linear gradient, and a X and Y scale factor, shouldn't I be able to replicate the same slope with scaled points?
> -----Original Message-----
> From: cworth at cworth.org
> Sent: Wed, 12 Dec 2007 12:40:42 -0800
> To: radracer59 at inbox.com
> Subject: Re: [cairo] Gradient Transformation Problems
>
> On Wed, 12 Dec 2007 10:10:25 -0800, Me Myself wrote:
>> So given any arbitrary X and Y scaling, do you know a formula I
>> could use on the gradient pattern points to make them maintain the
>> proper results when I manually calculate the points?
>
> As already mentioned, that's not possible.
>
> But what are you trying to achieve here that you are having trouble
> with? Do note that you can use a transformation for the gradient, but
> not also use that transformation for any subsequent paths, etc.
>
> That would look something like this:
>
> cairo_matrix_t save;
>
> cairo_get_matrix (cr, &save);
>
> cairo_scale (cr, sx, sy); /* or whatever transformation you
> * want for your gradient */
>
> cairo_set_source (cr, gradient_pattern);
>
> cairo_set_matrix (cr, &save);
>
> Note that I'm manually using cairo_get_matrix;cairo_set_matrix to save
> and restore just the transformation matrix. I can't use
> cairo_save;cairo_restore here since that would also save/restore the
> source pattern which would leave the call to cairo_set_source having
> no effect.
>
> Would an approach like the above help you achieve what you are wanting
> to do?
>
> -Carl
More information about the cairo
mailing list