Tom,

As Joe said, the Paint event should be ready to draw the whole canvas as needed. As Phil and Joe pointed out, and another Joe pointed out to me offlist, sometimes you may need to draw directly to canvas.graphics for performance reasons.

Here's what I do to work with my own FlickerFreeCanvas... All other canvases do all of their drawing in their Paint events, not outside. Sometimes, this might be bad for performance. In those cases, I cache objects to be drawn as picture properties of the canvas. These are computed on demand, and nil'd out when the canvas is resized or otherwise need the cached pictures updated.

So a paint event might look like:

        // draw cached pictures first
        if picBackground1 = nil then
           MakeBackground1
        end if
        if picBackground1 <> nil then
           g.DrawPicture picBackground1, 0,0
        end if
        ...

        // draw dynamic content here

An example of something I'm able to do with this general approach is adjust the brightness or color level of a full screen picture using a slider and getting very good responsiveness. So I don't think you have to draw from outside to achieve good performance. At least, I haven't seen a case where it was required. The bonus with this approach is that if you use a drop-in replacement for canvas that squashes flicker on Windows, your code just works, because it only draws inside the Paint event.

Hope that helps.

-Brad

On Feb 15, 2006, at 12:39 PM, Tom Buchler wrote:

Brad,

Thanks. I'm trying to get my head around this.
The functionality I'm building involves editing music notation with lyrics. So at various moments I'm drawing lines for music staffs, musical notes, positioned text with features (bold, etc.), scroll bar etc. In some code, I need to determine text width as it will appear in the canvas' current font. Sometimes I draw the whole page. Sometimes I just change the background color for a small area to indicate highlighted notes. Sometimes I redraw one note and its surrounding staff lines. Sometimes I need to redraw the entire canvas because another window is no longer obscuring part of my control, and I don't what part of the canvas was obscured.

What do I put in the paint event so to achieve that?
I can imagine marking the list of objects I'm displaying with a "Changed" property so that a monolithic redraw would only modify parts of the backimage before BLTing it to the canvas. In that scenario, how do I know that Paint wasn't triggered by another window that was just moved from obscuring the canvas?


-Tom

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to