There seems to be a problem in GradientBrush

I am having problem in using Gradient… I have Checked in 1.46 also…

I created a Color Gradient with both the colour 0.0 opacity…
I added a Color(Any color)…
If this is near to Start Point - it is working fine…
But if that colour position is near to End Point , it is not giving the expected result…

ColourGradient cg(Colours::red.withAlpha((uint8)0), 100, 100,   Colours::red.withAlpha((uint8)0), 100, 150, false); 
cg.addColour(0.99, Colours::red);
GradientBrush gb(cg);
g.setBrush(&gb);
g.fillRect(100, 0, 100, 250);

Where as the following code is working fine…

ColourGradient cg(Colours::red.withAlpha((uint8)0), 100, 100,   Colours::red.withAlpha((uint8)0), 100, 150, false); 
cg.addColour(0.01, Colours::red);
GradientBrush gb(cg);
g.setBrush(&gb);
g.fillRect(100, 0, 100, 250);

Interesting - it looks like there’s a little inaccuracy in the gradient code… How about this little tweak in juce_ColourGradient.cpp, line 153:

const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;

ColourGradient cg(Colours::red.withAlpha((uint8)0), 100, 100, Colours::red.withAlpha((uint8)0), 100, 150, false); 
cg.addColour(0.0, Colours::red);
GradientBrush gb(cg);
g.setBrush(&gb);
g.fillRect(100, 0, 100, 250);

ColourGradient cg(Colours::red.withAlpha((uint8)0), 100, 100, Colours::red.withAlpha((uint8)0), 100, 150, false); cg.addColour(0.0, Colours::red); GradientBrush gb(cg); g.setBrush(&gb); g.fillRect(100, 0, 100, 250); [/quote]

Seems to be doing the right thing to me… But it looks like you posted the same bit of code twice there?

When the proportion is 0.0 it is filling the region above start also…
But if the proportionate is 1.0 it is not filling the region below it…

I mean the proportion which we’ll give while adding a new color to a ColourGradient…

It’s just the sort-order of the three points - if you add a point at 0, it’ll insert it before the first point, but at 1.0 it’ll be before the last one. That’s not incorrect, but I see why it’s confusing.

But rather than messing about with things like this, you could just call clearColours() before adding the points you need - then you’re in full control of what’s going on.