If Action = xpnl_base.TOUCH_ACTION_DOWN Then
g_y = y
g_x = x
xpath_main.Initialize(X,Y)
Else if Action = xpnl_base.TOUCH_ACTION_MOVE Then
xcv_main.DrawLine(X, Y, g_x, g_y, xui.Color_Red,5)
xpath_main.LineTo(x,y)
g_x = X
g_y = Y
xcv_main.Invalidate
End If
And save the line in a B4XPath.
how can i remove this line with the help of the B4XPath?
A simple solution would be to use a list to add/remove the coords, and only create the path based on it, when/if needed. This will allow you for an undo-depth greater than one.
To remove the line once it is drawn, you could either just clear the canvas and redraw everything using a path created with the new list (once the last element is removed) , or redraw the last line with the background color (if it is solid)
Unless you are creating fast moving graphics (in which case you should probably be looking to use a game library approach), redrawing the canvas is quick enough to redraw all of the objects. Save the paths in a list, then manage the list to delete the ones you no longer want and clear and redraw them all.
It'll save problems where lines may cross or overlay at corners etc..
Public Sub Undo
If (current_index) > -1 Then
xcv_main.ClearRect(xcv_main.TargetRect)
For i = 0 To current_index -1
xcv_main.DrawPath(lst_paths.Get(i),xui.Color_Red,False,5)
Next
xcv_main.Invalidate
current_index = current_index -1
End If
End Sub