home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!olivea!apple!goofy!kip-56.apple.com!chris_russo
- From: chris_russo@gateway.qm.apple.com (Christopher Russo)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: Offscreen PixMaps: dumb question
- Message-ID: <34528@goofy.apple.COM>
- Date: 13 Jan 93 00:06:22 GMT
- References: <1993Jan12.113345.501@otago.ac.nz>
- Sender: usenet@goofy.apple.COM
- Organization: Apple
- Lines: 52
-
- In article <1993Jan12.113345.501@otago.ac.nz> John Marshall,
- jomar@otago.ac.nz writes:
- >However, I've read IM IV (I can be System 7 only if I want) and been
- >horrified by the incomprehensible talk of Offscreen Graphics Worlds and
- >Offscreen CPorts and so on.
-
- I totally agree. I'd been working with offscreen CPorts for a while and
- felt that they're GWorld help was fairly nebulous. I pulled out the
- folllowing routine from something I had handy. I don't think there are
- any glaring bugs in it although it does lack generallity. It will
- allocate an offscreen 8bit color port of the height and width (in pixels)
- that you hand in.
-
- /* Takes shorts of width and height then returns a CGrafPtr
- */
- CGrafPtr MyNewPort(short theWidth, short theHeight)
- {
- CGrafPtr aCGrafPtr;
- Ptr aPtr;
- Rect aRect;
-
-
- aPtr = NewPtr(sizeof(CGrafPort));
- aCGrafPtr = (CGrafPtr) aPtr;
-
- OpenCPort(aCGrafPtr);
- SetRect(&aRect,0,0,theWidth,theHeight);
- (**(*aCGrafPtr).portPixMap).bounds = aRect;
- (**(*aCGrafPtr).portPixMap).rowBytes = 0x8000 + theWidth;
- (*aCGrafPtr).portRect = aRect;
-
- aPtr = NewPtr((long)theWidth * (long)theHeight);
- (**(*aCGrafPtr).portPixMap).baseAddr = aPtr;
-
- OpenRgn();
- FrameRect(&aRect);
- CloseRgn((*aCGrafPtr).visRgn);
- EraseRect(&(*aCGrafPtr).portRect);
- return aCGrafPtr;
- }
-
- YUCK. It's been SOOO long since I've even looked at this routine. I wrote
- it when I was first learning the Mac & C. I'd change some of the style
- for you, but I'm afraid to introduce an error in haste. Oh well, take it
- for what it's worth. Anyway, you can draw to and from the port returned
- just like you draw to and from any other.
-
- I'll leave multiple bit depths up to you as a programming exercise. :-)
- to be read: "I'm lazy."
- -----Christopher Russo
- ----- I admire a clever .sig message. Wish I had one. <sigh>
- ----- day 408.974.6070
-