B4J Question Clearing a B4XCanvas on B4J

james_sgp

Active Member
Licensed User
Longtime User
HI, I`m having a problem clearing a transparent canvas, I`m using the code below but it isn`t doing anything. I have tried it with a solid color and works, but not with transarent color.

B4X:
        Dim cvsbk As B4XRect
        cvsbk.Initialize(0,0,1010,641)
        cvs.drawRect(cvsbk, xui.Color_Black, True, 0)

Thanks James
 

PaulMeuris

Well-Known Member
Licensed User
Here's a little test to show how to clear the B4XCanvas (or a rectangle of it) in B4J.
1718427946672.png
1718427980546.png
1718428044190.png

In the layout you have a pane and a button. The pane is on top of the button and is transparent.
1718428108685.png
1718428162290.png

At startup a black rectangle is drawn and the pane is sent to the background to allow you to click on the button.
When you click on the button then a portion of the black rectangle is cleared (cnvs.ClearRect(rect).
The pane is brought back to the front and a red circle is drawn.
And that is it.
P.S.: i could have answered with the one line cnvs.ClearRect(rect) but where is the fun in that, right?
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Pane1 As Pane
    Public cnvs As B4XCanvas
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    cnvs.Initialize(Pane1)
    Dim rect As B4XRect
    rect.Initialize(0,0,300,300)
    cnvs.DrawRect(rect,xui.Color_Black,True,1)
    Pane1.As(B4XView).SendToBack
End Sub
Private Sub Button1_Click
    Dim rect As B4XRect
    rect.Initialize(0,0,200,200)
    cnvs.ClearRect(rect)
    Pane1.As(B4XView).BringToFront
    cnvs.DrawCircle(100,100,50,xui.Color_Red,False,5)
End Sub
 
Upvote 0
Top