Paint sample

Post your Gambas programming questions here.
Post Reply
User avatar
tincho
Posts: 48
Joined: Wednesday 10th July 2019 1:12pm

Paint sample

Post by tincho » Monday 09th May 2022 12:40pm

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.
Image
Private afPoints As New Float[][]

Public Sub ToolButton1_Click()

  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

End

Public Sub DrawingArea1_Draw()

  Dim z As Integer

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

    For z = 0 To afPoints.Max - 1
      Paint.MoveTo(afPoints[0], afPoints[1])
      Paint.LineTo(afPoints[z + 1][0], afPoints[z + 1][1])
      Paint.Stroke
    Next
  Endif

End
Regrds

User avatar
cogier
Site Admin
Posts: 875
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Paint sample

Post by cogier » Monday 09th May 2022 1:35pm

This code should help (I had to change your line 27 as it caused a crash): -
Private afPoints As New Float[][]

Public Sub ToolButton1_Click()

  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

End

Public Sub DrawingArea1_Draw()

  Dim z 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
  Endif

End
Image

User avatar
tincho
Posts: 48
Joined: Wednesday 10th July 2019 1:12pm

Re: Paint sample

Post by tincho » Monday 09th May 2022 2:13pm

cogier wrote:
Monday 09th May 2022 1:35pm
This code should help (I had to change your line 27 as it caused a crash): -
ok, it works, but now I add the "E" and...
' 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

I looking for the general method.
However, with your example, I am closer to achieving it. Thanks :D
Regards

Post Reply