home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1993-1997 Fabrizio Oddone
- ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
- This source code is distributed as freeware:
- you may copy, exchange, modify this code.
- You may include this code in any kind of application: freeware,
- shareware, or commercial, provided that full credits are given.
- You may not sell or distribute this code for profit.
- */
-
- #include <Limits.h>
-
- #include "UtilsSys7.h"
-
- #include "TrackThumb.h"
-
- //#pragma segment Main
-
- short TrackThumb(ControlHandle control, Point start, void (*action)(ControlHandle, short))
- {
- enum {
- kTooDistant = 23
- };
-
- EventRecord dummyEventRec;
- Rect rct;
- GrafPtr savePort;
- Point pos;
- long newval;
- short val, old;
- short min, max;
- short widthOrheight;
-
- GetPort(&savePort);
- SetPort((*control)->contrlOwner);
- min = GetControlMinimum(control); // min value
- max = GetControlMaximum(control); // max value
- val = GetControlValue(control); // cur value
- rct = (*control)->contrlRect; // control's rectangle
-
- widthOrheight = rct.right - rct.left;
- old = SHRT_MIN;
- do {
- GetMouse(&pos);
-
- if (pos.v < rct.top + widthOrheight)
- pos.v = rct.top + widthOrheight;
- else if (pos.v > rct.bottom - widthOrheight)
- pos.v = rct.bottom - widthOrheight;
-
- if ((pos.h - rct.right) > kTooDistant || (rct.left - pos.h) > kTooDistant)
- newval = val;
- else {
- // newval = val + (max - min) * (pos.v - start.v) /
- // (rct.bottom - rct.top - widthOrheight - widthOrheight - widthOrheight);
- newval = val + AMultBDivC((max - min), (pos.v - start.v),
- (rct.bottom - rct.top - widthOrheight - widthOrheight - widthOrheight));
- if (newval < min)
- newval = min;
- else if (max < newval)
- newval = max;
- }
-
- if (newval != old) {
- SetControlValue(control, newval);
- action(control, old = GetControlValue(control));
- }
- else { /* give some time to other applications */
- SystemTask();
- (void)EventAvail(everyEvent, &dummyEventRec);
- }
- }
- while (StillDown());
- SetPort(savePort);
- return kControlIndicatorPart;
- }
-
-