home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / COffScreenPicture 2.0 / COffScreenPicture.cp next >
Encoding:
Text File  |  1997-07-21  |  3.2 KB  |  117 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. // COffScreenPicture.cp
  3. // 
  4. // ©1997 Maxym Runov. All rights reserved.
  5. //
  6. // You are free to use this code in any project, 
  7. // but the copyright remains with me.
  8. // Any questions and notes are welcome.
  9. //
  10. // E-mail: max@sunbay.crimea.ua
  11. // ===========================================================================
  12. // Version 2.0
  13.  
  14. #include <LStream.h>
  15. #include "COffScreenPicture.h"
  16.  
  17.  
  18. // ---------------------------------------------------------------------------
  19. // Constructor
  20. // ---------------------------------------------------------------------------
  21.  
  22. COffScreenPicture::COffScreenPicture(LStream *inStream) : LView(inStream){
  23.     mGWorld            = 0;
  24.     
  25.     inStream->ReadData(&mPICTid, sizeof(ResIDT));
  26.     SetPictureID(mPICTid);
  27. };
  28.  
  29.  
  30. // ---------------------------------------------------------------------------
  31. // Destructor
  32. // ---------------------------------------------------------------------------
  33.  
  34. COffScreenPicture::~COffScreenPicture(void){
  35.     if(mGWorld) delete mGWorld;
  36. };
  37.  
  38.  
  39. #pragma mark -
  40.  
  41.  
  42. // ---------------------------------------------------------------------------
  43. // GetPictureID
  44. // ---------------------------------------------------------------------------
  45. //    Return the PICT Resource ID associated with a Picture
  46.  
  47. ResIDT    COffScreenPicture::GetPictureID(void){
  48.     return mPICTid;
  49. }
  50.  
  51.  
  52. // ---------------------------------------------------------------------------
  53. // SetPictureID
  54. // ---------------------------------------------------------------------------
  55. //    Set the PICT Resource ID associated with a Picture
  56.  
  57. void    COffScreenPicture::SetPictureID(ResIDT inPictureID){
  58.     if(mGWorld) delete mGWorld;
  59.     ResizeImageTo(0, 0, false);
  60.  
  61.     mPICTid = inPictureID;
  62.     PicHandle    hpic = ::GetPicture(mPICTid);
  63.     if(hpic){
  64.         HLock((Handle)hpic);
  65.         Rect     rect = (*hpic)->picFrame;
  66.         rect.right     -= rect.left;
  67.         rect.bottom -= rect.top;
  68.         rect.left     = 0;
  69.         rect.top     = 0;
  70.  
  71.         mGWorld    = new LGWorld(rect, 32);
  72.         if(mGWorld){
  73.             mGWorld->BeginDrawing();
  74.             ::DrawPicture(hpic, &rect);
  75.             mGWorld->EndDrawing();
  76.             ResizeImageTo(rect.right, rect.bottom, false);
  77.         }
  78.         HUnlock((Handle)hpic);
  79.         ReleaseResource((Handle)hpic);
  80.     }
  81. }
  82.  
  83.  
  84. #pragma mark -
  85.  
  86.                 
  87. // ---------------------------------------------------------------------------
  88. // DrawSelf
  89. // ---------------------------------------------------------------------------
  90.  
  91. void    COffScreenPicture::DrawSelf(void){
  92.     if(!mGWorld) return;
  93.     RgnHandle    localUpdateRgnH = GetLocalUpdateRgn();
  94.     if(!EmptyRgn(localUpdateRgnH)){
  95.         ApplyForeAndBackColors();
  96.         Rect        updateRect     = (**localUpdateRgnH).rgnBBox;
  97.         Rect        portRect     = (mGWorld->GetMacGWorld())->portRect;
  98.         
  99.         ::EraseRect(&updateRect);
  100.         if(updateRect.right > portRect.right) updateRect.right = portRect.right;
  101.         if(updateRect.bottom > portRect.bottom) updateRect.bottom = portRect.bottom;
  102.         
  103.         ::LockPixels(::GetGWorldPixMap(mGWorld->GetMacGWorld()));
  104.         ::LockPixels(::GetGWorldPixMap((CGrafPtr)GetMacPort()));
  105.         
  106.         ApplyForeAndBackColors();
  107.         ::CopyBits((BitMapPtr)&((mGWorld->GetMacGWorld())->portPixMap),
  108.             &(GetMacPort())->portBits,
  109.             &updateRect, &updateRect, srcCopy, nil);
  110.     
  111.         ::UnlockPixels(::GetGWorldPixMap(mGWorld->GetMacGWorld()));
  112.         ::UnlockPixels(::GetGWorldPixMap((CGrafPtr)GetMacPort()));
  113.     }
  114.     ::DisposeRgn(localUpdateRgnH);
  115. }
  116.  
  117.