From: Matthew Mastracci Newsgroups: comp.os.msdos.djgpp Subject: Re: Compiler bug in Allegro? Shawn, DJ? Date: Thu, 10 Apr 1997 21:34:08 -0600 Organization: The University of Calgary Lines: 41 Message-ID: References: <5ik06u$42q AT yayrap DOT cc DOT muroran-it DOT ac DOT jp> NNTP-Posting-Host: mmastrac AT acs2 DOT acs DOT ucalgary DOT ca Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <5ik06u$42q@yayrap.cc.muroran-it.ac.jp> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On Fri, 11 Apr 1997, Patrick G. Kutch wrote: > for (c=0; d[c].proc; c++) > if ((mouse_x >= d[c].x) && (mouse_y >= d[c].y) && > (mouse_x < d[c].x + d[c].w) && (mouse_y < d[c].y + d[c].h) && > (!(d[c].flags & (D_HIDDEN | D_DISABLED)))) > { > mouse_object = c; > break; > } > > return mouse_object; > However, this causes all kind of problems. After doing this, the > routine doesn't seem to work properly. The focus will be lost while > definitley moving over a button. I'm guessing that Allegro uses the last-in-first-to-get-focus stack. When you short-circuit the for-loop, some of the later objects lose their ability to get the focus. If you want to optimize this loop, set a pointer to the current last object in the list (maintain it too! :) and step backwards like so: for (c = last_element;; c--) if (blah) { mouse_object = c; break; } return mouse_object; This will act in the same way as the current Allegro proc. I'm not 100% sure that Allegro does it this way, but give it a try. :) /\/\att /\/\astracci mmastrac AT acs DOT ucalgary DOT ca GCS/GE d- s+:+ a--- C++++ UA P+ L E-- W+ N++ o K+ w+ O M- V PS++ PE++ Y+ PGP t+++ 5+++ X++ R++ tv+ b+++ DI++++ I G++ e h r* z?