'Get the drawing counter.
'NOTE: GetDrawingCount, ClearDrawingCount, Invalidate, AutoInvalidate and any getter command will be excluded from count.
Sub GetDrawingCount As Long
Return count
End Sub
'Clear the drawing counter.
Sub ClearDrawingCount
count = 0
End Sub
'Clear the full canvas with the given color.
Sub Clear(Color As Int)
ArgList.Initialize2(Array("Clear",Color))
CommitCommand(ArgList)
End Sub
'This is a short hand of cvs.ClearRect(cvs.TargetRect)
Sub ClearTargetRect
ClearRect(cvs.TargetRect)
End Sub
'Clears the given rectangle. Does not work with clipped paths.
Sub ClearRect (Rect As B4XRect)
ArgList.Initialize2(Array("ClearRect", Rect))
CommitCommand(ArgList)
End Sub
''Clips the drawings to a closed path.
'Sub ClipPath (Path As B4XPath)
' CommitCommand(Array("ClipPath", Path))
'End Sub
'Draws the bitmat in the given destination.
'Use B4XBitmap.Crop To draw part of a bitmap.
Sub DrawBitmap (Bitmap As Image, Dest As B4XRect)
CommitCommand(Array("DrawBitmap", Bitmap, Dest))
End Sub
'Similar to DrawBitmap. Draws a rotated bitmap.
Sub DrawBitmapRotated (Bitmap As Image, Dest As B4XRect, Degrees As Float)
CommitCommand(Array("DrawBitmapRotated", Bitmap, Dest, Degrees))
End Sub
'Draws a circle.
Sub DrawCircle (x As Float, y As Float, Radius As Float, Color As Int, Filled As Boolean, StrokeWidth As Float)
CommitCommand(Array("DrawCircle", x, y, Radius, Color, Filled, StrokeWidth))
End Sub
'Draws a pixel.
Sub DrawPixel (x As Float, y As Float, Color As Int)
CommitCommand(Array("DrawPixel", x, y, Color))
End Sub
'Draws a line between x1,y1 and x2,y2.
Sub DrawLine (x1 As Float, y1 As Float, x2 As Float, y2 As Float, Color As Int, StrokeWidth As Float)
CommitCommand(Array("DrawLine", x1, y1, x2, y2, Color, StrokeWidth))
End Sub
''Draws the given path.
'Sub DrawPath (Path As B4XPath, Color As Int, Filled As Boolean, StrokeWidth As Float)
' CommitCommand(Array("DrawPath", Path, Color, Filled, StrokeWidth))
'End Sub
'
''Similar to DrawPath. Rotates the path based on the degrees and center parameters.
'Sub DrawPathRotated (Path As B4XPath, Color As Int, Filled As Boolean, StrokeWidth As Float, Degrees As Float, CenterX As Float, CenterY As Float)
' CommitCommand(Array("DrawPathRotated", Path, Color, Filled, StrokeWidth, Degrees, CenterX, CenterY))
'End Sub
'Draws a rectangle.
Sub DrawRect (Rect As B4XRect, Color As Int, Filled As Boolean, StrokeWidth As Float)
CommitCommand(Array("DrawRect", Rect, Color, Filled, StrokeWidth))
End Sub
'Similar to DrawRect. Draw a rotated rectangle.
Sub DrawRectRotated (Rect As B4XRect, Color As Int, Filled As Boolean, StrokeWidth As Float, Degrees As Float)
CommitCommand(Array("DrawRectRotated", Rect, Color, Filled, StrokeWidth, Degrees))
End Sub
'Draws a rectangle with round corners specified by CornerRadius.
Sub DrawRoundRect(Rect As B4XRect, Color As Int, Filled As Boolean, StrokeWidth As Float, CornerRadius As Float)
CommitCommand(Array("DrawRoundRect",Rect, Color, Filled, StrokeWidth, CornerRadius))
End Sub
'Similar to DrawRoundRect. Draw a rectangle with round corners and rotated by Degrees angle.
Sub DrawRoundRectRotated(Rect As B4XRect, Color As Int, Filled As Boolean, StrokeWidth As Float, CornerRadius As Float, Degrees As Float)
CommitCommand(Array("DrawRoundRectRotated",Rect, Color, Filled, StrokeWidth, CornerRadius, Degrees))
End Sub
'Draws an oval.
Sub DrawOval(Rect As B4XRect, Color As Int, Filled As Boolean, StrokeWidth As Float)
CommitCommand(Array("DrawOval", Rect, Color, Filled, StrokeWidth))
End Sub
'Similar to DrawOval. Draw the oval rotated by Degrees angle.
Sub DrawOvalRotated(Rect As B4XRect, Color As Int, Filled As Boolean, StrokeWidth As Float, Degrees As Float)
CommitCommand(Array("DrawOvalRotated", Rect, Color, Filled, StrokeWidth, Degrees))
End Sub
'Draws the text at the given position. For alignment use one of following values "LEFT", "CENTER", "RIGHT".
Sub DrawText (Text As String, x As Double, y As Double, Font As B4XFont, Color As Int, Alignment As Object)
CommitCommand(Array("DrawText", Text, x, y, Font, Color, Alignment))
End Sub
'Similar to DrawText. Rotates the text before it is drawn.
Sub DrawTextRotated (Text As String, x As Double, y As Double, Font As B4XFont, Color As Int, Alignment As Object, Degrees As Float)
CommitCommand(Array("DrawTextRotated", Text, x, y, Font, Color, Alignment, Degrees))
End Sub
'-----------------------------------
'Sets or gets AutoInvalidate property.
'By default AutoInvalidate is False, you will need to call Invalidate to update the drawings.
'If you set AutoInvalidate to True, then the drawings will be auto updated every command.
Sub setAutoInvalidate(Val As Boolean)
' CommitCommand("SetAutoInvalidate", Null)
' If Args.Get(0) = "true" Then mAutoInvalidate = True Else mAutoInvalidate = False
mAutoInvalidate = Val
End Sub
Sub getAutoInvalidate As Boolean
Return mAutoInvalidate
End Sub
'Measures single line texts and returns their width, height and the height above the baseline.
'Rect.Top returns the height above the baseline.
Sub MeasureText(Text As String, Font As B4XFont) As B4XRect
Return cvs.MeasureText(Text, Font)
End Sub
#If B4A Or B4i
Sub Release ' ONLY B4A and B4i
cvs.Release
End Sub
#End If
'Removes a previously set clip region.
Sub RemoveClip
cvs.RemoveClip
End Sub
'Resizes the canvas.
Sub Resize (Width As Double, Height As Double)
cvs.Resize(Width, Height)
pnl.SetLayoutAnimated(0, 0, 0, Width, Height)
End Sub
' //////////////// GETTERS, SETTERS //////////////////
'Returns a copy of B4XBitmap.
Sub CreateBitmap As B4XBitmap
Return cvs.CreateBitmap
End Sub
'Returns the native B4XCanvas.
Sub getCanvas As B4XCanvas
Return cvs
End Sub
'Returns the native B4XCanvas.
Sub getPanel As B4XView
Return pnl
End Sub
Sub TargetRect As B4XRect
Return cvs.TargetRect
End Sub
Sub TargetView As B4XView
Return cvs.TargetView
End Sub
'Gets or sets the canvas Width (You can use Resize instead to resize it).
Sub getWidth As Double
Return pnl.Width
End Sub
Sub setWidth(Width As Double)
pnl.Width = Width
End Sub
'Gets or sets the canvas Height (You can use Resize instead to resize it).
Sub getHeight As Double
Return pnl.Height
End Sub
Sub setHeight(Height As Double)
pnl.Height = Height
End Sub