mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-22 01:34:21 +00:00
Added a constructor to ColourGradient that takes Point arguments
This commit is contained in:
parent
a4c0968635
commit
bc78b2f524
2 changed files with 34 additions and 2 deletions
|
|
@ -43,6 +43,17 @@ ColourGradient::ColourGradient (Colour colour1, const float x1, const float y1,
|
|||
colours.add (ColourPoint (1.0, colour2));
|
||||
}
|
||||
|
||||
ColourGradient::ColourGradient (Colour colour1, Point<float> p1,
|
||||
Colour colour2, Point<float> p2,
|
||||
const bool radial)
|
||||
: point1 (p1),
|
||||
point2 (p2),
|
||||
isRadial (radial)
|
||||
{
|
||||
colours.add (ColourPoint (0.0, colour1));
|
||||
colours.add (ColourPoint (1.0, colour2));
|
||||
}
|
||||
|
||||
ColourGradient::~ColourGradient()
|
||||
{
|
||||
}
|
||||
|
|
@ -141,12 +152,12 @@ Colour ColourGradient::getColourAtPosition (const double position) const noexcep
|
|||
while (position < colours.getReference(i).position)
|
||||
--i;
|
||||
|
||||
const ColourPoint& p1 = colours.getReference (i);
|
||||
auto& p1 = colours.getReference (i);
|
||||
|
||||
if (i >= colours.size() - 1)
|
||||
return p1.colour;
|
||||
|
||||
const ColourPoint& p2 = colours.getReference (i + 1);
|
||||
auto& p2 = colours.getReference (i + 1);
|
||||
|
||||
return p1.colour.interpolatedWith (p2.colour, (float) ((position - p1.position) / (p2.position - p1.position)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,27 @@ public:
|
|||
Colour colour2, float x2, float y2,
|
||||
bool isRadial);
|
||||
|
||||
/** Creates a gradient object.
|
||||
|
||||
point1 is the location to draw with colour1. Likewise point2 is where
|
||||
colour2 should be. In between them there's a gradient.
|
||||
|
||||
If isRadial is true, the colours form a circular gradient with point1 at
|
||||
its centre.
|
||||
|
||||
The alpha transparencies of the colours are used, so note that
|
||||
if you blend from transparent to a solid colour, the RGB of the transparent
|
||||
colour will become visible in parts of the gradient. e.g. blending
|
||||
from Colour::transparentBlack to Colours::white will produce a
|
||||
muddy grey colour midway, but Colour::transparentWhite to Colours::white
|
||||
will be white all the way across.
|
||||
|
||||
@see ColourGradient
|
||||
*/
|
||||
ColourGradient (Colour colour1, Point<float> point1,
|
||||
Colour colour2, Point<float> point2,
|
||||
bool isRadial);
|
||||
|
||||
/** Creates an uninitialised gradient.
|
||||
|
||||
If you use this constructor instead of the other one, be sure to set all the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue