home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Aidan's Class Libraries / Source / Window & Dialog Classes / Offscreen.cpp < prev    next >
Encoding:
Text File  |  1997-07-20  |  3.2 KB  |  147 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "CLOffscreen.h"
  5. #include "CLLayout.h"
  6. #include "CLWindowDrawer.h"
  7.  
  8. TOffScreen::TOffScreen( SInt16 resID, TWindowLayer *layer, TLayoutLeaf *content ):
  9.     TBaseWindow( resID, layer, content )
  10. {
  11.     mWorld = 0l;
  12.     mhOldWorld = 0l;
  13.     mhOldDevice = 0l;
  14.     mhPixMap = 0l;
  15. }
  16.  
  17. TOffScreen::~TOffScreen()
  18. {
  19.     if( mWorld )
  20.         DisposeGWorld( mWorld );
  21. }
  22.  
  23. Boolean TOffScreen::GetDrawSelf()
  24. {
  25.     Boolean retVal;
  26.  
  27.     retVal= TBaseWindow::GetDrawSelf();
  28.     if( retVal )
  29.         if( mWorld ) {
  30.             ::GetGWorld( &mhOldWorld, &mhOldDevice );
  31.             ::SetGWorld( mWorld, 0l );
  32.             mhPixMap = ::GetGWorldPixMap( mWorld );
  33.             ::LockPixels( mhPixMap );
  34.         }
  35.     return( retVal );
  36. }
  37.  
  38. Boolean TOffScreen::ReleaseDrawSelf()
  39. {
  40.     if( mWorld ) {
  41.         ::SetGWorld( mhOldWorld, mhOldDevice );
  42.         ::UnlockPixels( mhPixMap );
  43.     }
  44.     return( TBaseWindow::ReleaseDrawSelf() );
  45. }
  46.  
  47. SInt8 TOffScreen::RespondResizeSelf( const Rect &oldRect, const Rect &newRect )
  48. {
  49.     GWorldPtr oldWorld;
  50.     GDHandle oldDevice;
  51.     PixMapHandle thePixMap;
  52.  
  53.     if( mWorld ) {
  54. //        ::UpdateGWorld( &mWorld, 0, &newRect, 0l, 0l, 0l );
  55.         DisposeGWorld( mWorld );
  56.         NewGWorld( &mWorld, 0, &newRect, 0l, 0l, 0l );
  57.     }
  58. //    if( !mWorld )
  59. //        NewGWorld( &mWorld, 4, &newRect, 0l, 0l, 0l );
  60.     TBaseWindow::RespondResizeSelf( oldRect, newRect );
  61. //    if( mWorld )
  62. //        Draw();
  63. }
  64.  
  65. SInt8 TOffScreen::DoUpdate()
  66. {
  67.     GrafPtr oldPort;
  68.  
  69.     BeginUpdate( mWindow );
  70.     ::GetPort( &oldPort );
  71.     ::SetPort( mWindow );
  72.     if( !mWorld )
  73.         Draw();
  74.     else {
  75.         if( mNeedWindowDrawers.MoveFirst() ) {
  76.             TWindowDrawer *iter;
  77.             do {
  78.                 mNeedWindowDrawers.GetData( iter );
  79.                 iter->DrawWindow( this );
  80.             } while( mNeedWindowDrawers.MoveNext() );
  81.         }
  82.         MarkChanged( GetWindowPort( mWindow )->portRect );
  83.     }
  84.     ::SetPort( oldPort );
  85.     EndUpdate( mWindow );
  86.     return( kWindowSuccess );
  87. }
  88.  
  89. SInt8 TOffScreen::DoShowWindow()
  90. {
  91.     TBaseWindow::DoShowWindow();
  92.     if( !mWorld )
  93.         NewGWorld( &mWorld, 0, &GetWindowPort( mWindow )->portRect, 0l, 0l, 0l );
  94.     if( !mWorld )
  95.         NewGWorld( &mWorld, 4, &GetWindowPort( mWindow )->portRect, 0l, 0l, 0l );
  96.     if( mWorld ) {
  97.         mhPixMap= ::GetGWorldPixMap( mWorld );
  98.         ::LockPixels( mhPixMap );
  99.         Draw();
  100.     }
  101. }
  102.  
  103. SInt8 TOffScreen::DoHideWindow()
  104. {
  105.     TBaseWindow::DoHideWindow();
  106.     if( mWorld ) {
  107.         DisposeGWorld( mWorld );
  108.         mWorld = 0l;
  109.     }
  110. }
  111.  
  112. void TOffScreen::MarkChanged( Rect rect )
  113. {
  114. //    GrafPtr oldPort;
  115. //
  116. //    ::GetPort( &oldPort );
  117. //    ::SetPort( mWindow );
  118. //    ::CopyBits( &((GrafPtr)mWorld)->portBits, &((GrafPtr)GetWindowPort( mWindow ))->portBits,
  119. //     &rect, &rect, srcCopy, 0l );
  120. //    ::SetPort( oldPort );
  121.     GrafPtr oldPort;
  122.     RgnHandle clipRgn, oldClip;
  123.  
  124.     ::GetPort( &oldPort );
  125.     ::SetPort( mWindow );
  126.     clipRgn= ::NewRgn();
  127.     oldClip= ::NewRgn();
  128.     ::RectRgn( clipRgn, &mWindow->portRect );
  129.     ::GetClip( oldClip );
  130.     if( mNeedWindowDrawers.MoveFirst() ) {
  131.         TWindowDrawer *iter;
  132.         RgnHandle cont= ::NewRgn();
  133.         do {
  134.             mNeedWindowDrawers.GetData( iter );
  135.             iter->GetClip( cont );
  136.             ::DiffRgn( clipRgn, cont, clipRgn );
  137.         } while( mNeedWindowDrawers.MoveNext() );
  138.         ::DisposeRgn( cont );
  139.     }
  140.     ::SetClip( clipRgn );
  141.     ::CopyBits( &((GrafPtr)mWorld)->portBits, &((GrafPtr)GetWindowPort( mWindow ))->portBits,
  142.      &rect, &rect, srcCopy, 0l );
  143.     ::SetClip( oldClip );
  144.     ::SetPort( oldPort );
  145.     ::DisposeRgn( oldClip );
  146.     ::DisposeRgn( clipRgn );
  147. }