Path: utzoo!attcan!uunet!ginosko!usc!bloom-beacon!LCS.MIT.EDU!MAP From: MAP@LCS.MIT.EDU (Michael A. Patton) Newsgroups: comp.windows.x Subject: Handling expose events. Message-ID: <8908221732.AA28636@gaak.LCS.MIT.EDU> Date: 22 Aug 89 17:32:31 GMT References: <8908220058.AA08564@mote.umb.edu> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 51 I, too, have a program that draws on many different devices (although in my case X is the focus and therefore the structure is somewhat biased). My tool is also based on Xlib rather than a Toolkit (for historical reasons, I'm not sure which way I'd do it if I was starting over). I use a simple technique to achieve the goal you describe. I'll relate it here with a bit of the history of how it came about since that may aid you in understanding how to do it to your programs. At first (and I assume this is really the stage you're at now) I just redrew everything on any expose event. This initially didn't seem like a real problem since it only took a second or so, but if the user iconifies lots of other windows, each of which overlaps my application just a little bit, it redraws, and redraws, and ... I did put in some code so that if it gets behind, it doesn't redraw over and over, it gets all the events out of the queue before actually doing the redraw. But that still often meant three or so times which was a bit much. Since I assume you're really looking at much longer redraw times, you probably need the next inprovement that I mostly put in for a better "feel". The redraw algorithm already had a linked list of "things" to draw and it just iterated down it drawing them. Then as I started making the "things" on the screen mouse sensitive, I was keeping an extent independantly for each type that was. I moved this up into the "common" part of the structure and set it for all "things", if they weren't supposed to be active, I still knew what the user was pointing at and could produce better (sometimes) error reports. From here it was just a short step to having the handler for expose events iterate down the list and set a flag in any "things" that overlapped the region. Then the redraw routine looks at the flag to determine what really needs to be drawn. I also have a "force" argument to make it draw everything whether it needs it or not, for the initial draw and when (at user request) I wipe the screen and do a full redraw. I realize that this method as described does not specifically map to your application, but I hope it helps give you (and any others listening in) some ideas on how you might handle this problem in a reasonably efficient way without undue impact on the structure of the rest of your program. If you want to discuss any details of how you might apply this technique to your code, feel free to send me a note with more details and I'll see what I can do. I'm very familiar with how my system works, but not knowing how your programs are structured I can't really make any concrete suggestions. __ /| /| /| \ Michael A. Patton, Network Manager / | / | /_|__/ Laboratory for Computer Science / |/ |/ |atton Massachusetts Institute of Technology Disclaimer: The opinions expressed above are a figment of the phosphor on your screen and do not represent the views of MIT, LCS, or MAP. :-)