home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Sample Code / Interapplication Communication / MenuScripter 4.0 / Sources / Offscreen.c < prev    next >
Encoding:
Text File  |  1996-07-09  |  1.9 KB  |  94 lines  |  [TEXT/CWIE]

  1. // Offscreen.c
  2. //
  3. // Original version by Jon Lansdell and Nigel Humphreys.
  4. // 3.1 updates by Greg Sutton.
  5. // ©Apple Computer Inc 1996, all rights reserved.
  6.  
  7.  
  8. #include "Offscreen.h"
  9.  
  10.  
  11. #ifndef __QUICKDRAW__
  12.     #include <Quickdraw.h>
  13. #endif
  14.  
  15. #ifndef __QDOFFSCREEN__
  16.     #include <QDOffscreen.h>
  17. #endif
  18.  
  19. #ifndef __MEMORY__
  20.     #include <Memory.h>
  21. #endif
  22.  
  23.  
  24. tWindowOffscreen* DrawOffscreen ( WindowRef theWindow )
  25. {
  26.     tWindowOffscreen*    theOffscreen;
  27.     GWorldPtr            theWorld;
  28.     Rect                globalRect;
  29.     
  30.     
  31.     theOffscreen = (tWindowOffscreen*) NewPtr ( sizeof ( tWindowOffscreen ) );
  32.     if ( theOffscreen == 0L )
  33.         return 0L;
  34.     
  35.     SetPort ( theWindow );
  36.     GetGWorld ( &theOffscreen->windowPort, &theOffscreen->windowDevice );
  37.     
  38.     globalRect = theWindow->portRect;
  39.     LocalToGlobal ( (Point*) &globalRect.top );
  40.     LocalToGlobal ( (Point*) &globalRect.bottom );
  41.     
  42.     if ( NewGWorld ( &theWorld, 0, &globalRect, 0L, 0L, 0) == noErr )
  43.     {
  44.         SetGWorld ( theWorld, 0L );
  45.         if ( !LockPixels ( theWorld->portPixMap ) )
  46.         {
  47.             DisposeOffscreen ( theOffscreen );
  48.             return 0L;
  49.         }
  50.         
  51.         CopyBits ( &theWindow->portBits, &((GrafPtr) theWorld)->portBits,
  52.                      &theWindow->portRect, &theWorld->portRect, srcCopy, 0L );
  53.         
  54.         theOffscreen->offscreenWorld = theWorld;
  55.         return theOffscreen;
  56.     }
  57.     
  58.     DisposePtr ( (Ptr) theOffscreen );
  59.     return 0L;
  60. }
  61.  
  62.  
  63.  
  64. tWindowOffscreen* DrawOnscreen ( tWindowOffscreen* theOffscreen )
  65. {
  66.     if ( theOffscreen )
  67.     {
  68.         SetGWorld ( theOffscreen->windowPort, theOffscreen->windowDevice );
  69.         CopyBits ( &((GrafPtr) theOffscreen->offscreenWorld)->portBits,
  70.                          (BitMap*) &(theOffscreen->windowPort)->portPixMap,
  71.                          &theOffscreen->offscreenWorld->portRect,
  72.                          &theOffscreen->windowPort->portRect,
  73.                         srcCopy, 0L );
  74.         UnlockPixels ( theOffscreen->offscreenWorld->portPixMap );
  75.         DisposeOffscreen ( theOffscreen );
  76.     }
  77.     
  78.     return nil;
  79. }
  80.  
  81.  
  82.  
  83. tWindowOffscreen* DisposeOffscreen ( tWindowOffscreen* theOffscreen )
  84. {
  85.     
  86.     DisposeGWorld ( theOffscreen->offscreenWorld );
  87.     DisposePtr ( (Ptr) theOffscreen );
  88.     
  89.     return nil;
  90. }
  91.  
  92.  
  93.  
  94.