home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21326 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  2.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!olivea!apple!goofy!kip-56.apple.com!chris_russo
  2. From: chris_russo@gateway.qm.apple.com (Christopher Russo)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Offscreen PixMaps: dumb question
  5. Message-ID: <34528@goofy.apple.COM>
  6. Date: 13 Jan 93 00:06:22 GMT
  7. References: <1993Jan12.113345.501@otago.ac.nz>
  8. Sender: usenet@goofy.apple.COM
  9. Organization: Apple
  10. Lines: 52
  11.  
  12. In article <1993Jan12.113345.501@otago.ac.nz> John Marshall, 
  13. jomar@otago.ac.nz writes:
  14. >However, I've read IM IV (I can be System 7 only if I want) and been
  15. >horrified by the incomprehensible talk of Offscreen Graphics Worlds and
  16. >Offscreen CPorts and so on.
  17.  
  18. I totally agree.  I'd been working with offscreen CPorts for a while and 
  19. felt that they're GWorld help was fairly nebulous.  I pulled out the 
  20. folllowing routine from something I had handy.  I don't think there are 
  21. any glaring bugs in it although it does lack generallity.  It will 
  22. allocate an offscreen 8bit color port of the height and width (in pixels) 
  23. that you hand in.
  24.  
  25. /* Takes shorts of width and height then returns a CGrafPtr 
  26. */
  27. CGrafPtr MyNewPort(short theWidth, short theHeight)
  28. {
  29.     CGrafPtr aCGrafPtr;
  30.     Ptr aPtr;
  31.     Rect aRect;
  32.     
  33.     
  34.     aPtr = NewPtr(sizeof(CGrafPort));
  35.     aCGrafPtr = (CGrafPtr) aPtr;
  36.     
  37.     OpenCPort(aCGrafPtr);
  38.     SetRect(&aRect,0,0,theWidth,theHeight);
  39.     (**(*aCGrafPtr).portPixMap).bounds = aRect;
  40.     (**(*aCGrafPtr).portPixMap).rowBytes = 0x8000 + theWidth;
  41.     (*aCGrafPtr).portRect = aRect;
  42.     
  43.     aPtr = NewPtr((long)theWidth * (long)theHeight);
  44.     (**(*aCGrafPtr).portPixMap).baseAddr = aPtr;
  45.     
  46.     OpenRgn();
  47.     FrameRect(&aRect);
  48.     CloseRgn((*aCGrafPtr).visRgn);
  49.     EraseRect(&(*aCGrafPtr).portRect);
  50.     return aCGrafPtr;
  51. }
  52.  
  53. YUCK. It's been SOOO long since I've even looked at this routine. I wrote 
  54. it when I was first learning the Mac & C.  I'd change some of the style 
  55. for you, but I'm afraid to introduce an error in haste.  Oh well, take it 
  56. for what it's worth.  Anyway, you can draw to and from the port returned 
  57. just like you draw to and from any other.
  58.  
  59. I'll leave multiple bit depths up to you as a programming exercise. :-)
  60. to be read: "I'm lazy."
  61. -----Christopher Russo
  62. ----- I admire a clever .sig message.  Wish I had one. <sigh>
  63. ----- day 408.974.6070
  64.