I’d like to replicate the removed Graphics.DrawArc function.
Given a starting point and an ending point, I’d like to draw an arc. I understand there can be two arcs drawn between two given points (I’ve yet to decide which one I’ll draw).
I tried various parameters with GraphicsPath.AddCurveToPoint or GraphicsPath.AddQuadraticCurveToPoint, even tried to convert examples found in other languages, but every attempt failed.
I’d also like to avoid drawing an oval to a temp picture and clearing 3/4 of it (I’m searching for the way to draw an arc directly).
i used this
it is called from within paint event DrawArc g
Public Sub DrawArc(g As Graphics)
Var cx As Double = g.Width / 2
Var cy As Double = g.Height -10-6
Var acrWidth As Double = g.Width -20.0
Var arcHeight As Double = acrWidth
'------------------------------------------------- Brush
Var linearBrush As New LinearGradientBrush
linearBrush.StartPoint = New Point(0, 0)
linearBrush.EndPoint = New Point(g.Width, 0)
linearBrush.GradientStops.Add(New Pair(0, TemperaturColor(-20)))
linearBrush.GradientStops.Add(New Pair(0.25, TemperaturColor(0)))
linearBrush.GradientStops.Add(New Pair(0.75, TemperaturColor(100.0)))
linearBrush.GradientStops.Add(New Pair(1.0, TemperaturColor(100.0)))
g.Brush = linearBrush
'------------------------------------------------- Acr Anfang
Var a As New ArcShape
a.Width = acrWidth
a.Height = arcHeight
Var angle As Double = ((1.57 * 2.0) * Temperature) / 100.0
a.ArcAngle = angle
a.StartAngle = -1.57*2.0
a.FillColor = Color.Orange
'a.BorderWidth = 1
'a.BorderColor = Color.Black
'a.BorderOpacity = 50
g.DrawObject(a, cx, cy)
'-------------------------------------------------
g.Brush = Nil
'------------------------------------------------- Acr Ende
a = New ArcShape
a.Width = acrWidth
a.Height = arcHeight
a.ArcAngle = 1.57*2.0-angle
a.StartAngle = -1.57*2.0+angle
a.FillColor = Color.Gray
'a.BorderWidth = 1
'a.BorderColor = Color.Black
'a.BorderOpacity = 50
g.DrawObject(a, cx, cy)
'------------------------------------------------- innnen Rund
Var oval As New OvalShape
oval.Height = a.Height * 0.60
oval.Width = a.Width * 0.60
oval.FillColor = Color.FillColor
'oval.BorderWidth = 1
'oval.BorderColor = Color.Black
'oval.BorderOpacity = 50
g.DrawObject(oval, cx, cy)
'-------------------------- Zeiger
Var dot As New OvalShape
dot.FillColor = Color.Black
dot.Width = 10
dot.Height = 10
'g.DrawObject dot, cx, cy
Var ox1 As Double = Cos(angle-1.57*2.0) * arcHeight / 2.0
Var oy1 As Double = Sin(angle-1.57*2.0) * arcHeight / 2.0
Var ox2 As Double = Cos(angle-1.57*2.0) * 40.0
Var oy2 As Double = Sin(angle-1.57*2.0) * 40.0
g.DrawingColor = Color.Black
g.PenSize = 3.0
g.LineCap = Graphics.LineCapTypes.Round
g.DrawLine cx +ox1 , cy +oy1, cx +ox2 , cy +oy2
End Sub
Public Function TemperaturColor(temp as double) As Color
Var col As Color
Var red As Double = 128.0 + (temp / 50.0) * 255.0
If red < 0.0 Then red = 0.0
If red > 255.0 Then red = 255.0
Var blue As Double = 128.0 + (-temp / 25.0) * 255.0
If blue < 0.0 Then blue = 0.0
If blue > 255.0 Then blue = 255.0
col = Color.RGB(red,0,blue)
Return col
End Function
Public Property Temperature As Double
Get
Return mTemperature
End Get
Set
mTemperature = value
Self.Invalidate
End Set
End Property