home *** CD-ROM | disk | FTP | other *** search
- ///////////////////////////////////////////////////////////////////////////////
- //
- // File: DrawingUtils.h
- //
- // Project: MacHack 2000 - Vertigo!
- // Authors: Darrin Cardani, Drew Thaler, Ed Wynne
- //
- // Date: 06/23/2000 (written entirely during the conference!)
- //
- ///////////////////////////////////////////////////////////////////////////////
-
- #ifndef _H_DrawingUtils
- #define _H_DrawingUtils
-
- #include <LowMem.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <Quickdraw.h>
- #include <QDOffscreen.h>
-
-
- // RegionList class, for managing lists of regions
- class RegionList
- {
- public:
- RegionList();
- ~RegionList();
-
- void Add(RgnHandle region, int duplicateRgn);
- void Remove(RgnHandle region, int dispose);
- void RemoveAll(int dispose);
-
- inline int GetCount() const { return mItemsInArray; };
- RgnHandle& operator[] (UInt32 index);
-
- protected:
- RgnHandle *mArray;
- RgnHandle mNull;
- Handle mArrayStorage;
- UInt32 mItemsInArray;
- UInt32 mCurrentArrayCapacity;
-
- private:
- RegionList(const RegionList&) {}
- };
-
-
- class StRegion
- {
- public:
- StRegion() { mRegion = NewRgn(); }
- StRegion(const StRegion &inRgn) { mRegion = NewRgn(); CopyRgn(inRgn.mRegion,mRegion); }
- StRegion(RgnHandle inRgn) { mRegion = NewRgn(); CopyRgn(inRgn,mRegion); }
- StRegion(const Rect &inRect) { mRegion = NewRgn(); RectRgn(mRegion,&inRect); }
- ~StRegion() { if (mRegion != NULL) DisposeRgn(mRegion); mRegion = NULL; }
-
- StRegion& operator = (const StRegion &inRgn) { if (this != &inRgn) CopyRgn(inRgn.mRegion,mRegion); return *this; }
- StRegion& operator = (RgnHandle inRgn) { if (inRgn == NULL) SetEmptyRgn(mRegion); else CopyRgn(inRgn,mRegion); return *this; }
- StRegion& operator = (const Rect &inRect) { RectRgn(mRegion,&inRect); return *this; }
-
- operator RgnHandle() const { return mRegion; }
- operator Handle() const { return (Handle)mRegion; }
-
- bool IsEmpty() const { return EmptyRgn(mRegion); }
- Rect &Bounds() const { return (**mRegion).rgnBBox; }
-
- StRegion& operator += (RgnHandle inRegion) { UnionRgn(mRegion, inRegion, mRegion); return *this; }
- StRegion& operator -= (RgnHandle inRegion) { DiffRgn(mRegion, inRegion, mRegion); return *this; }
- StRegion& operator &= (RgnHandle inRegion) { SectRgn(mRegion, inRegion, mRegion); return *this; }
- StRegion& operator |= (RgnHandle inRegion) { MacUnionRgn(mRegion, inRegion, mRegion); return *this; }
- StRegion& operator ^= (RgnHandle inRegion) { MacXorRgn(mRegion, inRegion, mRegion); return *this; }
- bool operator == (RgnHandle inRegion) const { return EqualRgn(mRegion, inRegion); }
- bool operator != (RgnHandle inRegion) const { return !EqualRgn(mRegion, inRegion); }
-
- StRegion& operator += (const Rect &inRect) { StRegion rgn(inRect); UnionRgn(mRegion,rgn,mRegion); return *this; }
- StRegion& operator -= (const Rect &inRect) { StRegion rgn(inRect); DiffRgn(mRegion,rgn,mRegion); return *this; }
- StRegion& operator &= (const Rect &inRect) { StRegion rgn(inRect); SectRgn(mRegion,rgn,mRegion); return *this; }
- StRegion& operator |= (const Rect &inRect) { StRegion rgn(inRect); UnionRgn(mRegion,rgn,mRegion); return *this; }
- StRegion& operator ^= (const Rect &inRect) { StRegion rgn(inRect); XorRgn(mRegion,rgn,mRegion); return *this; }
- bool operator == (const Rect &inRect) const { StRegion rgn(inRect); return EqualRgn(mRegion,rgn); }
- bool operator != (const Rect &inRect) const { StRegion rgn(inRect); return !EqualRgn(mRegion,rgn); }
-
- protected:
- RgnHandle mRegion;
- };
-
-
- class StSetGWorld
- {
- public:
- StSetGWorld(CGrafPtr port, GDHandle device = NULL) { GetGWorld(&mOldPort,&mOldDevice); SetGWorld(port,device); }
- ~StSetGWorld() { SetGWorld(mOldPort,mOldDevice); }
-
- protected:
- CGrafPtr mOldPort;
- GDHandle mOldDevice;
-
- private:
- StSetGWorld(const StSetGWorld&) {}
- };
-
-
- class StSetPort
- {
- public:
- StSetPort(GrafPtr port) { GetPort(&mOldPort); SetPort(port); }
- StSetPort(CGrafPtr port) { GetPort(&mOldPort); SetPort((GrafPtr)port); }
- ~StSetPort() { SetPort(mOldPort); }
-
- protected:
- GrafPtr mOldPort;
-
- private:
- StSetPort(const StSetPort&) {}
- };
-
-
- class StClipRgnState
- {
- public:
- StClipRgnState() { GetClip(mOldClip); mNewClip = mOldClip; }
- StClipRgnState(const Rect &clipRect) { GetClip(mOldClip); mNewClip = mOldClip; ClipTo(clipRect); }
- StClipRgnState(RgnHandle clipRgn) { GetClip(mOldClip); mNewClip = mOldClip; ClipTo(clipRgn); }
- ~StClipRgnState() { SetClip(mOldClip); }
-
- void ClipTo(const Rect &inRect) { mNewClip &= inRect; SetClip(mNewClip); }
- void ClipTo(RgnHandle inRgn) { mNewClip &= inRgn; SetClip(mNewClip); }
- bool IsEmpty() { return mNewClip.IsEmpty(); }
- void DontClip() { Rect wideOpen = {-32000,-32000,32000,32000}; mNewClip = wideOpen; SetClip(mNewClip); }
-
- protected:
- StRegion mOldClip;
- StRegion mNewClip;
-
- private:
- StClipRgnState(const StClipRgnState&) {}
- };
-
-
- class StGWorld
- {
- public:
- StGWorld(const GrafPtr sameSizeAsThis) { Create(sameSizeAsThis->portRect); }
- StGWorld(const CGrafPtr sameSizeAsThis) { Create(sameSizeAsThis->portRect); }
- StGWorld(const StGWorld &gworld) { Create(gworld.mGWorld->portRect); }
- StGWorld(const Rect &inRect) { Create(inRect); }
- ~StGWorld() { if (mGWorld) DisposeGWorld(mGWorld); mGWorld = NULL; }
-
- operator GWorldPtr() { return mGWorld; }
- operator BitMap*() { return &((GrafPtr)mGWorld)->portBits; }
-
- const Rect* PortRect() { return &mGWorld->portRect; }
-
- protected:
- GWorldPtr mGWorld;
-
- private:
- void Create(const Rect &inRect);
- };
-
-
- class StDisposeWindow
- {
- public:
- StDisposeWindow(const WindowPtr window) { mWindow = window; }
- ~StDisposeWindow() { DisposeWindow(mWindow); }
-
- protected:
- WindowPtr mWindow;
- };
-
-
- class StHideMenuBar
- {
- public:
- StHideMenuBar() {
- // Adjust the menu bar height
- mMenuBarHeight = GetMBarHeight();
- LMSetMBarHeight(0);
-
- // Re-add the menu bar to the gray rgn
- Rect mbarRect = qd.screenBits.bounds;
- mbarRect.bottom = mMenuBarHeight;
- mbarRect.right = qd.screenBits.bounds.right;
-
- StRegion newGrayRgn = mOldGrayRgn = GetGrayRgn();
- newGrayRgn += mbarRect;
- CopyRgn(newGrayRgn,GetGrayRgn());
-
- // Redraw
- DrawMenuBar();
- }
-
- ~StHideMenuBar() {
- CopyRgn(mOldGrayRgn,GetGrayRgn());
- LMSetMBarHeight(mMenuBarHeight);
- DrawMenuBar();
- }
-
- protected:
- short mMenuBarHeight;
- StRegion mOldGrayRgn;
- };
-
-
-
- inline void CopyGWorldToGWorld(const GWorldPtr inSrc, GWorldPtr inDst, RgnHandle maskRgn = NULL)
- {
- StSetGWorld setPort(inDst);
- ForeColor(blackColor);
- BackColor(whiteColor);
- CopyBits(&((GrafPtr)inSrc)->portBits,
- &((GrafPtr)inDst)->portBits,
- &inSrc->portRect,
- &inDst->portRect,
- srcCopy, maskRgn);
- }
-
- inline void CopyPortToGWorld(const GrafPtr inSrc, GWorldPtr inDst, RgnHandle maskRgn = NULL) { CopyGWorldToGWorld((GWorldPtr)inSrc,inDst,maskRgn); }
- inline void CopyPortToGWorld(const CGrafPtr inSrc, GWorldPtr inDst, RgnHandle maskRgn = NULL) { CopyGWorldToGWorld((GWorldPtr)inSrc,inDst,maskRgn); }
-
- inline void CopyGWorldToPort(const GWorldPtr inSrc, GrafPtr inDst, RgnHandle maskRgn = NULL)
- {
- StSetPort setPort(inDst);
- ForeColor(blackColor);
- BackColor(whiteColor);
- CopyBits(&((GrafPtr)inSrc)->portBits,
- &((GrafPtr)inDst)->portBits,
- &inSrc->portRect,
- &inDst->portRect,
- srcCopy, maskRgn);
- }
-
-
- #endif // _H_DrawingUtils
-
-