Android Question [XUI] drawing a dashed circle

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I would like to draw a dashed circle.

I have come up with this algorithm which uses initializearc, but it does not feel very efficient. Is there a better way?

B4X:
    Dim c As B4XCanvas
    c.Initialize(xview) ' view to draw on, assume a square

        Private path As B4XPath
        Private i As Int
        For i = 0 To 360 Step 30
            path.InitializeArc(c.targetrect.CenterX,c.TargetRect.CenterY,(c.TargetRect.Width / 2)-1dip,i,20)
            c.DrawPath(path,outlinecolour,False,2dip) ' Draw arc, not filled
            
        Next
        'remove all of the "spokes"
        Private pathin As B4XPath
        Private rt As B4XRect
        rt.Initialize(2dip,2dip,c.TargetRect.Right-2dip,c.TargetRect.Bottom-2dip)
        pathin.InitializeOval(rt)
        c.ClipPath(pathin)
        c.ClearRect(rt)
        c.RemoveClip
    c.Invalidate

    c.Release
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Here is a sample from the app screen, I am using it to draw the green line around the date. I had simplified the code to remove the date display etc

It works, I was just wondering if there was a better way.


upload_2019-2-19_16-54-14.png
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i think DrawPathRotated is better, one block (path) with 6 or 8 points painted 12x
u define inner and outer radius, with SinD & CosD you get the path block points.
 
Upvote 0
Top