Yes, this is rendered in JUCE with C++

Text shadows use the same melatonin::DropShadow and melatonin::InnerShadow classes as paths:

class MySlider : public juce::Component
{
public:

    void paint (juce::Graphics& g) override
    {
        g.setColour (juce::Colours::black);
        g.setFont (juce::Font (20));
        shadow.render (g, "Hello World", getLocalBounds(), juce::Justification::centred);
        g.drawText ("Hello World", getLocalBounds(), juce::Justification::centred);
    }

private:
    melatonin::DropShadow shadow = {{ juce::Colours::red, 8, { -2, 0 } }};
}

Right now, the API just mirrors g.drawText, so it’s not particularly DRY. I’m open to suggestions on how to improve this. Ellipses aren’t supported, but you can open a PR. I will never support drawFittedText — it’s downright evil and should be deprecated and removed from JUCE 🙂

Just like g.drawText, you can pass in a juce::Rectangle<int>, juce::Rectangle<float>, or the x, y, w, h as bounds arguments.

Text shadows are cached. As with path shadows, repainting is cheap and changing their color, offset, opacity is free.

However, changing the font, text, justification or bounds will require re-rendering both the glyphs and underlying blur.


Leave a Reply

Your email address will not be published. Required fields are marked *