Drawing brought to front?

wdegler

Active Member
Licensed User
Longtime User
Here is a minimal example of my problem. I wish to draw on a canvas of a panel, erase the drawing, and redraw it. The following code does not show the redrawing. Can someone show me how I should do this?

Dim Pnl As Panel
Dim Cnv As Canvas
Dim Pth As Path
Dim Wipe As Label

Pnl.Initialize("") 'init staff panel
Pnl.Color=Colors.Red
Activity.AddView(Pnl,0,0,40%x,40%y)
Cnv.Initialize(Pnl) 'init canvas for drawing on it
Pth.Initialize(5%x,15%y) 'draw a line segment
Pth.LineTo(15%x,15%y)
Cnv.drawPath(Pth,Colors.Yellow,False,1)
Activity.Invalidate
Msgbox("","Drawn?")
Wipe.Initialize("") 'remove the line segment
Wipe.Color=Colors.Red
Pnl.AddView(Wipe,5%x,14%y,15%x,16%y)
Msgbox("","Removed?")
Pth.Initialize(5%x,15%y) 'redraw the line segment
Pth.LineTo(15%x,15%y)
Cnv.drawPath(Pth,Colors.Yellow,False,1)
Activity.Invalidate
Msgbox("","Redrawn?")
 

klaus

Expert
Licensed User
Longtime User
This code works:
B4X:
Pnl.Initialize("") 'init staff panel
Pnl.Color=Colors.Red
Activity.AddView(Pnl,0,0,40%x,40%y)
Cnv.Initialize(Pnl) 'init canvas for drawing on it
Pth.Initialize(5%x,15%y) 'draw a line segment
Pth.LineTo(15%x,15%y)
Cnv.drawPath(Pth,Colors.Yellow,False,1)
Pnl.Invalidate
Msgbox("","Drawn?")
Cnv.drawPath(Pth,Colors.Red,False,1)
Pnl.Invalidate
Msgbox("","Removed?")
Pth.Initialize(5%x,15%y) 'redraw the line segment
Pth.LineTo(15%x,15%y)
Cnv.drawPath(Pth,Colors.Yellow,False,1)
Pnl.Invalidate
Msgbox("","Redrawn?")
You have following problems in your code:
- You should invalidate the Panel.
- Adding the Label to remove the drawing covers the Panel hiding the next drawing.

Best regards.


Best regards.
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Thank you, Klaus

Thank you for showing me :sign0142:your revision.
Although redrawing all my graphics is problematic, I see from your revision that drawing a red-filled rectangle of appropriate dimensions works.
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
And label text?

On this same panel, I also have some text from a label visible. The solution above removes the drawing but not the text. The label text is not visible if I make the label a child of Activity. How can I remove the text (as well as the drawing)?
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Ausgezeichnet!

Yes, that's it!
Now, I don't have to use Label.RemoveView.
Ich danke Ihnen.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
and if i have a imageview with an image loaded and i want to draw something on the image without deleting the image is it possible?

example i have a picture of a dog and i would like to paint the dog without delete the dog how ca i do it?

thanx
 
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
You could always position an imageview with an empty, transparent image on top of your dog and then draw into the transparent image. That way, the contours of the dog-to-be-painted will stay visible.

Or, I haven't tried it, but maybe you could place the drawing of the dog into the background property of the imageview and then draw directly on top of that. If the dog is not too big, I would prefer the first method, though.

Hope this helps.

Regards,
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
hi ukimiku

thanx for your help

but it doesnot work. i put an imageview with a transparent image and if i draw on the transparent image the other imageview with the dog is being overdrawing

what else could i do?

thanx
 
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
I'm not sure I understand what goes wrong and which image view is being on top in your app. Have you put the transparent image above the dog or below it? It should be above (on top of) the dog. If you declare the two imageviews in code, you should declare the transparent one after the one displaying the dog. Or you could bring the transparent imageview to the top with
B4X:
transparent.BringToFront

(please rename accordingly).
Please post your code here, I will take a look at it. Use code tags. Thanks.

Regards,
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I'm not sure I understand what goes wrong and which image view is being on top in your app. Have you put the transparent image above the dog or below it? It should be above (on top of) the dog.

hi

image1 = imageview with transparent imag
image2 = image with the dog

image1 with the transparent image is on the top like you told me to do

but still its drawing over the image2 (image with the dog) that is behind
image1.

i solved the problem in another way

i made the png file with the dog transparent (via GIMP) and put it on the top
of image1 that is without any imagefile (only white background) and not transparent

the listener is on the image2 (image with the dog) but the drawing happens on the image1 that is behind.

like this the image2 with the dog stays like i wanted.

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