home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-22 | 2.0 KB | 103 lines | [TEXT/CWIE] |
- // ===========================================================================
- // UOffscreenUtils.h ©1999 Eric Traut
- // ===========================================================================
-
- /*------------------------------------------------------------------
- StGWorldLocker
-
- This class sets up the GWorld for drawing. Its constructor
- and destructor automatically handle the chore of saving and
- restoring the old GWorld and GDevice.
- ------------------------------------------------------------------*/
-
- class StGWorldLocker
- {
- public:
- inline
- StGWorldLocker (GWorldPtr inGWorld, Boolean inSetGWorld = true)
- {
- mActiveGWorldPixMap = ::GetGWorldPixMap (inGWorld);
- mSavedPixelsState = ::GetPixelsState (mActiveGWorldPixMap);
- ::LockPixels (mActiveGWorldPixMap);
-
- if (inSetGWorld)
- {
- ::GetGWorld (&mSavedGWorld, &mSavedDevice);
- ::SetGWorld (inGWorld, NULL);
- }
- else
- {
- mSavedGWorld = NULL;
- mSavedDevice = NULL;
- }
- }
-
- inline
- ~StGWorldLocker (void)
- {
- if (mSavedGWorld != NULL)
- ::SetGWorld (mSavedGWorld, mSavedDevice);
- ::SetPixelsState (mActiveGWorldPixMap, mSavedPixelsState);
- }
-
- inline UInt16
- GetRowBytes(void)
- {
- return (mActiveGWorldPixMap[0]->rowBytes & 0x3FFF);
- }
-
- inline UInt8 *
- GetBasePointer(void)
- {
- return (UInt8 *)(mActiveGWorldPixMap[0]->baseAddr);
- }
-
- inline PixMapHandle
- GetPixMap(void)
- {
- return mActiveGWorldPixMap;
- }
-
- inline void
- RestoreOldPort(void)
- {
- if (mSavedGWorld != NULL)
- ::SetGWorld (mSavedGWorld, mSavedDevice);
- mSavedGWorld = NULL;
- mSavedDevice = NULL;
- }
-
- private:
- GWorldFlags mSavedPixelsState;
- PixMapHandle mActiveGWorldPixMap;
- GWorldPtr mSavedGWorld;
- GDHandle mSavedDevice;
- };
-
-
- class StCPortSaver
- {
- public:
- StCPortSaver(void)
- {
- ::GetPort(&mSavedPort);
- }
-
- ~StCPortSaver(void)
- {
- ::SetPort(mSavedPort);
- }
-
- CGrafPtr
- GetSavedPort(void)
- {
- return reinterpret_cast<CGrafPtr>(mSavedPort);
- }
-
- private:
- GrafPtr mSavedPort;
- };
-
-
-
-