Graphic independent gradient?


#1

Hi,

Currently, the gradient brush is dependent on what’ll be paint after it’s created. It’s like a chicken&egg problem here.

I would like to create a gradient brush, let say from (10%,10%) to (60%,60%) of the size of what will be painted afterward but I can’t with current code.

This mean that I must know the size I’ll be drawing to create the gradient before actually starting drawing anything.

As it’s user code that will control the drawing code, I can’t create the gradient.

I wonder if it would be possible to add a case to current GradientBrush to let it create the gradient only when first used, with relative value (like percent or a destination’s width&height ratio) ?


#2

Well, that’s not really very easy. Maybe you think about using drawables instead?


#3

I don’t fully understand your answer.

You meant create a 1px * 1px drawablePath with a specified gradient brush, and then resize the drawable before drawing it, right ?

This is ok if I want to fill a shape, but if I want to draw a line or something else that’s not a path ?

In fact, I more or less critisizing this usage pattern (the way they are used means that gradient can only be temporary variable).
Maybe I should try to create a buffered gradient ?


#4

Well, I don’t think gradients shouldn’t really be coupled to things like components or other persistent objects. All the code relating to graphics contexts is inherently temporary because a context is just created for use in a paint() call, and then discarded. If you want a more powerful object, maybe it should be something that contains a gradient and some extra information that it can use to update the gradient’s parameters.