Post by Stefan CsomorWhich situations are you thinking of ? rubberbanding ?
Yes, as well as virtually any other time you'd use a wxClientDC.
My understanding (and this is from wxPython, not C++, if that makes any
difference) is that you only want to use a PaintDC inside a system Paint
event. There are a LOT of times when I want to draw something to the
screen when there is no paint event, and calling Refresh() causes a lot
of flashing.
-RubberBanding
-User Drawing something with the mouse
-Updating an image as a result of some other event (computation loop, etc)
-Animation
I have mostly used double buffering in my apps. In this case, I tend to
draw to the buffer, and then blit the buffer to a wxClientDC. whenever
it changes. The other option is to draw to the buffer and call
Refresh(), but that results in a lot of flashing, on GTK at least.
My Paint handler does nothing but blit the buffer to the screen.
It sounds like OS-X is double buffering for you, so I wouldn't need to
do that there, but I'm writing cross platform apps, so I'm kind of
stuck. What would be great is if wx had a double buffered Window class,
which would just be a Window on OS-X, and have the double buffering
implemented on the other platforms.
Post by Stefan CsomorPost by David Elliottexplicitly recommend that you force a
window refresh and handle the drawing from your paint event.
I'm way out of my depth here, but I imagine that that's because OS-X
doesn't trigger Paint events very often, as most of the time it will
just repair the screen with the buffer, and your app doesn't have to do
anything. It also seems to have optimized the refresh process.
Post by Stefan CsomorPost by David ElliottSo in most cases the proper solution is to, as Stefan says, handle
everything from the regular paint event and explicitly force an Update()
if you need it to draw before the next event iteration.
I've done a couple little test apps in wxPython to see how this would
work. Much to my surprise, I don't get any of the flicker that I
expected! However, this is a pretty simple example. It does two things:
1) Draws a line while the user drags the left mouse button
2) Runs a little animation of a line being drawn
I did three versions, the first two without using a wxClientDC, and the
third with a wxClientDC, which is how I have always done it.
TestUpdate.py is the simplest, without a wxClientDC
TestUpdate2.py uses a double buffer, without a wxClientDC
TestUpdate3.py uses a wxClientDC
I noticed a couple things while writing these tests:
- Without double buffering or a wxClientDC, the entire image has to be
re-drawn with each change, rather than just drawing the new line. This
would be a real problem if you had a complex image (rubberbanding over a
complex image, for instance)
- With the double buffering, I'm essentially triple buffering on OS-X (I
think!)
- With the wxClientDC, I found I needed a wxApp.Yield() in the animation
method, or it would wait 'till the end to draw. Update() did not work in
this case.
Note that these were tested only on wxGTK with wxPython 2.5.1
How should I be doing this kind of thing???
-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
***@noaa.gov