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

T Lee Davidson t.lee.davidson at gmail.com
Tue May 10 01:09:34 CEST 2022


On 5/9/22 14:42, Martin Belmonte wrote:
> 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.
[snip]

You are iterating over *every* point. Which means essentially, you are moving to where you just drew a line to, and then drawing 
from the same point to itself.

Try this:
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 Step 2 ' <<<<----- HERE
       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


-- 
Lee


More information about the User mailing list