B4J Question Draw round rect

moore_it

Well-Known Member
Licensed User
Longtime User
Hi all,

it's possible to draw a round rect in an canvas ?

Thanks in advice
 

klaus

Expert
Licensed User
Longtime User
B4X:
'Draws a rouded Rectangle
'x = left coordinate of the surrounding rectangle
'Y = top coordinate of the surrounding rectangle
'Width = width coordinate of the surrounding rectangle
'Height = height coordinate of the surrounding rectangle
'ArcWidth = corner arc width
'ArcHeight = corner arc height
'Color = fx.Colors.Color
'Filled  True Filled, False only the line
'Stroke = line width, has no effect when Filled = True
Public Sub DrawRectRounded(MyCanvas As Canvas, x As Double, y As Double, Width As Double, Height As Double, ArcWidth As Double, ArcHeight As Double, Color As Paint, Filled As Boolean, LineWidth As Double)    
    Private joCanvas, joGraph As JavaObject

    joCanvas = Canvas
    joGraph = joCanvas.RunMethod("getGraphicsContext2D", Null)

    If Filled = False Then
        joGraph.RunMethod("setStroke", Array As Object(Color))   
        joGraph.RunMethod("setLineWidth", Array As Object(LineWidth))   
        joGraph.RunMethod("strokeRoundRect", Array As Object(x, y, Width, Height, ArcWidth, ArcHeight))
    Else
        joGraph.RunMethod("setFill", Array As Object(Color))   
        joGraph.RunMethod("fillRoundRect", Array As Object(x, y, Width, Height, ArcWidth, ArcHeight))
    End If
End Sub
 
Upvote 0
Top