Hey all. I’m lost on how to draw a simple drop shadow behind an SVG Drawable. I’ve tried all sorts of things, and the only one with which I’ve had success is to draw the Drawable to a background
Image object, then use the
DropShadow::drawForImage method to draw a dropshadow for that image onto my graphics context.
I’m not a fan of that approach because it means I have to render my drawable twice: once to the background image, and once to the actual graphics context, though I can optimize it somewhat by holding the background image as a member variable and only redrawing if I need a new size. You might say I should just paste the background image onto the graphics context as well when I need to, but I’ve found that the result looks very pixelated as opposed to rendering my Drawable directly. (And if I’m going to draw larger res and rescale to try to fix that, why not just use pngs in the first place? Feels to me like that would defeat the point of a vector interface.)
It seems to me, from the docs, that I should be able to do something like this:
DrawablePath* knobCap = static_cast<DrawablePath*>(DrawablePath::createFromImageData(BinaryData::KnobCap_svg, BinaryData::KnobCap_svgSize)); ColourGradient shadow(Colours::black, x + (width / 2), y + (height / 2), Colours::transparentBlack, width, height, true); knobCap->setTransformToFit(dest.reduced(10.f, 10.f), RectanglePlacement::centred); knobCap->drawWithin(g, dest, RectanglePlacement::centred, 1.f); knobCap->setFill(shadow); knobCap->drawWithin(g, dest, RectanglePlacement::centred, 1.f);
The approach here (buggy, I know) being to draw the SVG and also overwrite the SVG’s fill type with a radial gradient representing the shadow, and draw the shadow that way. I’d have to reverse the order in this example and add an offset to the shadow, but this approach quickly hits an error having to do with deleting a non-existant object somewhere underneath the
knobCap->setFill call. Perhaps that’s just a bug in JUCE?
I’ve similarly tried using a
shadow.drawForPath(g, knobCap->getOutlineAsPath()) approach, but in my case where the SVG is a knob, the outline returned is a ring, and thus the shadow that is drawn is the shadow of a ring, not of a knob (circle).
So at this point I’m kinda just lost. What’s the right way to do this? Thanks