home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / System Extensions / Macintosh Drag and Drop 1.1.1 / Demo Applications / DragText Sources / Offscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-12  |  1.5 KB  |  70 lines  |  [TEXT/KAHL]

  1. /*
  2.  *        Offscreen.c
  3.  */
  4.  
  5.  
  6. #include <QDOffscreen.h>
  7. #include "Offscreen.h"
  8.  
  9.  
  10. WindowOffscreen *DrawOffscreen(WindowPtr theWindow)
  11.  
  12. {    WindowOffscreen        *theOffscreen;
  13.     GWorldPtr            theWorld;
  14.     short                depth;
  15.     Rect                globalRect;
  16.  
  17.     if ((theOffscreen = (WindowOffscreen *) NewPtr(sizeof(WindowOffscreen))) == 0L)
  18.         return(0L);
  19.  
  20.     SetPort(theWindow);
  21.     GetGWorld(&theOffscreen->windowPort, &theOffscreen->windowDevice);
  22.  
  23.     globalRect = theWindow->portRect;
  24.     LocalToGlobal((Point *) &globalRect.top);
  25.     LocalToGlobal((Point *) &globalRect.bottom);
  26.  
  27.     if (NewGWorld(&theWorld, 0, &globalRect, 0L, 0L, 0) == noErr) {
  28.  
  29.         SetGWorld(theWorld, 0L);
  30.         if (! LockPixels(theWorld->portPixMap)) {
  31.             DisposeGWorld(theWorld);
  32.             DisposePtr(theOffscreen);
  33.             return(0L);
  34.         }
  35.  
  36.         CopyBits(&theWindow->portBits,
  37.                  &((GrafPtr) theWorld)->portBits,
  38.                  &theWindow->portRect,
  39.                  &theWorld->portRect,
  40.                  srcCopy, 0L);
  41.  
  42.         theOffscreen->offscreenWorld = theWorld;
  43.         return(theOffscreen);
  44.  
  45.     } else {
  46.  
  47.         DisposePtr(theOffscreen);
  48.         return(0L);
  49.  
  50.     }
  51. }
  52.  
  53.  
  54.  
  55. void DrawOnscreen(WindowOffscreen *theOffscreen)
  56.  
  57. {
  58.     if (theOffscreen) {
  59.         SetGWorld(theOffscreen->windowPort, theOffscreen->windowDevice);
  60.         CopyBits(&((GrafPtr) theOffscreen->offscreenWorld)->portBits,
  61.                  &(theOffscreen->windowPort)->portPixMap,
  62.                  &theOffscreen->offscreenWorld->portRect,
  63.                  &theOffscreen->windowPort->portRect,
  64.                  srcCopy, 0L);
  65.         UnlockPixels(theOffscreen->offscreenWorld->portPixMap);
  66.         DisposeGWorld(theOffscreen->offscreenWorld);
  67.         DisposePtr((Ptr) theOffscreen);
  68.     }
  69. }
  70.