Re: repainting own panel-component

From: Rob Kennedy (me3_at_privacy.net)
Date: 03/28/04


Date: Sun, 28 Mar 2004 14:30:20 -0600

J French wrote:
>> I figure the slowdown might be from however Dirk is determining that
>> three seconds have passed and that the control needs to be repainted. I
>> hope he's using a timer and not a loop.
>
> I did not see anything about 3 Seconds

Oh, nevermind. Neither did I, apparently. I saw something about the
colors changing every three pixels, but must have stopped reading before
I reached "pixels." I was imagining some color-cycling.

Unfortunately, now that I know the display isn't changing dynamically, I
don't have anything to blame for the slowdown anymore.

> - actually I would not have any 'timing' or delay at all
> - from watching Paint Events, they seem to only happen when necessary
>
> Ah! I see what you mean

Well, that makes one of us!

> You are saying that the Resize Event could occur hundreds of times
> - but when something gotta be painted, it gotta be painted
> - I think the 'oversize' background and copying large chunks will
> eradicate that problem
> - but you've made me think that the resize event is not necessarily
> the best place to build the background canvas

I still think that is the best place. However, there are ways to reduce
the load when the window is being resized. When a resize operation
begins, Windows sends a wm_Sizing message. (This might be difficult,
depending on whether all the controls get that message or only the
top-level window.) When the window is in "sizing" mode, you could turn
off generation of new bitmaps and just continue painting the old size.
When the window receives a wm_Size message, that means the resize
operation has ended, which would be the cue to regenerate a properly
sized bitmap.

> Hmm - do you think the Invalidate is necessary ?

Depends on the nature of the striped background. If the number of
stripes remains constant and they get thicker when the control grows,
then Invalidate is definitely necessary. When a control grows, Windows
only repaints the part that just became visible. When a control shrinks,
Windows might not repaint the control at all. So if the backgorund image
is proportional to the size of the control, then you need to repaint the
whole thing. I think TPanel has a related property, called something
like FullRepaintOnResize.

> I'm also inclined to suggest that he makes his background Canvas
> slightly larger than the Screen
> - a little jiggling with coordinates would guarantee stripes being in
> the right place regardless of the ClipRect

Another approach, the usefulness of which depends on the thickness of
the stripes, would be to use a patterned brush. You can set up an 8x8
bitmap that matches the stripe pattern, the top four rows in one color
and the bottom four in another. Assign the brush handle in the panel's
CreateParams method, and Windows should handle the background painting
automatically.

-- 
Rob

Quantcast