------------------------------------------------------------------------------- See also the file ../perl/perl_tk.hints ------------------------------------------------------------------------------- Using the Canvas widget (redraw and speed) D. Richard Hipp The canvas widget was too slow, so I went directly to X11. Here's what I did: * Use a "frame" widget for my drawing area. I used the "bind" command, on this frame, to capture expose events. The expose events trigger a C function to schedule a redraw. Also use "bind" to catch Configure events, which always cause a complete redraw. Also use "bind" to catch button and key presses, which are then dispatched to appropriate C routines. * All requests to redraw, or scroll, or otherwise change the canvas are deferred using Tk_DoWhenIdle. In other words, I don't redraw right away, but what until there is nothing else left to do. (All of the Tk widgets do the same thing, as you can tell by looking at the code.) Take care to make sure you don't have more than one redraw idle-callback pending at a time! * When it is time to redraw, first draw everything to a pixmap. Then copy the contents of the pixmap to the window using a single XCopyArea() call. (Again, this is how Tk widgets do it.) * You can find the window associated with your frame widget using the Tk_NameToWindow() function. All this is tricky to get right. You have to be very careful. Basically, you're have to write a new Tk widget, so use the existing Tk widgets as a guide. It's tough, but the resulting application will be VERY VERY fast, so it may well be worth your while. -------------------------------------------------------------------------------