Drawing live to a non-visible Canvas

I am having some issues trying to draw to a canvas that is enabled but not visible. Should the invalidate/refresh only work if the canvas is visible? I am trying to draw some graphs while a user is on another screen which I am simply hiding that canvas that I am trying to draw on. When I then bring the visible = true to that canvas then it begins to draw only while its visible.

Thanks
Mike

When you say “draw to a canvas”, do you mean drawing into canvas.backdrop.graphics? Or do you mean code in the Paint event? And since invalidate/refresh imply updating the display, I wouldn’t expect them to have any effect on a non-visible control. Or put another way, as soon as the canvas becomes visible again, it’s going to want to fire its Paint event to redraw, so invalidate/refresh are pointless anyway.

Sorry Tim I should have been more specific. Having code in the paint event of the canvas and firing it off from a timer using invalidate(false).

I understand what you are saying about the invalidate/refresh. So am I going about this wrong? Ie. Should I just keep the canvas visible but just move it off screen and then bring it back giving the proper appearance to the user?
Thanks!

This is what I am doing with the graphing. For example if you click on the bottom entry on the left listbox I still want the top one graphing in the background somehow so when I return to it --it will be already graphed vs. having to wait a few seconds for the graph to build after its visible.

I just tried to move the container that holds the canvas offscreen and still no dice. Any thoughts? :slight_smile:
Thanks in advance!

A canvas not visible or off the screen will never draw.

Paint into a Picture and in the canvas’ Paint event use g.DrawPicture.

[quote=272594:@Eli Ott]A canvas not visible or off the screen will never draw.

Paint into a Picture and in the canvas’ Paint event use g.DrawPicture.[/quote]
Thanks Eli - I am trying not to draw anything in a picture offline since I am supporting Retina and I’m trying not to mess with manually handling a code drawn picture.

Why would this not work?

It would but I’ll have to own recognizing the Scaling Factor and then drawing in-code 1x/2x/3x size images. Exploring any other paths first. (Also thank you for taking the time to answer) :slight_smile:

But aren’t you doing that currently in the Paint event anyway?

I am currently not drawing offline pictures, but live to the canvas.paint using g.drawstring and g.drawobject using Sam’s RetinaKit. I have to use 2014r2.1 since I have been using Mac OSLib for a bunch of things and it breaks north of this version.

Isn’t the Graphics object of a picture the same class as the Graphics object of a canvas? If so you could DrawString and DrawObject into a picture with the RetinaKit the same way.

For static 1x/2x pictures loaded into the IDE yes with RetinaKit, but when you are creating on-the-fly code based pictures RetinaKit can’t support that (AFAIK as I asked Sam one time). Otherwise will handle it manually, but I don’t want to unless I have to since it will be a pain for me :slight_smile:

my understanding is a CANVAS object (not a PICTURE object) does its drawing only during the PAINT event, and this event does not/will not fire if the CANVAS is not visible. You can send 1000’s of Invalidate and/or REFRESH commands, and they will do nothing until such time as the CANVAS becomes at least partially visible (and then it will refresh ONE time regardless of how many times you had commanded it while it was not visible). AND the event of it becoming visible is in and of itself enough to trigger the PAINT event anyways.

Pre-calculate the graph so that the paint event is nothing but simple drawing commands. You should do as little computation in Paint as possible.

If you move the canvas offscreen, you risk losing the scaling factor, as that is tied to the display area. And as soon as you bring it back, it will redraw anyway.

If you draw to a Picture at 3x, it should scale correctly to the canvas at either retina or non-retina. So you might not have to deal with the scaling factor yourself.

It would but I’ll have to own recognizing the Scaling Factor and then drawing in-code 1x/2x/3x size images. [/quote]
Use BitmapForCaching to create the Picture and everything works out. No fiddling with ScaleFactor or changing the drawing code. All you have to do is use BitmapForCaching to create the Picture instead of New Picture.

edit: technically some situations won’t work transparently, but most typical uses do.

Mike uses version 2014r2.1 for his project.

[quote=272592:@Mike Cotrone]This is what I am doing with the graphing. For example if you click on the bottom entry on the left listbox I still want the top one graphing in the background somehow so when I return to it --it will be already graphed vs. having to wait a few seconds for the graph to build after its visible.

I just tried to move the container that holds the canvas offscreen and still no dice. Any thoughts? :slight_smile:
Thanks in advance!

[/quote]

hey?seems you hidden the window /min/max button and boarder,how do you do that?thanks

If your graph was made up from Object2d items in a group, when the canvas is eventually displayed you call .drawobject on thegroup and it will be virtually instantaneous.

The group can be scaled to meet whatever size the canvas is, and because it is vector based, you don’t get fuzzy edges.
The words become stringshapes not .drawstrings

Thank you Everyone! I appreciate the ideas!

[quote=272618:@Will Shank]Use BitmapForCaching to create the Picture and everything works out. No fiddling with ScaleFactor or changing the drawing code. All you have to do is use BitmapForCaching to create the Picture instead of New Picture.

edit: technically some situations won’t work transparently, but most typical uses do.[/quote]
Thank you Will. I will check this out. I also can’t believe I missed this Xojo Blog on the topic.

http://blog.xojo.com/advanced-retina/hidpi-bitmapforcaching-and-scalefactorchanged