Android Question [Solved] canvas clear issue

Pflichtfeld

Active Member
Licensed User
I have a panel pan as b4xview (defined in Globals) and a canvas can as b4xcanvas, defined in the sub
pan.color is in designer set to white

all happens in a drawing sub:
I start with canv.Initialize(pan)

it works fine, drawing one figure to the canvas.
If I draw the figure in a for next loop (calling the sub from the loop) in different positions and If I do not call
canv.ClearRect(canv.TargetRect)
then the figure is drawn one over another.

If I DO call canv.ClearRect(canv.TargetRect), the previous figure is deleted, but the background-color of the pan is gone. (Each figure is drawn solely)

If I instead of .ClearRect use canv.DrawRect(canv.TargetRect,colors.white,True,1) it works fine, but I wanna keep the pan.color, which could be other then white in other panels, and
canv.DrawRect(canv.TargetRect,pan.Color,True,1) seems not to work, because pan.color here is 0 which I do not understand.

Where am I wrong?
TH
 

Pflichtfeld

Active Member
Licensed User
Thank you, Erel!

I also tried to draw the background myself. I wanna use this sub for different panels so I tried canv.DrawRect(canv.TargetRect,pan.Color,True,1) but pan.Color returns 0, what I would not have expected. (Why does it return 0?)
So: How can I draw the background of the canvas with the original backgroundcolor of changing panels?
 
Upvote 0

Pflichtfeld

Active Member
Licensed User
Tried to upload a .zip with 814 kByte, but I am told "the uploaded file is too large"
(Just zipped the folder of my project)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Pflichtfeld

Active Member
Licensed User
I have a panel pan as b4xview (defined in Globals) and a canvas can as b4xcanvas, defined in the sub
pan.color is in designer set to white
all happens in a drawing sub:
I start with canv.Initialize(pan)

I found the problem myself now: the label-Color is set to 0 by initializing a canvas with this label:
B4X:
Log ("Color in sub draw before canv. initialize: " & pan.Color)
canv.Initialize(pan)
Log ("Color in sub draw after canv. initialize: " & pan.Color)
In first line the correct color is returned, after canv. Initialize 0 is returned.
Pity!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If you want to have a background which remains, you could add a second panel with a second canvas which has a transparent background.
 
Upvote 0
Top