Changing Color of SVG

For simple shapes like this, which I use for buttons e.g, I usually open the svc-file in my browser, view the source and take the gist of the shit, paste it as char * in the source file, do a Drawable::parseSVGPath, use path.getTransformToScaleToFit() to fit my destination area, scale it, and do g.fillPath() in paint(), which will render it in the currently selected colour. Something like:

static char *mySvg = "M1998.01,978.981a29.988,29.988,0,1,1,30.01-29.988A30,30,0,0,1,1998.01,978.981Zm0-54.524a24.536,24.536,0,1,0,24.55,24.536A24.544,24.544,0,0,0,1998.01,924.457ZM1988,936.141l25.73,12.424v0.856L1988,961.845v-25.7Z";
.
.
path = Drawable::parseSVGPath(mySvg); //in the relevant constructor
.
.

void paint(Graphics& g)
{
.
.
   auto tr = path.getTransformToScaleToFit(getLocalBounds().toFloat().reduced(3.5), false, Justification::centred);
   path.applyTransform(tr);
   g.setColour(Colours::red);
   g.fillPath(path);
}

To save a few cpu cycles you could do the scaling in your resized() function, so you don’t have to scale it for every paint…

6 Likes