Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!hacgate!ashtate!dbase!awd From: awd@dbase.UUCP (Alastair Dallas) Newsgroups: comp.sys.mac.programmer Subject: TrackButton() Keywords: Anyone want to help polish some code? Message-ID: <128@dbase.UUCP> Date: 26 Jun 89 20:42:08 GMT Organization: Ashton Tate Devlopment Center Glendale, Calif. Lines: 46 It occurred to me that the following simple function might be interesting to the net. The first version was considerably longer and it got polished down to this, so I thought I'd invite the net to critique it and help _really_ polish it. I have a fondness for "lapidary code." Boolean TrackButton(button) Rect *button; { Boolean wasIN = FALSE; Point mouse; while (StillDown()) { GetMouse(&mouse); if (PtInRect(mouse, button) != wasIN) { InvertRect(button); wasIN = !wasIN; } } if (wasIN) InvertRect(button); return (wasIN); } /* TrackButton */ This does the job using THINK C v3.0. I'd be interested to hear of any language incompatibilities, etc. that would make it non-portable. Also, the various toolbox routines that Track.. things usually take an initial point as an argument--why is this? Finally, any thoughts about how to make the button flash before returning TRUE? My current solution (not shown) is pretty crude and I'd like to be more Mac-family-clean (isn't there a parameter RAM setting or something?) By the way, I'm not missing something obvious, am I? I mean, the Control Manager seems like a lot of overkill to handle a simple (and custom) button or two. Should I write a CDEF for this? Anyway. Comments are welcome... /alastair/