home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 8.7 KB | 350 lines | [TEXT/CWIE] |
- //===================================================================
- //======================= Headers =============================
-
- #include "Screen.h"
- #include "GameUtilities.h"
- #include "ApplicationHandler.h"
- #include "MenuBar.h"
- #include "Quickdraw.h"
-
- //===================================================================
- //======================= Globals =============================
-
- COSScreen screen;
-
-
- //===================================================================
- //======================= #define =============================
-
-
- //===================================================================
- //======================= Function Prototypes =====================
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: Constructor
-
- \----------------------------------------------------------------------------*/
- COSScreen :: COSScreen( void )
- {
- numUpdate = 0;
- drawAll = false;
- MySetRect( &screenSize , 0 , 0 , 1024 , 768 );
- MySetRect( &viewArea , 0 , 20 , 1024, 768);
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: Deconstructor
-
- \----------------------------------------------------------------------------*/
- COSScreen :: ~COSScreen( void )
- {
- LMSetMBarHeight( OldMBarHeight );
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: InitScreen
-
- \----------------------------------------------------------------------------*/
- Boolean COSScreen :: InitScreen( void )
- {
- OldMBarHeight = LMGetMBarHeight();
- LMSetMBarHeight( 0 );
-
- // first center the window
- Rect myScreenBoundsRect;
- short mX,mY;
- rect bounds;
-
- bounds = screenSize;
-
- // bounds.top += 20;
- // bounds.bottom += 20;
-
- mX = rToR( bounds).right - rToR( bounds).left; // find the width
- mY = rToR( bounds).bottom - rToR( bounds).top; // find the hieght,
-
- myScreenBoundsRect = qd.screenBits.bounds; // get the screens rect
-
- rToR( bounds).left = ((myScreenBoundsRect.right - myScreenBoundsRect.left) >> 1 ) - (mX>>1);
- rToR( bounds).top = ((myScreenBoundsRect.bottom - ( myScreenBoundsRect.top )) >> 1 ) - (mY>>1);
- rToR( bounds).right = bounds.left + mX;
- rToR( bounds).bottom = bounds.top + mY;
-
- // now make the window
- screen = NewCWindow( nil,
- & rToR(bounds),
- "\p",
- true,
- plainDBox,
- WindowPtr( -1 ),
- false,
- nil );
- if( screen == NULL )
- return false;
-
- bounds.right -= bounds.left;
- bounds.bottom -= bounds.top;
- bounds.left = 0;
- bounds.top = 0;
-
- ClipRect( & rToR( bounds ) );
-
-
- Rect mBarRect;
- RgnHandle mBarRgn = NewRgn();
- RgnHandle grayRegion = nil;
-
- grayRegion = GetGrayRgn();
-
- SetRect( &mBarRect, qd.screenBits.bounds.left,
- qd.screenBits.bounds.top,
- qd.screenBits.bounds.right,
- qd.screenBits.bounds.top+OldMBarHeight );
-
-
- RectRgn( mBarRgn , &mBarRect );
- //UnionRgn( grayRegion, mBarRgn, grayRegion);
- RectRgn( grayRegion, &rToR(bounds) );
- UnionRgn( screen->visRgn , mBarRgn , screen->visRgn );
-
- CopyRgn( screen->visRgn , screen->clipRgn);
-
- DisposeRgn( mBarRgn );
-
-
-
-
-
- SetPort( (GrafPtr) screen );
- // create the screen buffer now
-
- MySetRectWH( &bounds , 0 , 0 , 1024 , 768 );
-
- if( !viewBuffer.NewBuff( bounds ) )
- return false;
-
- PaintRect( &viewBuffer , &bounds , 0xffff );
- AddRectToUpdate( bounds );
-
- return true;
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: UpdateMainWindow
-
- \----------------------------------------------------------------------------*/
- void COSScreen :: UpdateMainWindow( void )
- {
-
- if( !drawAll )
- {
- short i;
-
- for( i = 0; i < numUpdate; i++ )
- {
- CleanUp( &update[ i ] );
-
- CopyBits( (BitMap *) (*(viewBuffer.GetOffScreen()->PixMap)), &(screen->portBits),
- & rToR( update[ i ] ), & rToR( update[ i ] ), srcCopy , (RgnHandle)nil );
-
- }
-
- numUpdate = 0;
- }
- else
- {
- CleanUp( &viewArea );
-
- CopyBits( (BitMap *) (*(viewBuffer.GetOffScreen()->PixMap)), &(screen->portBits),
- & rToR( screenSize ), & rToR( screenSize ), srcCopy , (RgnHandle)nil );
-
- drawAll = false;
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: RectAllInScreen
-
- \----------------------------------------------------------------------------*/
- Boolean COSScreen :: RectAllInScreen( const rect *where )
- {
- if( where->left < 0 )
- return false;
-
- if( where->top < 0 )
- return false;
-
- if( where->right >= screenSize.right )
- return false;
-
- if( where->bottom >= screenSize.bottom )
- return false;
-
- return true;
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: DrawGeneric
-
- \----------------------------------------------------------------------------*/
- void COSScreen :: DrawGeneric( OffScreenBuff *srcBuff , rect *srcRect ,
- rect *destRect , rect *crop , ushort options ,
- uchar more , ushort color , Boolean menu )
- {
- rect blarg;
-
- if( menu )
- blarg = screenSize;
- else
- blarg = viewArea;
-
- if( crop == NULL )
- {
- ::DrawGeneric( srcBuff , srcRect , &viewBuffer , destRect ,
- &blarg , kDrawCrop1 | options, more , color );
-
- }
- else
- {
- rect where;
-
- MyCropRect( crop , &blarg , &where );
-
- ::DrawGeneric( srcBuff , srcRect , &viewBuffer , destRect ,
- &where , kDrawCrop1 | options , more , color );
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: DrawAll
-
- \----------------------------------------------------------------------------*/
- void COSScreen :: DrawAll( void )
- {
- drawAll = true;
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: AddRectToUpdate
-
- - this asumes everything is with in the view area and will not curropt memory
-
- \----------------------------------------------------------------------------*/
- void COSScreen :: AddRectToUpdate( rect theRect )
- {
- ulong area = 0xffffffff;
- ulong tempArea;
- int counter;
- int best = -1;
- rect tempRect;
- rect bestRect;
-
- // crop it to make sure it is with in the buffer
- MyCropRect( &theRect , &screenSize , &theRect );
-
- // adjust the rect so that it can be blited faster
- AdjustRect( &theRect );
-
- // see if it over laps any other rectangle
-
- for( counter = 0; counter < numUpdate; counter++ )
- {
- if( MySectRect( &theRect , &update[ counter ] ) )
- {
- // combined the two rects
- theRect.left = ( theRect.left < update[ counter ].left )
- ? theRect.left : update[ counter ].left;
-
- theRect.right = ( theRect.right > update[ counter ].right )
- ? theRect.right : update[ counter ].right;
-
- theRect.top = ( theRect.top < update[ counter ].top )
- ? theRect.top : update[ counter ].top;
-
- theRect.bottom = ( theRect.bottom > update[ counter ].bottom )
- ? theRect.bottom : update[ counter ].bottom;
-
- // remove the rectfrom the list
- numUpdate--;
- for( ; counter < numUpdate; counter++ )
- {
- update[ counter ] = update[ counter + 1];
- }
-
- // put the new combined rect through this proccess again
- AddRectToUpdate( theRect );
-
- return;
- }
- }
-
- // if there is room just add it to the list
- if( numUpdate < kMaxUpdate )
- {
- update[ numUpdate ] = theRect;
- numUpdate++;
- }
- else
- {
- // else find what rect combined with this will be the smallest area
- for( counter = 0; counter < kMaxUpdate; counter++ )
- {
- tempRect.left = ( tempRect.left < update[ counter ].left ) ?
- tempRect.left : update[ counter ].left;
-
- tempRect.right = ( tempRect.right > update[ counter ].right ) ?
- tempRect.right : update[ counter ].right;
-
- tempRect.top = ( tempRect.top < update[ counter ].top ) ?
- tempRect.top : update[ counter ].top;
-
- tempRect.bottom = ( tempRect.bottom > update[ counter ].bottom ) ?
- tempRect.bottom : update[ counter ].bottom;
-
- tempArea = (tempRect.right - tempRect.left) * (tempRect.bottom - tempRect.top );
-
- if( tempArea < area )
- {
- area = tempArea;
- best = counter;
- bestRect = tempRect;
- }
- }
-
- AdjustRect( &bestRect );
- update[ best ] = bestRect;
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: AdjustRect
-
- - makes it so it is faster to blit
- \----------------------------------------------------------------------------*/
- void COSScreen :: AdjustRect( rect *theRect )
- {
- // make it aligned
- theRect->left = theRect->left & 0xfffc;
- theRect->right = ( theRect->right + 3 ) & 0xfffc;
- }
-
- /*----------------------------------------------------------------------------\
-
- COSScreen :: CleanUp
-
- \----------------------------------------------------------------------------*/
- void COSScreen :: CleanUp( rect *where )
- {
- AH.CleanUp( where );
- menuBar.UpdateMenuBar( where );
- }
-