GliderPRO/Sources/Utilities.c

1 line
19 KiB
C
Raw Normal View History

//============================================================================ //---------------------------------------------------------------------------- // Utilities.c //---------------------------------------------------------------------------- //============================================================================ #include <Icons.h> #include <NumberFormatting.h> #include <Resources.h> #include <Sound.h> #include <TextUtils.h> #include <ToolUtils.h> #include "Externs.h" #include "Utilities.h" GDHandle thisGDevice; UInt32 theSeed; extern Boolean switchedOut; //============================================================== Functions //-------------------------------------------------------------- MyGetGlobalMouse // Returns the position of the mouse in global coordinates. Point MyGetGlobalMouse (void) { Point localWhere; GetMouse(&localWhere); LocalToGlobal(&localWhere); return (localWhere); } //-------------------------------------------------------------- ToolBoxInit // The standard ToolBox intialization that must happen when any Mac<61> // program first launches. void ToolBoxInit (void) { #if !TARGET_CARBON InitGraf(&qd.thePort); InitFonts(); FlushEvents(everyEvent, 0); InitWindows(); InitMenus(); TEInit(); InitDialogs(nil); MaxApplZone(); MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters(); GetDateTime((UInt32 *)&qd.randSeed); #endif InitCursor(); switchedOut = false; } //-------------------------------------------------------------- RandomInt // Returns a random integer (short) within "range". short RandomInt (short range) { register long rawResult; rawResult = Random(); if (rawResult < 0L) rawResult *= -1L; rawResult = (rawResult * (long)range) / 32768L; return ((short)rawResult); } //-------------------------------------------------------------- RandomLong // Returns a random long interger within "range". long RandomLong (long range) { register long highWord, lowWord; register long rawResultHi, rawResultLo; highWord = (range & 0xFFFF0000) >> 16; lowWord = range & 0x0000FFFF; rawResultHi = Random(); if (rawResultHi < 0L) rawResultHi *= -1L; rawResultHi = (rawResultHi * highWord) / 32768L; rawResultLo = Random(); if (rawResultLo < 0L) rawResultLo *= -1L; rawResultLo = (rawResultLo * lowWord) / 32768L; rawResultHi = (rawResultHi << 16) + rawResultLo; return (rawResultHi); } //-------------------------------------------------------------- InitRandomLongQUS // Initializes random seed for quick & dirty long random number function (below). void InitRandomLongQUS (void) { GetDateTime(&theSeed); } //-------------------------------------------------------------- RandomLongQUS // Very simple (but fast) pseudo-random number generator. UInt32 RandomLongQUS (void) { theSeed = theSeed * 1103515245 + 12345; return (theSeed); } //-------------------------------------------------------------- RedAlert // Called when we must quit app. Brings up a dialog informing user<65> // of the problem and the exits to shell. void RedAlert (short errorNumber) { #define rDeathAlertID 170 // alert res. ID for death error #define rErrTitleID 170 // string ID for death error title #define rErrMssgID 171 // string ID for death error message short dummyInt; Str255 errTitle, errMessage, errNumberString; InitCursor(); if (errorNumber > 1) // <= 0 is unaccounted for { GetIndString(errTitle, rErrTitleID, errorNumber); GetIndString(errMessage, rErrMssgID, errorNumber); } else { GetIndString(errTitle, rErrTitleID, 1); GetIndString(errMessage, rErrMssgID, 1); } NumToString((long)errorNumber, errNumberString); ParamText(errTitle, errMessage, errNumberString, "\p"); // CenterAlert(rDeathAlertID); dummyInt = Alert(rDeathAlertID, nil); ExitToShell(); } //-------------------------------------------------------------- FindOurDevice // Finds the main device (monitor with the menu bar on it). void FindOurDevice (void) { thisGDevice = GetMainDevice(); if (thisGDevice == nil) RedAlert(k