Drawing dashed, filled arcs

Hi, not sure if there’s anyway of doing this out of the box?

I can see there’s code for drawing filled arcs, stroking dashed paths, but no obvious way to do a dashed filled arc?

Cheers

Everything’s done with Paths - just create your arc as a path and you can fill + stroke it however you need.

i think that’s the bit I’m having trouble figuring out - how to create a dashed fill…

Well, you’d fill it, then as a second pass, draw a dashed stroke around it (?)

Maybe you are after a dashed FillType aka diagonal?

I haven"t seen one, would be a usefull addition…

Well if you mean you’re trying to fill an area with hatched lines, then you could mask the graphics context to the arc shape by clipping it, then just draw a bunch of parallel lines.

Yes, maybe my description is off. I tried the first approach you suggested originally, but not what I wanted as I don’t want a filled area with dashed lines around it. I don’t want to mask and fill an area, I still want to be able to specify the dash lengths and draw an arc. I tried just drawing a thick outline but it draws the inside and outside paths which doesn’t work.

I still can’t understand what you’re actually trying to do. Maybe draw a picture of it!

Here’s some example code, which I think is doing what you’re after

void YourComponent::paint(Graphics &g)
{
    Path p;

    /* draw your arc */
    p.startNewSubPath(0.0, getHeight()*0.5);
    p.addArc(0.0, 0.0, getWidth(), getHeight(), -0.5*float_Pi, 0.5*float_Pi);

    /* create path stroke type, */
    PathStrokeType stroke(1.0);

    /* create an array for your dash lengths */
    float dash[1] = {5.0};

    /* create the dashes */
    stroke.createDashedStroke(p, p, dash, 1);

    /* paint */
    g.strokePath(p, stroke);
}
1 Like

Yes, that’s it - thanks for your help. The place I was going wrong was that I was basing my code on the LAF code for drawing a rotary slider which used addPieSegment instead of addArc - once this was changed it behaves as I need it to.

Thanks!