Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!lll-winken!ames!oliveb!felix!dhw68k!thecloud From: thecloud@dhw68k.cts.com (Ken McLeod) Newsgroups: comp.sys.mac.programmer Subject: Re: CDEF's Message-ID: <19324@dhw68k.cts.com> Date: 29 Jan 89 20:15:51 GMT References: <5631@paris.ics.uci.edu> Reply-To: thecloud@dhw68k.cts.com (Ken McLeod) Organization: Wolfskill & Dowling residence; Anaheim, CA (USA) Lines: 66 In article <5631@paris.ics.uci.edu> Petey O'Leary writes: > > I am trying to code a simple CDEF that is exactly like the standard >push-button, only with square instead of rounded corners. The CDEF that >I have functions except that no "tracking" seems to be done when I >click in the control. By this I mean that when I click in the button, >it is not inverted and it seems that action takes place on the mouse- >down rather than the mouse-up, like a standard push-button. It sounds like a CDEF may be overkill for what you want to do. Here's a simple function I use for tracking rectangular buttons (replace the calls to InvertRect() with InvertOval() if you want a circular button, and so on). /*===================================================================*/ short TrackButton () /* called when we determine that a mouseDown has occurred in the rect of our 'pseudo-button'; handles button tracking until the mouse is up, then returns 1 (true) if the mouse was released inside the button, or 0 (false) if released outside the button. */ { short itemtype, struck; Handle itemhand; Rect itemrect; Point mPt; /* set up 'itemrect' to be your button's rectangle here; you could also pass it as a parameter to this function if you wanted */ InsetRect(&itemrect, 1, 1); InvertRect(&itemrect); struck = 1; /* used to track inverted state */ while (Button()) { GetMouse(&mPt); if (PtInRect(mPt, &itemrect)) { if (!struck) { InvertRect(&itemrect); struck = !struck; } } else if (!(PtInRect(mPt, &itemrect))) { if (struck) { InvertRect(&itemrect); struck = !struck; } } } if (struck) { /* mouse was released in button box */ InvertRect(&itemrect); return(1); } else return(0); } /*===================================================================*/ Hope that helps... -ken -- ========== ....... ============================================= Ken McLeod :. .: felix!dhw68k!thecloud@ics.uci.edu ========== :::.. ..::: InterNet: thecloud@dhw68k.cts.com //// =============================================