LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Canvas draw

Hello!
I am using a canvas control to draw a polar plot. If the user clicks at some point on the plot, I draw a vector from the center of the polar plot to that particular point. The way I do it is, whenever the user clicks at a point I have to redraw the whole polar polt and the vector because on a canvas there is now way I can just redraw the vector to position to the new point leaving the polar plot in the background untouched. Is there a better way of doing this? Any suggestions?

Thanks
tmach
0 Kudos
Message 1 of 4
(2,976 Views)
Hi,

There are a cuple of things that I can advice here; first you can have a transparent canvas control on top of another canvas control. i.e.: you have canvas1 with a white background where you draw your grid and scales. Then you have on top of that canvas2 with a transparent background on top of canvas1; there you draw your actual plots. On top of cavas2 you have canvas3 (also transparent) where you draw the vectors that are generate by the user. Having these layers allows you to redraw only what is strictly necesary.

Together with this layered scheme, you should use CanvasStartBatchDraw(...) and CanvasEndBatchDraw(...) to perform repeated draw operations on a canvas this will avoid unecessary updates and refreshing. It's also a good idea to draw your c
anvas in a callback; this way you don't process draw events until you are done drawing all the layers.

I hope this helps!

Regards,

Juan Carlos
N.I.
0 Kudos
Message 2 of 4
(2,976 Views)
Allow me to add one more suggestion to what Juan Carlos already suggested.

If I understand your situation correctly, you're trying to draw vectors on a polar plot grid, such that the vectors "move" within the plot.

If that's the case, a common strategy is to draw the animated part of the drawing (in this case, the vector) in 'xor' mode. This imparts on the vector the property of combining with the background in such a way that if you draw the same vector again, in the same location, it restores the original background, thus erasing the vector. This suggests a fairly simple algorithm: before drawing the vector in the new position, draw the old vector one more time in order to erase it. You won't need to draw anything else.

To use the 'xor' raster operation, si
mply set the ATTR_PEN_MODE attribute to VAL_XOR_MODE.

Luis
NI
0 Kudos
Message 3 of 4
(2,976 Views)
Thanks Luis very much. I got the thing working.

tmach
0 Kudos
Message 4 of 4
(2,976 Views)