32 point1.
setX (987654.0f);
33 #define JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED jassert (! exactlyEqual (point1.x, 987654.0f));
35 #define JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED
40 : point1 (
other.point1), point2 (
other.point2), isRadial (
other.isRadial), colours (
other.colours)
44 : point1 (
other.point1), point2 (
other.point2), isRadial (
other.isRadial),
45 colours (std::move (
other.colours))
48ColourGradient& ColourGradient::operator= (
const ColourGradient&
other)
50 point1 =
other.point1;
51 point2 =
other.point2;
53 colours =
other.colours;
57ColourGradient& ColourGradient::operator= (ColourGradient&&
other)
noexcept
59 point1 =
other.point1;
60 point2 =
other.point2;
61 isRadial =
other.isRadial;
62 colours = std::move (
other.colours);
87 return {
c1, 0,
y1,
c2, 0, y2,
false };
92 return {
c1, x1, 0,
c2, x2, 0,
false };
97 return point1 ==
other.point1 && point2 ==
other.point2
98 && isRadial ==
other.isRadial
99 && colours ==
other.colours;
102bool ColourGradient::operator!= (
const ColourGradient&
other)
const noexcept
104 return ! operator== (
other);
120 colours.
set (0, { 0.0, colour });
127 for (i = 0; i < colours.
size(); ++i)
131 colours.
insert (i, { pos, colour });
143 for (
auto& c : colours)
144 c.colour = c.colour.withMultipliedAlpha (
multiplier);
150 return colours.
size();
156 return colours.getReference (index).position;
164 return colours.getReference (index).colour;
172 colours.getReference (index).colour =
newColour;
179 if (position <= 0 || colours.size() <= 1)
180 return colours.getReference (0).colour;
182 int i = colours.size() - 1;
183 while (position < colours.getReference (i).position)
186 auto&
p1 = colours.getReference (i);
188 if (i >= colours.size() - 1)
191 auto&
p2 = colours.getReference (i + 1);
193 return p1.colour.interpolatedWith (
p2.colour, (
float) ((position -
p1.position) / (
p2.position -
p1.position)));
199 JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED
206 for (
int j = 0;
j < colours.size() - 1; ++
j)
208 const auto&
o = colours.getReference (
j + 0);
209 const auto& p = colours.getReference (
j + 1);
211 const auto pix1 =
o.colour.getNonPremultipliedPixelARGB();
212 const auto pix2 = p.colour.getNonPremultipliedPixelARGB();
214 for (
auto i = 0; i <
numToDo; ++i)
220 jassert (0 <= index && index < numEntries);
221 lookupTable[index++] =
blended;
225 std::fill (lookupTable + index, lookupTable + numEntries, colours.getLast().colour.getPixelARGB());
230 JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED
236 lookupTable.
malloc (numEntries);
243 for (
auto& c : colours)
244 if (! c.colour.isOpaque())
252 for (
auto& c : colours)
253 if (! c.colour.isTransparent())
259bool ColourGradient::ColourPoint::operator== (ColourPoint
other)
const noexcept
261 const auto tie = [] (
const ColourPoint& p) {
return std::tie (p.position, p.colour); };
262 return tie (*
this) == tie (
other);
265bool ColourGradient::ColourPoint::operator!= (ColourPoint
other)
const noexcept
267 return ! operator== (
other);
int size() const noexcept
Returns the current number of elements in the array.
void remove(int indexToRemove)
Removes an element from the array.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
void set(int indexToChange, ParameterType newValue)
Replaces an element with a new value.
void clear()
Removes all elements from the array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
Describes the layout and colours that should be used to paint a colour gradient.
static ColourGradient horizontal(Colour colour1, float x1, Colour colour2, float x2)
Creates a horizontal linear gradient between two X coordinates.
ColourGradient() noexcept
Creates an uninitialised gradient.
int createLookupTable(const AffineTransform &transform, HeapBlock< PixelARGB > &resultLookupTable) const
Creates a set of interpolated premultiplied ARGB values.
Colour getColour(int index) const noexcept
Returns the colour that was added with a given index.
bool isOpaque() const noexcept
Returns true if all colours are opaque.
static ColourGradient vertical(Colour colour1, float y1, Colour colour2, float y2)
Creates a vertical linear gradient between two Y coordinates.
Colour getColourAtPosition(double position) const noexcept
Returns the an interpolated colour at any position along the gradient.
void removeColour(int index)
Removes one of the colours from the gradient.
bool isRadial
If true, the gradient should be filled circularly, centred around point1, with point2 defining a poin...
int getNumColours() const noexcept
Returns the number of colour-stops that have been added.
bool isInvisible() const noexcept
Returns true if all colours are completely transparent.
void multiplyOpacity(float multiplier) noexcept
Multiplies the alpha value of all the colours by the given scale factor.
void setColour(int index, Colour newColour) noexcept
Changes the colour at a given index.
void clearColours()
Removes any colours that have been added.
~ColourGradient()
Destructor.
int addColour(double proportionAlongGradient, Colour colour)
Adds a colour at a point along the length of the gradient.
double getColourPosition(int index) const noexcept
Returns the position along the length of the gradient of the colour with this index.
Represents a colour, also including a transparency value.
Very simple container class to hold a pointer to some data on the heap.
void malloc(SizeType newNumElements, size_t elementSize=sizeof(ElementType))
Allocates a specified amount of memory.
Represents a 32-bit INTERNAL pixel with premultiplied alpha, and can perform compositing operations w...
A pair of (x, y) coordinates.
ValueType getDistanceFrom(Point other) const noexcept
Returns the straight-line distance between this point and another one.
void setX(ValueType newX) noexcept
Sets the point's x coordinate.
Point transformedBy(const AffineTransform &transform) const noexcept
Returns the position of this point, if it is transformed by a given AffineTransform.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.