Android Question B4A to B4X Draw Function

marconotsopolo

Member
Licensed User
I have been trying to convert the following into B4X code today which I found on the forum in a project (sorry can't remember the original author), but with little success. I have only just started with the drawing canvas/rect functions, so still learning!

B4X:
Private Sub DrawValue2(View As View, cvs As Canvas, Value As Float)
   Dim clr As Int = Colors.White
   cvs.DrawColor(Colors.Transparent)
   Dim strokewidth As Int = 2dip
   Dim cx = View.Width / 2, cy = View.Height / 2 As Float
  
   Dim r As Rect
   r.Initialize(-100dip, -100dip, View.Width + 200dip, View.Height + 200dip)
   Dim ArcRect As JavaObject
   ArcRect.InitializeNewInstance("android.graphics.RectF", Array(r))
   Dim p As Path
   p.Initialize(cx, cy)
   Dim jo As JavaObject = p
   Dim start As Float = -90
   jo.RunMethod("arcTo", Array(ArcRect, start, Value))
   If Value < 360 Then cvs.ClipPath(p)
   DrawRoundRect2(cvs, 1dip, 1dip, View.Width - 2dip, View.Height - 2dip, 10dip, clr, False, strokewidth)
   If Value < 360 Then cvs.RemoveClip
   View.Invalidate
End Sub

I know it would seem simple but the logic has eluded me so far. I have tried various drawpath options but with little luck.

Any help appreciated.
 

Cableguy

Expert
Licensed User
Longtime User
First some clarification...
B4X code is a piece of code that can/may run in one or more B4X IDE.
You can have a piece of code that only runs in B4J and not in B4A nor B4i and is still B4X code, although you can think of it as being B4J code. The same way, you can have some piece of code that runs in B4A and B4J and not in B4i... and it's B4X code.
Hope I was clear enough.
 
Upvote 0

marconotsopolo

Member
Licensed User
Thank you for that clarification and noted, I was looking for a cross platform solution if that is any clearer.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Thank you for that clarification and noted, I was looking for a cross platform solution if that is any clearer.
If you want to make this cross platform, you should take a look at B4xCanvas and B4xPath.

B4xPath can draw an arc using the InitialiseArc and then using drawPath method from the canvas

All of the calls to JavaObject will only work on B4A.

see

and
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…