Is there any easy way in the juce framework to make gradients like this?
https://i.stack.imgur.com/JG0KB.pnghttps://i.stack.imgur.com/1tpCq.png
it’s super easy in html/css but damn near impossible via the tools in juce, I’ve found.
the html looks like this:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%" height="100%"
viewBox="0 0 100 100">
<radialGradient id="radial" cx="50" cy="50" r="50"
gradientUnits="userSpaceOnUse">
<stop offset="0.8" style="stop-color:#00FFFF"/>
<stop offset="1" style="stop-color:#004444"/>
</radialGradient>
<circle cx="50" cy="50" r="50"
fill="url(#radial)"/>
</svg>
that <stop offset="0.8" style="stop-color:#00ffff"/>
is similar to the ColourGradient::addColor() method. But getting a gradient to wrap around a shape is basically impossible, unless you make a gradient for every non-horizontal/vertical edge. which means shapes like this are impossible with Colour Gradients:
I need to be able to resize shapes like this dynamically, that’s why i’m asking about doing it in code, instead of just using regular images.
code like this:
void SquareGradient::paint(Graphics& g)
{
auto inner = getLocalBounds().withSizeKeepingCentre(3 * getWidth() / 4, 3 * getHeight() / 4);
auto innerTopleftPoint = inner.getTopLeft();
auto innerTopRightPoint = inner.getTopRight();
auto innerBottomLeftPoint = inner.getBottomLeft();
auto innerBottomRightPoint = inner.getBottomRight();
auto obCenter = getLocalBounds().toFloat().getCentre();
Point<float> topLeft{0,0};
Point<float> topRight{static_cast<float>(getWidth()), 0};
Point<float> bottomLeft{0,static_cast<float>(getHeight())};
Point<float> bottomRight{static_cast<float>(getWidth()),static_cast<float>(getHeight())};
g.setGradientFill({outerColor, 0, 0, centerColor, static_cast<float>(innerTopleftPoint.getX()), 0, false});
Path path;
path.addTriangle(topLeft, obCenter, bottomLeft);
g.fillPath(path);
g.setGradientFill( {centerColor, static_cast<float>(innerTopRightPoint.getX()), 0,
outerColor, static_cast<float>(getWidth()), 0,
false} );
path.clear();
path.addTriangle(obCenter, topRight, bottomRight);
g.fillPath(path);
g.setGradientFill( {outerColor, 0, 0,
centerColor, 0, static_cast<float>(innerTopleftPoint.getY()),
false } );
path.clear();
path.addTriangle(topLeft, topRight, obCenter);
g.fillPath(path);
g.setGradientFill( {centerColor, 0, static_cast<float>(innerBottomLeftPoint.getY()),
outerColor, 0, static_cast<float>(getHeight()),
false} );
path.clear();
path.addTriangle(bottomLeft, obCenter, bottomRight);
g.fillPath(path);
}
gets me images like this: