home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-26 | 5.0 KB | 289 lines | [TEXT/KAHL] |
-
- // utils
- #include <Picker.h>
- #include <GestaltEqu.h>
- #include <utils.h>
-
- // this is from the Think C reference code example ...
- // fixed by me later on
- unsigned short RangedRdm( unsigned short min, unsigned short max )
- /* assume that min is less than max */
- {
- // uh ... not this isn't quite right - it's between 0 and 65535, not 65536
- unsigned qdRdm; /* treat return value as 0-65536 */
- long range, t;
- unsigned short temp;
-
- if (min == max)
- return min;
-
-
- // just to be safe, I'll put this here
- if (min > max) {
- //DebugStr("\pMin greater then Max in RangedRdm");
- temp = min;
- min = max;
- max = temp;
- }
-
- qdRdm = Random();
- range = max - min;
- // max - min gives us the the difference between max and min ... that is
- // not inclusive. It gives us { min <= range < max }
- // so we never see that max number!!
- range++;
- t = ((long)qdRdm * range) / 65536; /* now 0 <= t <= range */
- return( t+min );
- }
-
-
- // this tests if a key is currently held down
- short isPressed(unsigned short k )
- // k = any keyboard scan code, 0-127
- {
- unsigned char km[16];
-
- GetKeys( (long *) km);
- return ( ( km[k>>3] >> (k & 7) ) & 1);
- }
-
-
- Boolean
- WNEAvailable(void) {
- SysEnvRec theSysEnv;
- Boolean wneAvail = FALSE;
-
- SysEnvirons( 1, &theSysEnv );
- if ( theSysEnv.machineType >= 1 ) {
- if ( NGetTrapAddress( 0xA860, 1 ) != 0xA89F )
- return TRUE;
- }
- return FALSE;
- }
-
-
- Boolean
- HasColorQD(void) {
- OSErr err;
- Boolean answer = true;
- long gestaltResult;
-
- err = Gestalt(gestaltQuickdrawVersion, &gestaltResult);
-
- answer = (err == noErr) && (gestaltResult >= gestalt8BitQD);
- return answer;
- }
-
-
- Boolean HasNewGWorld(void)
- {
- OSErr err;
- long gestaltResult;
-
- err = Gestalt(gestaltQuickdrawVersion, &gestaltResult);
-
- return (err == noErr) && (((gestaltResult > gestaltOriginalQD) &&
- (gestaltResult < gestalt8BitQD)) || (gestaltResult >= gestalt32BitQD));
- }
-
-
-
- void
- RandomIndexedColor(short screenDepth) {
- short numColors;
- RGBColor rgb;
-
- numColors = 1 << screenDepth;
- Index2Color( RangedRdm(1,numColors), &rgb );
- RGBForeColor( &rgb);
-
- }
-
-
-
- void
- SetIndexedColor(int whichColor) {
- RGBColor rgb;
-
- if (HasColorQD()) {
- Index2Color( whichColor, &rgb );
- RGBForeColor( &rgb);
- } else ForeColor(whiteColor);
- }
-
-
- void
- PickBrightRGB( RGBColor *rgb) {
- HSVColor hColor;
- hColor.hue = RangedRdm(0, 65535);
- hColor.saturation = (SmallFract)RangedRdm( 49150, 65535);
- hColor.value = (SmallFract) RangedRdm( 49150, 65535);
- HSV2RGB( &hColor, rgb);
- }
-
- void
- PickDarkRGB( RGBColor *rgb) {
- HSVColor hColor;
- hColor.hue = RangedRdm(0, 65535);
- hColor.saturation = (SmallFract)RangedRdm( 49150, 65535);
- hColor.value = (SmallFract) RangedRdm( 32767/2, 32767);
- HSV2RGB( &hColor, rgb);
- }
-
-
- void
- SetRandomDarkRGB(void) {
- RGBColor rColor;
-
- if (!HasColorQD()) {
- ForeColor(blackColor);
- } else {
- PickDarkRGB( &rColor);
- RGBForeColor( &rColor);
- }
- }
-
- void
- SetRandomBrightRGB(void) {
- RGBColor rColor;
-
- if (!HasColorQD()) {
- ForeColor(whiteColor);
- } else {
- PickBrightRGB( &rColor);
- RGBForeColor( &rColor);
- }
- }
-
-
- #define theLower(a, b) ( (a) < (b) ? (a) : (b) )
- #define abs(a) ((a) < 0 ? -(a) : (a))
-
- void
- SetColorDiff(
- RGBColor *rgbTheColor,
- RGBColor *a, RGBColor *b,
- double percent) {
- HSVColor ha, hb, hc;
-
- RGB2HSV( a, &ha);
- RGB2HSV( b, &hb);
-
- hc.hue = theLower(ha.hue, hb.hue) +
- (percent * abs( ha.hue - hb.hue) );
-
- hc.saturation = 65535;
- hc.value = 65535;
-
- HSV2RGB( &hc, rgbTheColor);
-
- }
-
- #if 0
- rgbTheColor->red = theLower(a->red, b->red) +
- (percent * abs( a->red - b->red ) );
-
- rgbTheColor->blue = theLower(a->blue, b->blue) +
- (percent * abs( a->blue - b->blue ) );
-
- rgbTheColor->green = theLower(a->green, b->green) +
- (percent * abs( a->green - b->green ) );
- #endif
-
-
-
-
- Boolean
- HasSoundInputDevice(void) {
- OSErr retCode;
- long feature;
-
- retCode = Gestalt(gestaltSoundAttr, &feature);
- if (retCode != noErr)
- return FALSE;
- else
- return (feature & (1 << gestaltHasSoundInputDevice));
- }
-
-
-
- // this assumes the port is set to the dialog box?
- void
- FlashDItem(DialogPtr dlg, int item)
- {
- long waste;
- short type;
- Handle theHandle;
- Rect iRect;
-
- GetDItem(dlg, item, &type, &theHandle, &iRect);
-
- HiliteControl( (ControlHandle)theHandle, inButton);
- Delay(2, &waste);
- HiliteControl( (ControlHandle)theHandle, 0);
-
- }
-
-
- void
- pstrcat(char *s1, char *s2)
- {
- register char *p;
- register short len, i;
-
- if (*s1+*s2<=255) {
- p = *s1 + s1 + 1;
- *s1 += (len = *s2++);
- }
- else {
- *s1 = 255;
- p = s1 + 256 - (len = *s2++);
- }
- for (i=len; i; --i) *p++ = *s2++;
- }
-
- void
- pstrcpy( char *s1, char *s2 )
- {
- register int length;
-
- for (length=*s2; length>=0; --length) *s1++=*s2++;
- }
-
-
- // has the system 7 time manager?
- Boolean HasTimeMgr(void)
- {
- OSErr err;
- Boolean isSystemGood = true;
- long gestaltResult;
-
- err = Gestalt(gestaltTimeMgrVersion, &gestaltResult);
-
- isSystemGood = (err == noErr) && (gestaltResult >= gestaltStandardTimeMgr);
-
- return isSystemGood;
- }
-
- long
- PickDarkIndexColor(void) {
- RGBColor rColor;
-
- PickDarkRGB( &rColor);
- return Color2Index( &rColor);
-
- }
-
-
- long
- PickBrightIndexColor(void) {
- RGBColor rColor;
-
- PickBrightRGB( &rColor);
- return Color2Index( &rColor);
-
- }
-
-
-
-