Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!HLERUL5I.BITNET!laffra From: laffra@HLERUL5I.BITNET Newsgroups: comp.windows.x Subject: Re: rubberbanding with Xlib Message-ID: <8908290738.AA08852@rulcs.uucp> Date: 29 Aug 89 07:38:08 GMT Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 38 In response to: Does anyone have a good way of doing rubberbanding with Xlib, by good I mean where rubberband box keeps up with the cursor. The normal way of doing rubberbanding erasebox(flush buffer)-redrawbox(flush buffer)-erasebox.. requires a roundtrip for each request (batching requests makes it even worse) and the cursor is always ahead of the box being drawn. Has anyone worked a solution where rubberbanding box always tracks thr cursor very closely. There is a way: You have to make sure that you do not redraw your box with every motion event. What I generally do (and it works very nicely) is the following: XNextEvent(&event); switch( type_of(&event) ) { case MotionNotify : if (event_queue_is_empty_now()) { erase_box(...); draw(box(...); else ignore(); } The 'event_queue_is_empty_now()' function calls XPending() (XLib function). In this way you only redraw the box when the mouse pointer is not moving anymore. This reduce the delay of redrawing and the box will follow the cursor better. If your picture is very complicated you might want to test the queue for new motion event even while you are drawing the picture. The you do not finish the picture but erase the sofar drawn parts. Chris Laffra laffra@HLERUL5I.BITNET h