home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-20 | 3.2 KB | 147 lines | [TEXT/CWIE] |
- //Copyright (c) 1997 Aidan Cully
- //All rights reserved
-
- #include "CLOffscreen.h"
- #include "CLLayout.h"
- #include "CLWindowDrawer.h"
-
- TOffScreen::TOffScreen( SInt16 resID, TWindowLayer *layer, TLayoutLeaf *content ):
- TBaseWindow( resID, layer, content )
- {
- mWorld = 0l;
- mhOldWorld = 0l;
- mhOldDevice = 0l;
- mhPixMap = 0l;
- }
-
- TOffScreen::~TOffScreen()
- {
- if( mWorld )
- DisposeGWorld( mWorld );
- }
-
- Boolean TOffScreen::GetDrawSelf()
- {
- Boolean retVal;
-
- retVal= TBaseWindow::GetDrawSelf();
- if( retVal )
- if( mWorld ) {
- ::GetGWorld( &mhOldWorld, &mhOldDevice );
- ::SetGWorld( mWorld, 0l );
- mhPixMap = ::GetGWorldPixMap( mWorld );
- ::LockPixels( mhPixMap );
- }
- return( retVal );
- }
-
- Boolean TOffScreen::ReleaseDrawSelf()
- {
- if( mWorld ) {
- ::SetGWorld( mhOldWorld, mhOldDevice );
- ::UnlockPixels( mhPixMap );
- }
- return( TBaseWindow::ReleaseDrawSelf() );
- }
-
- SInt8 TOffScreen::RespondResizeSelf( const Rect &oldRect, const Rect &newRect )
- {
- GWorldPtr oldWorld;
- GDHandle oldDevice;
- PixMapHandle thePixMap;
-
- if( mWorld ) {
- // ::UpdateGWorld( &mWorld, 0, &newRect, 0l, 0l, 0l );
- DisposeGWorld( mWorld );
- NewGWorld( &mWorld, 0, &newRect, 0l, 0l, 0l );
- }
- // if( !mWorld )
- // NewGWorld( &mWorld, 4, &newRect, 0l, 0l, 0l );
- TBaseWindow::RespondResizeSelf( oldRect, newRect );
- // if( mWorld )
- // Draw();
- }
-
- SInt8 TOffScreen::DoUpdate()
- {
- GrafPtr oldPort;
-
- BeginUpdate( mWindow );
- ::GetPort( &oldPort );
- ::SetPort( mWindow );
- if( !mWorld )
- Draw();
- else {
- if( mNeedWindowDrawers.MoveFirst() ) {
- TWindowDrawer *iter;
- do {
- mNeedWindowDrawers.GetData( iter );
- iter->DrawWindow( this );
- } while( mNeedWindowDrawers.MoveNext() );
- }
- MarkChanged( GetWindowPort( mWindow )->portRect );
- }
- ::SetPort( oldPort );
- EndUpdate( mWindow );
- return( kWindowSuccess );
- }
-
- SInt8 TOffScreen::DoShowWindow()
- {
- TBaseWindow::DoShowWindow();
- if( !mWorld )
- NewGWorld( &mWorld, 0, &GetWindowPort( mWindow )->portRect, 0l, 0l, 0l );
- if( !mWorld )
- NewGWorld( &mWorld, 4, &GetWindowPort( mWindow )->portRect, 0l, 0l, 0l );
- if( mWorld ) {
- mhPixMap= ::GetGWorldPixMap( mWorld );
- ::LockPixels( mhPixMap );
- Draw();
- }
- }
-
- SInt8 TOffScreen::DoHideWindow()
- {
- TBaseWindow::DoHideWindow();
- if( mWorld ) {
- DisposeGWorld( mWorld );
- mWorld = 0l;
- }
- }
-
- void TOffScreen::MarkChanged( Rect rect )
- {
- // GrafPtr oldPort;
- //
- // ::GetPort( &oldPort );
- // ::SetPort( mWindow );
- // ::CopyBits( &((GrafPtr)mWorld)->portBits, &((GrafPtr)GetWindowPort( mWindow ))->portBits,
- // &rect, &rect, srcCopy, 0l );
- // ::SetPort( oldPort );
- GrafPtr oldPort;
- RgnHandle clipRgn, oldClip;
-
- ::GetPort( &oldPort );
- ::SetPort( mWindow );
- clipRgn= ::NewRgn();
- oldClip= ::NewRgn();
- ::RectRgn( clipRgn, &mWindow->portRect );
- ::GetClip( oldClip );
- if( mNeedWindowDrawers.MoveFirst() ) {
- TWindowDrawer *iter;
- RgnHandle cont= ::NewRgn();
- do {
- mNeedWindowDrawers.GetData( iter );
- iter->GetClip( cont );
- ::DiffRgn( clipRgn, cont, clipRgn );
- } while( mNeedWindowDrawers.MoveNext() );
- ::DisposeRgn( cont );
- }
- ::SetClip( clipRgn );
- ::CopyBits( &((GrafPtr)mWorld)->portBits, &((GrafPtr)GetWindowPort( mWindow ))->portBits,
- &rect, &rect, srcCopy, 0l );
- ::SetClip( oldClip );
- ::SetPort( oldPort );
- ::DisposeRgn( oldClip );
- ::DisposeRgn( clipRgn );
- }