Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!well!oster From: oster@well.sf.ca.us (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: How does one save/restore clipping? Message-ID: <22461@well.sf.ca.us> Date: 6 Jan 91 20:19:40 GMT References: <1CE00001.csbntk@tbomb.ice.com> <47697@apple.Apple.COM> Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 80 The update procedure for most of my panes just draws the frame, and recursively calls the update procedure in each of the sub-panes. Each sub pane does a : if(ClippedOff()){ return; } to avoid time-consuming drawing that won't show anyway. Each sub-pane sets the clip to the intersection of the old clip and the size of the sub-pane, and restores the clip when the update is finished. I use: /* RestrictClipRgn - set clip to intersection of old and new, and return old. */ public RgnHandle RestrictClipRgn(rgn)RgnHandle rgn;{ RgnHandle oldClip, smallClip; oldClip = NewRgn(); smallClip = NewRgn(); GetClip(oldClip); SectRgn(thePort->clipRgn, rgn, smallClip); SetClip(smallClip); DisposeRgn(smallClip); return oldClip; } /* RestrictClipRect - set clip to intersection of old and new, and return old. */ RgnHandle oldClip, smallClip; smallClip = NewRgn(); oldClip = RestrictClipRgn(smallClip); DisposeRgn(smallClip); return oldClip; } Which is fine, except for the outermost pane of the window. It uses: /* RestrictVisClipRgn - set clip to intersection of old and new, and return old. also clip off the visRgn */ private RgnHandle RestrictVisClipRgn(rgn)RgnHandle rgn;{ RgnHandle oldClip, smallClip; oldClip = NewRgn(); smallClip = NewRgn(); GetClip(oldClip); SectRgn(thePort->clipRgn, rgn, smallClip); SectRgn(thePort->visRgn, smallClip, smallClip); SetClip(smallClip); DisposeRgn(smallClip); return oldClip; } /* RestrictVisClipRect - set clip to intersection of old and new, and return old. also clip off the visRgn */ public RgnHandle RestrictVisClipRect(r)Rect *r;{ RgnHandle oldClip, smallClip; smallClip = NewRgn(); RectRgn(smallClip, r); oldClip = RestrictVisClipRgn(smallClip); DisposeRgn(smallClip); return oldClip; } So that if the window is partially obscured by another, the visRgn will be taken into account, by ClippedOff(). You should also do a SetOrigin() so each pane can have a local coordiante system starting at (0,0), and once again, you should set it on entry, and restore the old value on exit. If you don't call SetOrigin, then patteern fills after a small horizontal scroll are not likely to line up correctly. Clear? -- -- David Phillip Oster - At least the government doesn't make death worse. -- oster@well.sf.ca.us = {backbone}!well!oster