How to create a double buffer on a DC? (Re: wxDC and Refresh()??)

Stefan Holmgren wrote:

is it possible to speed up the refresh for a dc?
my python code looks like this,
(created on a wxScrolledWindow:).

----------------
def onPaint(self, event):
self.doDraw(wxPaintDC(self))

def doDraw(self, dc):
dc.SetUserScale(self.scale, self.scale)

alot of this.....
dc.DrawPolygon(drawlist)
.....
---------------

when I change 'self.scale' or a color for an
object I have to make a Refresh().

Chris Barker wrote:

Double buffer. This is usually used to speed refreshes if the drawing
hasn't changed, but if the drdawing has changed, it may be that only
part of the drawing is changing regularly, and the rest is a background
of sorts. In this case, you could store the background in a buffer, and
only re-draw the foreground.

Tnx Chris, wxClientDC was a nice way to draw on the existing dc.
But, when I have a moving object, (created with wxClientDC),
I have to reset the background object.

I tried:
  dc.SetClippingRegion
  dc.Clear
  dc.DestroyClippingRegion
but, instead of clear I want to do a refresh for that region with object from my doDraw.
is there a way to refresh a dc region?

And please... How do I create a Double Buffer...
add an example with my code above, or do I have to change my code from scratch?

Tnx

Stefan Holmgren

Holmgren Stefan wrote:

but if the drdawing has changed, it may be that only

>part of the drawing is changing regularly, and the rest is a background
>of sorts. In this case, you could store the background in a buffer, and
>only re-draw the foreground.

Tnx Chris, wxClientDC was a nice way to draw on the existing dc.
But, when I have a moving object, (created with wxClientDC),
I have to reset the background object.

I tried:
        dc.SetClippingRegion
        dc.Clear
        dc.DestroyClippingRegion
but, instead of clear I want to do a refresh for that region with object from my doDraw.
is there a way to refresh a dc region?

Well, in theory, you could call self.DoDraw(dc), instead of the Clear().
This should allow your DoDraw routine to drw only to the clipping
Region, However, I suspect you won't get the performace you want this
way. It will only be negligably faster than just re-drawing the whole
thing. What I have done is something like the following:

# create a background bitmap:

self.background = wxEmptyBitmap(self.PanelSize[0],self.PanelSize[1])

# draw your background into it:

BackgroundDC = wxMemoryDC()
BackgroundDC.SelectObject(self.background)

DrawBackground(BackgroundDC)

# When the stuff moving on top changes:

#create a client DC
DC = wxClientDC(self)
#draw the background
DC.DrawBitmap(self.background,0,0)

#draw the foreground:
DrawForeground(DC)

You need to do pretty much the same thing in an OnPaint, except use a
wxPaintDC instead.

In theory, you can figure out what part of the back ground needs
refresshing, and only blit that part, but I did some esperiments, and
found no noticable change in performance. blits (or DrawBitmaps) are
pretty darn fast.

I've done all this, and a whole lot more, in my FloatCanvas class, but
it still needs some cleaning up. Let me know if you want to take a look
anyway, and I'll send you the code.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

While I've lost track of this conversation, I can point you
at an example of double buffering if you like. Check out:
http://www.sourceforge.net/projects/wxcolourchooser. I implemented
double buffering for the wxPyColourChooser. There's also wxBufferedDC
(I think that's the correct name), which should help you do double
buffering. Essentially, you maintain two DCs, one off-screen and
in memory, and another on-screen. You do all your drawing in the
off-screen and then blit on-screen.

            Hope that helps,

                  -- Mike

···

On Wed, Dec 04 @ 11:59, Holmgren Stefan wrote:

And please... How do I create a Double Buffer...
add an example with my code above, or do I have to change my code from scratch?

--
Michael Gilfix
mgilfix@eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html