Private Sub DrawSegmentText(oCan As B4XCanvas, CX As Int, CY As Int, AngleStart As Float, AngleEnd As Float, _
Radius As Int, Text As String, TextFont As Typeface, TextSize As Float, TextColor As Int)
Dim pdMid As Double
Dim piMidX As Int
Dim piMidY As Int
Dim pdAngle As Double
Dim poFont As B4XFont
Dim poSize As B4XRect
Dim piStartX As Int
Dim piStartY As Int
Dim piEndY As Int
Dim piEndX As Int
Dim pdChordLen As Double
Dim pdSagitta As Double
If Text.Trim.Length = 0 Then
Return
End If
' setup our font and measure the text we need to print
poFont = moXUI.CreateFont(TextFont, TextSize)
poSize = oCan.MeasureText(Text, poFont)
' calculate mid point of outer arc
pdAngle = (AngleEnd + AngleStart) / 2
pdMid = DegreeToRadian(pdAngle)
' calculate the height of the arc "bulge" so we can make sure the text falls below it and the edges won't be cut off by the falling arc
piStartX = CX + Radius * Cos(DegreeToRadian(AngleStart))
piStartY = CY + Radius * Sin(DegreeToRadian(AngleStart))
piEndX = CX + Radius * Cos(DegreeToRadian(AngleEnd))
piEndY = CY + Radius * Sin(DegreeToRadian(AngleEnd))
' formula requires 1/2 of the chord length
pdChordLen = Sqrt(Power(piEndX - piStartX, 2) + Power(piEndY - piStartY, 2)) / 2
pdSagitta = Radius - Sqrt(Power(Radius, 2) - Power(pdChordLen, 2))
' adjust text position
piMidX = CX + (Radius - (poSize.Width / 2)) * Cos(pdMid)
piMidY = CY + (Radius - pdSagitta - poSize.Height) * Sin(pdMid)
oCan.DrawTextRotated(Text, piMidX, piMidY, poFont, TextColor, "CENTER", pdAngle + 90)
End Sub
Private Sub DegreeToRadian(DegreeValue As Double) As Double
Return DegreeValue * 0.017453292
End Sub