[Gambas-user] Paint: Draw lines only between .MoveTo & .LineTo

Martin Belmonte mbelmonte at belmotek.net
Mon May 9 20:42:39 CEST 2022


Hello friends.
Could someone please tell me how to stop paint from drawing a line when 
it is positioned on another point.
The problem appears between point 4 and 5 which should not be drawn.
In the example I try to draw the capital letter "A" but you see the result.

https://i.imgur.com/g0CQKjB.png

On the topic [1] Charly proposed a solution for the letter A but then 
when extending the example with the letter E it doesn't apply anymore.
I am looking for a general solution that allows to draw lines between 
two given points without generating an extra line when moving to the 
first point of the next line.

[1] https://forum.gambas.one/viewtopic.php?f=4&t=1323

Here is the code.

' Gambas class file

Private afPoints As New Float[][]

Public Sub Lettering_Click()

   afPoints.Clear
   Select Last.Tag
     Case "a"
       afPoints.Add([10, 100])
       afPoints.Add([60, 10])

       afPoints.Add([60, 10])
       afPoints.Add([110, 100])

       afPoints.Add([30, 50])
       afPoints.Add([80, 50])
       DrawingArea1.Refresh

     Case "e"
       afPoints.Add([10, 100])
       afPoints.Add([10, 10])

       afPoints.Add([10, 10])
       afPoints.Add([110, 10])

       afPoints.Add([10, 50])
       afPoints.Add([80, 50])

       afPoints.Add([10, 100])
       afPoints.Add([110, 100])

   End Select

   DrawingArea1.Refresh

End

Public Sub DrawingArea1_Draw()

   Dim z As Integer
   Dim i As Integer

   If afPoints.Count > 0 Then
     Paint.Brush = Paint.Color(Color.Red)
     Paint.LineWidth = 3

     For z = 0 To afPoints.Max - 1
       If z = afPoints.Max - 2 Then
         Paint.NewPath()
       Else
         Paint.MoveTo(afPoints[z][0], afPoints[z][1])
         Paint.LineTo(afPoints[z + 1][0], afPoints[z + 1][1])
       Endif
       Paint.Stroke
     Next
   Else
     DrawingArea1.Children.Clear
   Endif

End


More information about the User mailing list