Curving a rectangle dynamically along a path

Hi all, I’ve done some research on curve drawing with Path etc but can’t seem to get them working together to get my desired result.

I have one path that’s drawing a curved line (working fine). Now I’m trying to use fillRectangle() in a second path to illustrate another point of data. What I’d like to have is the bottom part of the rectangle draw along the path of the line.

Here is what I have…

I tried to use addLineSegment and look at a way of filling in to the previous line segment, but that didn’t quite work either, though this shows how I’d like the bottom to curve along the line

Can anyone offer a tip? Thinking it’s somehow using cubicTo but can’t get it to quite work.

Thanks for any help!

I am not sure I understand, but a few remarks about the drawing primitives:

You can always call fillPath or strokePath. fillPath will have no effect on a path that was not explicitly closed calling closeSubPath().

cubicTo has nothing to do with a cube, it refers to the polynomial how a bezier curve is defined.

I am not sure, but you might be after using the path as a clipping region.
To do so, create a copy of your path and close it, preferably along the Component borders.

It looks roughly llike this:

juce::Path fp (curve);
fp.lineTo (currentX, 0);
fp.LineTo (firstX, 0);
fp.closeSubPath();
{
    // new scope to conveniently save the Graphics state
    Graphics::ScopedSaveState saveState (g);

    g.reduceClipRegion (fp);
    g.fillRect (whateverRect);
    // end of scope restores original clip region
}

// draw the curve on top to avoid clipping by the curve
curve.strokePath (g, ...);

Hope that helps

2 Likes