1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a template to allow the HeapBlock class to be given signed ints or other types that are not size_t for its size parameters

This commit is contained in:
jules 2017-10-11 12:10:58 +01:00
parent 13ccdf9411
commit 369d59f656
32 changed files with 189 additions and 199 deletions

View file

@ -37,20 +37,15 @@ ColourGradient::ColourGradient() noexcept
#endif
}
ColourGradient::ColourGradient (Colour colour1, const float x1, const float y1,
Colour colour2, const float x2, const float y2,
const bool radial)
: point1 (x1, y1),
point2 (x2, y2),
isRadial (radial)
ColourGradient::ColourGradient (Colour colour1, float x1, float y1,
Colour colour2, float x2, float y2, bool radial)
: ColourGradient (colour1, Point<float> (x1, y1),
colour2, Point<float> (x2, y2), radial)
{
colours.add (ColourPoint (0.0, colour1));
colours.add (ColourPoint (1.0, colour2));
}
ColourGradient::ColourGradient (Colour colour1, Point<float> p1,
Colour colour2, Point<float> p2,
const bool radial)
Colour colour2, Point<float> p2, bool radial)
: point1 (p1),
point2 (p2),
isRadial (radial)
@ -92,7 +87,7 @@ int ColourGradient::addColour (const double proportionAlongGradient, Colour colo
return 0;
}
const double pos = jmin (1.0, proportionAlongGradient);
auto pos = jmin (1.0, proportionAlongGradient);
int i;
for (i = 0; i < colours.size(); ++i)
@ -111,11 +106,8 @@ void ColourGradient::removeColour (int index)
void ColourGradient::multiplyOpacity (const float multiplier) noexcept
{
for (int i = 0; i < colours.size(); ++i)
{
Colour& c = colours.getReference(i).colour;
c = c.withMultipliedAlpha (multiplier);
}
for (auto& c : colours)
c.colour = c.colour.withMultipliedAlpha (multiplier);
}
//==============================================================================
@ -137,7 +129,7 @@ Colour ColourGradient::getColour (const int index) const noexcept
if (isPositiveAndBelow (index, colours.size()))
return colours.getReference (index).colour;
return Colour();
return {};
}
void ColourGradient::setColour (int index, Colour newColour) noexcept
@ -175,14 +167,14 @@ void ColourGradient::createLookupTable (PixelARGB* const lookupTable, const int
jassert (numEntries > 0);
jassert (colours.getReference(0).position == 0.0); // The first colour specified has to go at position 0
PixelARGB pix1 (colours.getReference (0).colour.getPixelARGB());
auto pix1 = colours.getReference (0).colour.getPixelARGB();
int index = 0;
for (int j = 1; j < colours.size(); ++j)
{
const ColourPoint& p = colours.getReference (j);
const int numToDo = roundToInt (p.position * (numEntries - 1)) - index;
const PixelARGB pix2 (p.colour.getPixelARGB());
auto& p = colours.getReference (j);
auto numToDo = roundToInt (p.position * (numEntries - 1)) - index;
auto pix2 = p.colour.getPixelARGB();
for (int i = 0; i < numToDo; ++i)
{
@ -205,18 +197,18 @@ int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlo
JUCE_COLOURGRADIENT_CHECK_COORDS_INITIALISED // Trying to use this object without setting its coordinates?
jassert (colours.size() >= 2);
const int numEntries = jlimit (1, jmax (1, (colours.size() - 1) << 8),
3 * (int) point1.transformedBy (transform)
.getDistanceFrom (point2.transformedBy (transform)));
lookupTable.malloc ((size_t) numEntries);
auto numEntries = jlimit (1, jmax (1, (colours.size() - 1) << 8),
3 * (int) point1.transformedBy (transform)
.getDistanceFrom (point2.transformedBy (transform)));
lookupTable.malloc (numEntries);
createLookupTable (lookupTable, numEntries);
return numEntries;
}
bool ColourGradient::isOpaque() const noexcept
{
for (int i = 0; i < colours.size(); ++i)
if (! colours.getReference(i).colour.isOpaque())
for (auto& c : colours)
if (! c.colour.isOpaque())
return false;
return true;
@ -224,8 +216,8 @@ bool ColourGradient::isOpaque() const noexcept
bool ColourGradient::isInvisible() const noexcept
{
for (int i = 0; i < colours.size(); ++i)
if (! colours.getReference(i).colour.isTransparent())
for (auto& c : colours)
if (! c.colour.isTransparent())
return false;
return true;