Problem with FillPath

I’ve appropriated some of @anon20074439 code for drawing a tab panel:

g.PenSize = 1

Dim height As Double = 30
Dim width As Double = 50
Dim curve As Double = 10
Dim offset As Double = 10

Dim p As New GraphicsPath
p.MoveToPoint(g.PenSize / 2, height + g.PenSize / 2)
p.AddLineToPoint(offset + g.PenSize / 2, height + g.PenSize / 2)
p.AddLineToPoint(offset + g.PenSize / 2, curve + g.PenSize / 2)
p.AddCurveToPoint(offset + g.PenSize / 2, curve + g.PenSize / 2, offset + g.PenSize / 2, g.PenSize / 2, offset + curve + g.PenSize / 2, g.PenSize / 2)
p.AddLineToPoint(offset + width - g.PenSize / 2, g.PenSize / 2)

p.MoveToPoint(offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2) 'move to the end of the curve so we can draw it back where we came from
p.AddCurveToPoint(offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2, offset + width + curve - g.PenSize / 2, g.PenSize / 2, offset + width - g.PenSize / 2, g.PenSize / 2) 'draw it backwards so we have similar antialiasing
p.MoveToPoint(offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2) 'move to the end of the curve to carry on the line

'carry on with the line
p.AddLineToPoint(offset + width + curve - g.PenSize / 2, height + g.PenSize / 2)
p.AddLineToPoint(offset + width + curve + offset - g.PenSize / 2, height + g.PenSize / 2)
g.DrawPath(p, False)

I want to fill the result with:

g.DrawingColor = rgb(200, 200, 200)
g.FillPath(p, true)

But the result is super odd:

Screenshot 2022-04-05 at 14.55.21

How do I get the filled result? I’ve tried to close the path. But even then the path isn’t filled correctly:

Screenshot 2022-04-05 at 14.57.15

How do I get the path filled?

Xojo 2021r1 on Monterey.

Fill only with this path :

  • left vertical line
  • left arc
  • horizontal line
  • right arc
  • right vertical line

I stole the code not to do that. Besides, the resulting path should be the same.

I think it is because your second arc is drawn backward

g.PenSize = 1

Dim height As Double = 30
Dim width As Double = 50
Dim curve As Double = 10
Dim offset As Double = 10

Dim p As New GraphicsPath
p.MoveToPoint(g.PenSize / 2, height + g.PenSize / 2)
p.AddLineToPoint(offset + g.PenSize / 2, height + g.PenSize / 2)
p.AddLineToPoint(offset + g.PenSize / 2, curve + g.PenSize / 2)
p.AddCurveToPoint(offset + g.PenSize / 2, curve + g.PenSize / 2, offset + g.PenSize / 2, g.PenSize / 2, offset + curve + g.PenSize / 2, g.PenSize / 2)
p.AddLineToPoint(offset + width - g.PenSize / 2, g.PenSize / 2)

p.MoveToPoint(offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2) 'move to the end of the curve so we can draw it back where we came from
p.AddCurveToPoint(offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2, offset + width + curve - g.PenSize / 2, g.PenSize / 2, offset + width - g.PenSize / 2, g.PenSize / 2) 'draw it backwards so we have similar antialiasing
p.MoveToPoint(offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2) 'move to the end of the curve to carry on the line

'carry on with the line
p.AddLineToPoint(offset + width + curve - g.PenSize / 2, height + g.PenSize / 2)
p.AddLineToPoint(offset + width + curve + offset - g.PenSize / 2, height + g.PenSize / 2)
g.DrawPath(p, False)

Dim p2 As New GraphicsPath
p2.MoveToPoint (offset + g.PenSize / 2, height + g.PenSize / 2)
p2.AddLineToPoint(offset + g.PenSize / 2, curve + g.PenSize / 2)
p2.AddCurveToPoint(offset + g.PenSize / 2, curve + g.PenSize / 2, offset + g.PenSize / 2, g.PenSize / 2, offset + curve + g.PenSize / 2, g.PenSize / 2)
p2.AddLineToPoint(offset + width - g.PenSize / 2, g.PenSize / 2)

p2.AddCurveToPoint(offset + width - g.PenSize / 2, g.PenSize / 2, offset + width + curve - g.PenSize / 2, g.PenSize / 2, offset + width + curve - g.PenSize / 2, curve + g.PenSize / 2)

'carry on with the line
p2.AddLineToPoint(offset + width + curve - g.PenSize / 2, height + g.PenSize / 2)

p2.AddLineToPoint(offset + g.PenSize / 2, height + g.PenSize / 2)

g.DrawingColor = rgb(200, 200, 200)
g.FillPath(p2, true)

Capture d’écran 2022-04-05 à 15.40.18

2 Likes