home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / Offscreen.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  2.4 KB  |  132 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Offscreen.cp
  3.  
  4.     Contains:    Class to help with offscreen drawing.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #include "Offscreen.h"
  28. #include "ColorPenState.h"
  29.  
  30. Offscreen::Offscreen()
  31. {
  32.     fWorld = nil;
  33.     fSavePort = nil;
  34.     fSaveDevice = nil;
  35.     SetRect( &fBounds, 0, 0, 0, 0 );
  36. }
  37.  
  38. Offscreen::~Offscreen()
  39. {
  40. }
  41.  
  42. void
  43. Offscreen::StartDrawing( const Rect& bounds, Boolean copyDest )
  44. {
  45.     QDErr            err;
  46.     Rect            globalRect;
  47.     ColorPenState    state;
  48.     
  49.     fBounds = bounds;
  50.     
  51.     GetGWorld( &fSavePort, &fSaveDevice );
  52.     
  53.     globalRect = fBounds;
  54.     
  55.     LocalToGlobal( &topLeft( globalRect ) );
  56.     LocalToGlobal( &botRight( globalRect ) );
  57.  
  58.     err = NewGWorld( &fWorld, 0, &globalRect, nil, nil, 0 );
  59.     if ( err == noErr )
  60.     {
  61.         GetColorAndPenState( &state );
  62.         SetGWorld( fWorld, nil );
  63.         SetOrigin( fBounds.left, fBounds.top );
  64.         SetColorAndPenState( &state );
  65.         
  66.         LockPixels( GetGWorldPixMap( fWorld ) );
  67.         EraseRect( &fBounds );
  68.         TextFont( fSavePort->txFont );
  69.         TextSize( fSavePort->txSize );
  70.         TextFace( fSavePort->txFace );
  71.         TextMode( fSavePort->txMode );
  72.         
  73.         if ( copyDest )
  74.         {
  75.             CopyBits( (BitMap*)*fSavePort->portPixMap, (BitMap*)*fWorld->portPixMap,
  76.                 &fBounds, &fWorld->portRect, srcCopy, nil );
  77.         }
  78.     }
  79.     else
  80.         fWorld = nil; // make sure
  81. }
  82.  
  83. void
  84. Offscreen::EndDrawing()
  85. {
  86.     ColorPenState    state;
  87.     
  88.     if ( fWorld == nil ) return;
  89.     
  90.     SetOrigin( 0, 0 );
  91.     SetGWorld( fSavePort, fSaveDevice );
  92.  
  93.     GetColorAndPenState( &state );
  94.     NormalizeColorAndPen();
  95.     
  96.     CopyBits( (BitMap*)&fWorld->portPixMap, (BitMap*)&fSavePort->portPixMap,
  97.             &fWorld->portRect, &fBounds, srcCopy, NULL );
  98.  
  99.     UnlockPixels( GetGWorldPixMap( fWorld ) );
  100.     DisposeGWorld( fWorld );
  101.     
  102.     fWorld = nil;
  103.     
  104.     SetColorAndPenState( &state );
  105. }
  106.  
  107. void
  108. Offscreen::EndDrawingAndBlend( const RGBColor& opColor )
  109. {
  110.     ColorPenState    state;
  111.     
  112.     if ( fWorld == nil ) return;
  113.     
  114.     SetOrigin( 0, 0 );
  115.     SetGWorld( fSavePort, fSaveDevice );
  116.  
  117.     GetColorAndPenState( &state );
  118.     NormalizeColorAndPen();
  119.     
  120.     OpColor( &opColor );
  121.     CopyBits( (BitMap*)&fWorld->portPixMap, (BitMap*)&fSavePort->portPixMap,
  122.             &fWorld->portRect, &fBounds, blend, NULL );
  123.  
  124.     UnlockPixels( GetGWorldPixMap( fWorld ) );
  125.     DisposeGWorld( fWorld );
  126.     
  127.     fWorld = nil;
  128.     
  129.     SetColorAndPenState( &state );
  130. }
  131.  
  132.