home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-16 | 3.0 KB | 126 lines | [TEXT/MACA] |
- //**********************************
- //* Depth-Switcher *
- //* A SAT Add-On by: *
- //* *
- //* Richard F. Bannister *
- //* Titan Software *
- //* 76 Stillorgan Wood *
- //* Stillorgan, Co. Dublin *
- //* Republic of Ireland *
- //* *
- //* http://aoife.indigo.ie/~titan/ *
- //* mailto:titan@indigo.ie *
- //**********************************
-
- /* Modified by Ingemar to be fully non-CQD compatible. */
-
-
- #include "SAT.h"
- #include "Palettes.h"
-
- GDHandle thisGDevice;
-
- static Boolean HasCQD(void)
- {
- SysEnvRec thisWorld;
-
- if (SysEnvirons(1, &thisWorld) != noErr) return false;
- return thisWorld.hasColorQD;
- }
-
- short SATGetDepth (void)
- {
- short thisDepth;
- char wasState;
-
- if (!HasCQD()) return 1;
-
- thisGDevice=GetMainDevice();
-
- if (thisGDevice != nil)
- {
- wasState = HGetState((Handle)thisGDevice);
- HLock((Handle)thisGDevice);
- thisDepth = (**(**thisGDevice).gdPMap).pixelSize;
- HSetState((Handle)thisGDevice, wasState);
- }
-
- return (thisDepth);
- }
-
- static Boolean CanWeSwitch (GDHandle theDevice,short wantedDepth)
- {
- short canDepth;
- Boolean canDo;
-
- // if (!HasCQD()) return (wantedDepth != 1);
-
- canDo = FALSE;
- canDepth = HasDepth(theDevice, wantedDepth, 1, 0);
- if (canDepth != 0)
- canDo = TRUE;
-
- return (canDo);
- }
-
- static void SwitchToDepth (short newDepth, Boolean doColor)
- {
- OSErr theErr;
- short colorFlag;
- char tagByte;
-
- // if (!HasCQD()) return;
-
- if (doColor)
- colorFlag = 1;
- else
- colorFlag = 0;
-
- if (thisGDevice != nil)
- {
- tagByte = HGetState((Handle)thisGDevice);
- HLock((Handle)thisGDevice);
- theErr = SetDepth(thisGDevice, newDepth, 1, colorFlag);
- HSetState((Handle)thisGDevice, tagByte);
- }
- }
-
- void SATRestoreDepth (short old)
- {
- if (!HasCQD()) return;
-
- thisGDevice = GetMainDevice();
-
- if (CanWeSwitch(thisGDevice,old))
- SwitchToDepth(old, TRUE);
- else
- SysBeep(1);
- }
-
- Boolean SATSetDepth (short DepthWanted)
- {
- short wasDepth;
-
- if (!HasCQD()) return false;
-
- thisGDevice = GetMainDevice();
-
- wasDepth = SATGetDepth();
- if (wasDepth != DepthWanted)
- {
- if (CanWeSwitch(thisGDevice,DepthWanted))
- {
- SwitchToDepth(DepthWanted, TRUE);
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
-