B4J Question Drawing Arrow on Canvas

dieterp

Active Member
Licensed User
Longtime User
Is it possible to draw an arrow on a canvas (Or CanvasExt), where the arrow will follow and extend as you drag your mouse along the canvas?
 

dieterp

Active Member
Licensed User
Longtime User
I managed to solve this query by using the function below
B4X:
Sub canvas_arrow(fromx As Double, fromy As Double, tox As Double, toy As Double)
    Dim headlen As Int = 10 ' length of head in pixels
    Dim dx As Double = tox - fromx
    Dim dy As Double = toy - fromy
    Dim angle As Double = ATan2(dy, dx)
    Canvas1Ext.beginPath
    Canvas1Ext.DrawRect(0, 0, Canvas1.PrefWidth, Canvas1.PrefHeight, fx.Colors.Transparent, True, 0)
    Canvas1Ext.moveTo(fromx, fromy)
    Canvas1Ext.lineTo(tox, toy)
    Canvas1Ext.lineTo(tox - headlen * Cos(angle - cPI / 6), toy - headlen * Sin(angle - cPI / 6))
    Canvas1Ext.moveTo(tox, toy)
    Canvas1Ext.lineTo(tox - headlen * Cos(angle + cPI / 6), toy - headlen * Sin(angle + cPI / 6))
    Canvas1Ext.stroke
    Canvas1Ext.closePath
End Sub
 
Upvote 0
Top