home *** CD-ROM | disk | FTP | other *** search
- /*
- HASCoolAboutBox.c from Hsoi's App Shell ©1995-1997 John C. Daub. All rights reserved.
-
- This is a "neat" About box. Much better than the plain old about boxes.
- Plus, it's sorta my attempt at an "Easter Egg" for the app shell.
-
- It has animation and uses GWorlds for that animation. I gleaned how to do
- this sorta thing from Metrowerk's own About box (they included the code on
- how to do this sorta thing on their CD in the "Examples" folder).
- */
-
- #pragma mark ••• #includes •••
-
- #ifndef _WASTE_
- #include "WASTE.h"
- #endif
- #include "HASGlobals.h"
- #ifndef __HSOIS_APP_SHELL__
- #include "HASMain.h"
- #endif
- #include "HASCoolAboutBox.h"
- #include "HASUtilities.h"
- #include "HASMiscEvents.h"
-
- #include "WASTE_Objects.h"
-
- #ifndef __QDOFFSCREEN__
- #include <QDOffscreen.h>
- #endif
-
- #pragma mark -
- #pragma mark ••• Public Call •••
-
-
- // the big meat call that starts it all
-
- void HsoiDoCoolAboutBox( void )
- {
- GWorldPtr saveWorld;
- GDHandle saveDevice;
-
- // if we have a WASTE sound playing, stop it before proceeding.
-
- if ( SoundIsPlaying() )
- StopCurrentSound();
-
- // we should check for system 7, having color quickdraw, and even for the monitor
- // to 256 color pixels (or greater, if not already there), but since we know this
- // is working within the realmz of a System 7 app, we don't need to. However,
- // it'd probably be a good thing to throw the checks in here anyways, y'know?
-
- // save the current GWorlds
-
- GetGWorld( &saveWorld, &saveDevice );
-
- // see if we have some free memory running about
-
- if ( FreeMem() < 350000 )
- {
- SysBeep( 5 );
- return;
- }
-
- // deactivate the front window
-
- HsoiDoActivate( false, FrontWindow() );
-
- // set things up
-
- HsoiSetUpCoolAboutBox();
-
- // do the stuff
-
- HsoiDoCoolStuff();
-
- // clean up
-
- HsoiCleanUpCoolAboutBox();
-
- // reactivate the "front" window
-
- HsoiDoActivate( true, FrontWindow() );
-
- // and restore our GWorlds
-
- SetGWorld( saveWorld, saveDevice );
-
- return;
- }
-
- #pragma mark -
- #pragma mark ••• Setup Routines •••
-
-
- // this is the setup routine that gets everything ready to go
-
- void HsoiSetUpCoolAboutBox( void )
- {
- Rect backgroundRect;
- PixMapHandle hPixMap;
- OSErr err;
-
- // get an area equal to our background
-
- HsoiGetItemRect( iCoolAboutBkgrnd, &backgroundRect );
-
- // try to create a gworld that size to draw the background into
-
- err = NewGWorld( &gDrawWorldPtr, PIXEL_DEPTH, &backgroundRect, nil, nil, 0 );
-
- // if we've run out of memory, try tapping temporary memory
-
- if ( err == memFullErr ) // -108
- err = NewGWorld( &gDrawWorldPtr, PIXEL_DEPTH, &backgroundRect, nil, nil, 0 + useTempMem );
-
- // get a handle to the pixel map for the offscreen world
-
- hPixMap = GetGWorldPixMap( gDrawWorldPtr );
-
- // lock the handle hi in the heap
-
- HLockHi( (Handle)hPixMap );
-
- // lock the offscren buffer
-
- LockPixels( hPixMap );
-
- // readjust a few things
-
- gDrawPixMapPtr = *hPixMap;
-
-
- // make gworld for the background
-
- // draw the background pict into the background gworld
-
- HsoiDrawPictIntoNewGWorld( rCoolAboutBkgrndPICT, PIXEL_DEPTH, &gBackWorldPtr );
-
- // get a handle to the pixmap
-
- hPixMap = GetGWorldPixMap( gBackWorldPtr );
-
- // lock the handle hi
-
- HLockHi( (Handle)hPixMap );
-
- // lock the offscreen buffer
-
- LockPixels( hPixMap );
-
- // and again, readjust the variables
-
- gBackPixMapPtr = *hPixMap;
-
- // get us a window...
-
- aboutBoxWindow = (CWindowPtr)GetNewCWindow( rCoolAboutWIND, nil, MOVE_TO_FRONT );
-
- // show it
-
- ShowWindow( (WindowRef)aboutBoxWindow );
-
- // lock hi the window's port pixel map
-
- HLockHi( (Handle)aboutBoxWindow->portPixMap );
- windowPixMapPtr = *aboutBoxWindow->portPixMap;
-
- // draw the background in the window
-
- SetGWorld( aboutBoxWindow, GetMainDevice() );
- CopyBits( (BitMapPtr)gBackPixMapPtr, (BitMapPtr)windowPixMapPtr, &backgroundRect,
- &backgroundRect, srcCopy, nil );
-
-
- return;
- }
-
-
- // set up our logo picture
-
- void HsoiSetUpLogo( LogoRec *inLogoBoxRec )
- {
- // draw the logo pict into a new gworld
-
- HsoiDrawPictIntoNewGWorld( rLogoPICT, PIXEL_DEPTH, &inLogoBoxRec->theGWorldPtr );
-
- // and all this places our pict in a nice starting location
-
- HsoiGetItemRect( iCoolAboutLogo, &inLogoBoxRec->currPos );
- inLogoBoxRec->bottomLoc = inLogoBoxRec->currPos.bottom;
- OffsetRect( &inLogoBoxRec->currPos, 0, -inLogoBoxRec->currPos.bottom );
- inLogoBoxRec->imagePos.left = inLogoBoxRec->imagePos.top = 0;
- inLogoBoxRec->imagePos.right = inLogoBoxRec->currPos.right - inLogoBoxRec->currPos.left;
- inLogoBoxRec->imagePos.bottom = inLogoBoxRec->currPos.bottom - inLogoBoxRec->currPos.top;
-
- return;
- }
-
- // set up for version pict
-
- void HsoiSetUpVersion( VersionRec *inVersionBoxRec )
- {
- Rect bkgndRect;
-
- // draw the version pict into a new gworld
-
- HsoiDrawPictIntoNewGWorld( rVersionPICT, PIXEL_DEPTH, &inVersionBoxRec->theGWorldPtr );
-
- // and place the pict in a nice starting place offscreen
-
- HsoiGetItemRect( iCoolAboutVersion, &inVersionBoxRec->currPos );
- HsoiGetItemRect( iCoolAboutBkgrnd, &bkgndRect );
- inVersionBoxRec->bottomLoc = inVersionBoxRec->currPos.bottom;
- OffsetRect( &inVersionBoxRec->currPos, 0, ( bkgndRect.bottom - inVersionBoxRec->currPos.top) );
- inVersionBoxRec->imagePos.left = inVersionBoxRec->imagePos.top = 0;
- inVersionBoxRec->imagePos.right = inVersionBoxRec->currPos.right - inVersionBoxRec->currPos.left;
- inVersionBoxRec->imagePos.bottom = inVersionBoxRec->currPos.bottom - inVersionBoxRec->currPos.top;
-
- return;
- }
-
- // set up the credits
-
- void HsoiSetUpCredits(CreditsRec *inCreditsRec)
- {
- PicHandle pictureH;
- Rect picFrame;
- PixMapHandle thePixMapH;
- Rect creditsBox;
- OSErr err;
-
- // The only animation is the credits
- // Therefore, we can reduce the size of the offscreen worlds for the background
- // and scratch drawing to just cover the area where the credits are drawn.
-
- DisposeGWorld(gBackWorldPtr);
- DisposeGWorld(gDrawWorldPtr);
-
- HsoiGetItemRect(iCoolAboutText, &inCreditsRec->viewRect);
-
- // Make GWorld for offscreen drawing.
-
- err = NewGWorld(&gDrawWorldPtr, PIXEL_DEPTH, &inCreditsRec->viewRect, nil, nil, 0);
- if ( err == memFullErr )
- err = NewGWorld( &gDrawWorldPtr, PIXEL_DEPTH, &inCreditsRec->viewRect, nil, nil, 0 + useTempMem );
- thePixMapH = GetGWorldPixMap(gDrawWorldPtr);
- HLockHi((Handle)thePixMapH);
- LockPixels(thePixMapH);
- gDrawPixMapPtr = *thePixMapH;
-
- // Make GWorld for background.
-
- err = NewGWorld(&gBackWorldPtr, PIXEL_DEPTH, &inCreditsRec->viewRect, nil,
- GetGWorldDevice(gDrawWorldPtr), noNewDevice);
- if ( err == memFullErr )
- NewGWorld( &gBackWorldPtr, PIXEL_DEPTH, &inCreditsRec->viewRect, nil,
- GetGWorldDevice( gDrawWorldPtr), noNewDevice + useTempMem );
- thePixMapH = GetGWorldPixMap(gBackWorldPtr);
- HLockHi((Handle)thePixMapH);
- LockPixels(thePixMapH);
- gBackPixMapPtr = *thePixMapH;
-
- // draw the background pict into it's own little gworld
-
- SetGWorld(gBackWorldPtr, nil);
- pictureH = GetPicture(rCoolAboutBkgrndPICT);
- picFrame = (**pictureH).picFrame;
- DrawPicture(pictureH, &picFrame);
- HsoiForgetResource( (Handle *)&pictureH );
-
- // Make GWorld for credits.
-
- creditsBox = inCreditsRec->viewRect;
- HsoiDrawTextIntoNewGWorld(rCoolAboutCreditsText, &creditsBox,
- PIXEL_DEPTH, &inCreditsRec->theGWorldPtr);
-
- inCreditsRec->pictRect.left = 0;
- inCreditsRec->pictRect.top = 0;
- inCreditsRec->pictRect.right = inCreditsRec->viewRect.right -
- inCreditsRec->viewRect.left;
- inCreditsRec->pictRect.bottom = inCreditsRec->viewRect.bottom -
- inCreditsRec->viewRect.top;
-
- inCreditsRec->pictHeight = creditsBox.bottom;
-
- return;
- }
-
- // just what you think...dispose of stuff
-
- void HsoiCleanUpCoolAboutBox( void )
- {
- DisposeGWorld( gDrawWorldPtr );
- DisposeGWorld( gBackWorldPtr );
- DisposeWindow( (WindowRef)aboutBoxWindow );
- return;
- }
-
-
- #pragma mark -
- #pragma mark ••• Animation •••
-
- // this does all the cool animation and action in the box
-
- void HsoiDoCoolStuff( void )
- {
- /* start on the cool stuff...
-
- Have the logo bounce in...the version bounce in...the credits fade in and then
- scroll through. after scrolling through, it'll pause a bit at the end,
- then automatically dismiss. It used to wrap the credits around and scroll
- continuously, but I removed that...it seems to hate life if tempMem is
- used for the GWorlds
- */
-
- CreditsRec theCreditsRec;
- LogoRec theLogoRec;
- VersionRec theVersionRec;
- Rect currPos, imagePos;
-
- AnimateState animLogoDown = animate_Active;
- AnimateState animLogoUp = animate_Waiting;
- AnimateState animVersionDown = animate_Waiting;
- AnimateState animVersionUp = animate_Waiting;
- AnimateState animVersion = animate_Waiting;
- AnimateState animCreditsFade = animate_Waiting;
- AnimateState animCreditsScroll = animate_Waiting;
-
- Boolean logoHalfDrawn = false;
- Boolean logoWholeDrawm = false;
-
- RGBColor fadeColor;
- short grayIndex = 0;
- unsigned short grayLevels[FADE_LEVELS] = {
- 4369, 8738, 17476, 21845, 30583, 34952, 43690, 48059, 52428, 56979,
- 61166, 65535
- };
-
- // initialize things
-
- theLogoRec.theGWorldPtr = nil;
- theVersionRec.theGWorldPtr = nil;
- theCreditsRec.theGWorldPtr = nil;
-
- // set up the logo
-
- HsoiSetUpLogo( &theLogoRec );
-
- // set up the version picture
-
- HsoiSetUpVersion( &theVersionRec );
-
- // and begin the big mama loop to make it all go
-
- // but before we go, let's flush the event queue a bit
-
- FlushEvents(mDownMask | mUpMask | keyDownMask | keyUpMask | autoKeyMask, 0);
-
-
- while ( !Button() ) // a mouse click will end it all
- {
- long ticks;
- long endTicks;
- long startTicks = TickCount();
-
- // the following things are kinda confusing...what we're doing is constantly
- // monitoring the state of the animating things...based upon the state of
- // one thing, we'll determine the state of the next thing and then go from
- // there...again, it's kinda confusing, so read it over a bunch of times.
- // eventually, it'll sink in and make sense (i hope!)
-
- // if the logo is the current active object and it's gone down as far as
- // we want it, set a few things to let us know it's time to move it up
-
- if ( (animLogoDown == animate_Active) &&
- (theLogoRec.currPos.bottom >= theLogoRec.bottomLoc + BOUNCE ))
- {
- animLogoDown = animate_Done;
- animLogoUp = animate_Active;
- }
-
- // if the logo is the current active object and it's now moved all the way
- // up and is in it's final resting place, we don't need to animate it anymore,
- // and we'll now start the version animating
-
- if ( (animLogoUp == animate_Active) &&
- (theLogoRec.currPos.bottom <= theLogoRec.bottomLoc) )
- {
- animLogoUp = animate_Done;
- animVersionUp = animate_Active;
- }
-
- // if the version is the current active object and it's moved up as far as
- // it should, time to bounce it back down into place
-
- if ( (animVersionUp == animate_Active ) &&
- (theVersionRec.currPos.bottom <= theVersionRec.bottomLoc ) )
-
- {
- animVersionUp = animate_Done;
- animVersionDown = animate_Active;
- }
-
- // HERE'S A BIG ONE!
-
- // the logo and version picts are all in place...it's now time to
- // start on the scrolling credits...first we'll have to fade them in,
- // so we'll have to get them all set up!
-
- if ( (animVersionDown == animate_Active) &&
- (theVersionRec.currPos.bottom >= theVersionRec.bottomLoc + BOUNCE ) )
- {
- animVersionDown = animate_Done;
- animCreditsFade = animate_Active;
- HsoiSetUpCredits( &theCreditsRec );
- }
-
- // if the credits have totally faded in, wait a sec and a half,
- // then begin to scroll 'em.
-
- if ( (animCreditsFade == animate_Active) &&
- (grayIndex >= FADE_LEVELS))
- {
- animCreditsFade = animate_Done;
- Delay( 90, &ticks );
- animCreditsScroll = animate_Active;
- }
-
- // if the text has scrolled all the way through, time to bail
- // out and go bye bye (originally, this is where things would be reset
- // to allow the scrolling text to loop back to the beginning)
-
- if ( (animCreditsScroll == animate_Active) &&
- (theCreditsRec.pictRect.top > theCreditsRec.pictHeight))
- {
- theCreditsRec.pictRect.top = 1;
- theCreditsRec.pictRect.top = theCreditsRec.viewRect.bottom - theCreditsRec.viewRect.top + 1;
- goto byebye;
- }
-
-
- // alright...all the above stuff was just the setting up of the animate
- // states....now, based upon those, we now will commence to do things..
-
-
- // we want to move the logo down, so let's adjust coordinates as such
-
- if ( animLogoDown == animate_Active )
- {
- currPos = theLogoRec.currPos;
- theLogoRec.currPos.top++;
- theLogoRec.currPos.bottom++;
- imagePos = theLogoRec.imagePos;
- HsoiMoveOffWorld( theLogoRec.theGWorldPtr, &currPos, &theLogoRec.currPos, &imagePos );
- }
-
- // and now move the logo up, so adjust coordinates as such
-
- if ( animLogoUp == animate_Active )
- {
- currPos = theLogoRec.currPos;
- theLogoRec.currPos.top--;
- theLogoRec.currPos.bottom--;
- imagePos = theLogoRec.imagePos;
- HsoiMoveOffWorld( theLogoRec.theGWorldPtr, &currPos, &theLogoRec.currPos, &imagePos );
- }
-
- // move the version up, so adjust coordinates to suit
-
- if ( animVersionUp == animate_Active )
- {
- currPos = theVersionRec.currPos;
- theVersionRec.currPos.top--;
- theVersionRec.currPos.bottom--;
- imagePos = theVersionRec.imagePos;
- HsoiMoveOffWorld( theVersionRec.theGWorldPtr, &currPos, &theVersionRec.currPos, &imagePos );
- }
-
- // move the version down, again, adjust coordinates
-
- if ( animVersionDown == animate_Active )
- {
- currPos = theVersionRec.currPos;
- theVersionRec.currPos.top++;
- theVersionRec.currPos.bottom++;
- imagePos = theVersionRec.imagePos;
- HsoiMoveOffWorld( theVersionRec.theGWorldPtr, &currPos, &theVersionRec.currPos, &imagePos );
- }
-
- // we're going to fade in the credits from black
-
- if ( animCreditsFade == animate_Active )
- {
- PixMapHandle thePixMapH;
-
- // delay for a 1/20th of a second
-
- Delay( 3, &ticks );
-
- // set our gworld up
-
- SetGWorld( gDrawWorldPtr, nil );
-
- // get the credit's pixel map
-
- thePixMapH = GetGWorldPixMap( theCreditsRec.theGWorldPtr );
-
- // lock 'em for drawing
-
- LockPixels(thePixMapH);
-
- // and copy
-
- CopyBits( (BitMapPtr)(*thePixMapH), (BitMapPtr)gDrawPixMapPtr,
- &theCreditsRec.pictRect, &theCreditsRec.viewRect, srcCopy, nil );
-
- // unlock the pixels
-
- UnlockPixels( thePixMapH );
-
- // change the color (incrimentally), from black to white
-
- fadeColor.red = fadeColor.blue = fadeColor.green = grayLevels[grayIndex++];
-
- // set this new color
-
- RGBForeColor( &fadeColor );
-
- // set our pen mode
-
- PenMode( adMin );
-
- // paint the viewRect
-
- PaintRect( &theCreditsRec.viewRect );
-
- // set the pen mode again
-
- PenMode( patCopy );
-
- // and make things black
-
- ForeColor( blackColor );
-
- // copy from the background
-
- CopyBits( (BitMapPtr)gBackPixMapPtr, (BitMapPtr)gDrawPixMapPtr,
- &theCreditsRec.viewRect, &theCreditsRec.viewRect, adMax, nil );
-
- // set to our onscreen about box
-
- SetGWorld( aboutBoxWindow, GetMainDevice() );
-
- // and finally, copy things onscreen
-
- CopyBits( (BitMapPtr)gDrawPixMapPtr, (BitMapPtr)windowPixMapPtr,
- &theCreditsRec.viewRect, &theCreditsRec.viewRect, srcCopy, nil );
- }
-
- // if it's time to scroll the credits...
-
- if ( animCreditsScroll == animate_Active )
- {
- PixMapHandle thePixMapH;
- short i, j;
- short creditsWidth = theCreditsRec.viewRect.right - theCreditsRec.viewRect.left - 1;
-
- // set the gworld to a "scrap" drawing gworld
-
- SetGWorld( gDrawWorldPtr, nil );
-
- // set up the rect's coordinates...bump up 1 pixel to make the scroll happen
-
- theCreditsRec.pictRect.top += 1;
- theCreditsRec.pictRect.bottom += 1;
-
- // get the pix map
-
- thePixMapH = GetGWorldPixMap( theCreditsRec.theGWorldPtr );
- LockPixels( thePixMapH );
-
- // if we haven't scrolled all the way through...
-
- if ( theCreditsRec.pictRect.bottom <= theCreditsRec.pictHeight)
- {
- // copy into our scrap gworld for nice "editing"
-
- CopyBits( (BitMapPtr)(*thePixMapH), (BitMapPtr)gDrawPixMapPtr,
- &theCreditsRec.pictRect, &theCreditsRec.viewRect, srcCopy, nil );
- }
-
- UnlockPixels( thePixMapH );
-
- // set our pen mode
-
- PenMode( adMin );
-
- // and we do a nice little touch here...at the top and bottom of the
- // credits, instead of just going in and out of the screen, we have a nice
- // little fade effect.
-
- // this loop makes the fade nice and gradual
-
- j = FADE_LEVELS - 1;
- for ( i = 0; i < j; i++ )
- {
- fadeColor.red = fadeColor.blue = fadeColor.green = grayLevels[i];
- RGBForeColor( &fadeColor );
- MoveTo( theCreditsRec.viewRect.left, theCreditsRec.viewRect.top + i);
- Line( creditsWidth, 0 );
- MoveTo( theCreditsRec.viewRect.left, theCreditsRec.viewRect.bottom - i - 1 );
- Line( creditsWidth, 0 );
- }
-
- // set the fore color to black
-
- ForeColor( blackColor );
-
- // new pen mode
-
- PenMode( patCopy );
-
- // copy from the back to the scrap gworld
-
- CopyBits( (BitMapPtr)gBackPixMapPtr, (BitMapPtr)gDrawPixMapPtr,
- &theCreditsRec.viewRect, &theCreditsRec.viewRect, adMax, nil );
-
- // set the gworld to our abou box
-
- SetGWorld( aboutBoxWindow, GetMainDevice() );
-
- // and copy it all onscreen and give the illusion of scrolling :)
-
- CopyBits( (BitMapPtr)gDrawPixMapPtr, (BitMapPtr)windowPixMapPtr,
- &theCreditsRec.viewRect, &theCreditsRec.viewRect, srcCopy, nil );
-
- }
-
- // a nice little buffer to pace the scrolling. if the user's computer is so
- // way fast is blows through a cycle of the while-loop too fast, we don't
- // want the credits to scroll by at a million miles an hour. it's like
- // a nice speed limit. :)
-
- endTicks = TickCount();
- if ( endTicks == startTicks )
- while ( endTicks == TickCount() )
- ;
- } // end while (!Button())
-
- byebye:
-
- // clean out the event queue
-
- FlushEvents(mDownMask | mUpMask | keyDownMask | keyUpMask | autoKeyMask, 0);
-
- // dispose of unneeded gworlds
-
- if ( theCreditsRec.theGWorldPtr != nil )
- DisposeGWorld(theCreditsRec.theGWorldPtr );
- if ( theLogoRec.theGWorldPtr != nil )
- DisposeGWorld(theLogoRec.theGWorldPtr );
- if ( theVersionRec.theGWorldPtr != nil )
- DisposeGWorld( theVersionRec.theGWorldPtr );
-
- return;
- }
-
- // this function is unused here...it's "left over" from the original Metrowerks
- // animated about box code
-
- void HsoiMoveLogoBox(GWorldPtr theGWorldP, Rect *inCurrPos, short inVertOffset)
- {
- #pragma unused ( theGWorldP )
-
- Rect exposedRect, coveredRect, imageRect;
- RGBColor boxColor = {
- 65535, 52428, 0
- };
-
- // Draw to the Window.
-
- SetGWorld(aboutBoxWindow, GetMainDevice());
-
- // Determine areas exposed and covered by bar as it moves.
-
- exposedRect = coveredRect = *inCurrPos;
- if (inVertOffset > 0) {
- exposedRect.bottom = exposedRect.top + inVertOffset;
- coveredRect.top = coveredRect.bottom;
- coveredRect.bottom += inVertOffset;
- } else {
- exposedRect.top = exposedRect.bottom + inVertOffset;
- coveredRect.bottom = coveredRect.top;
- coveredRect.top += inVertOffset;
- }
- imageRect.left = 0;
- imageRect.right = coveredRect.right - coveredRect.left;
- imageRect.top = 0;
- imageRect.bottom = coveredRect.bottom - coveredRect.top;
-
- // Restore background over exposed area.
-
- CopyBits((BitMapPtr)gBackPixMapPtr, (BitMapPtr)windowPixMapPtr, &exposedRect,
- &exposedRect, srcCopy, nil);
-
- // Draw image at covered area.
-
- RGBForeColor(&boxColor);
- PaintRect(&coveredRect);
- ForeColor(blackColor);
-
- return;
- }
-
- void HsoiMoveOffWorld(GWorldPtr theGWorldP, Rect *inCurrPos, Rect *inNewPos, Rect *inOffPos)
- {
- Rect drawRect;
- PixMapHandle offPixMapH;
-
- // Create image in draw world.
-
- SetGWorld(gDrawWorldPtr, nil);
-
- // Restore background at current position.
-
- CopyBits((BitMapPtr)gBackPixMapPtr, (BitMapPtr)gDrawPixMapPtr, inCurrPos,
- inCurrPos, srcCopy, nil);
-
- // Draw image at new position.
-
- offPixMapH = GetGWorldPixMap(theGWorldP);
- LockPixels(offPixMapH);
- CopyBits((BitMapPtr)(*offPixMapH), (BitMapPtr)gDrawPixMapPtr, inOffPos,
- inNewPos, srcCopy, nil);
- UnlockPixels(offPixMapH);
-
- // Draw union of old and new position to Window.
-
- SetGWorld(aboutBoxWindow, GetMainDevice());
- UnionRect(inCurrPos, inNewPos, &drawRect);
- CopyBits((BitMapPtr)gDrawPixMapPtr, (BitMapPtr)windowPixMapPtr, &drawRect,
- &drawRect, srcCopy, nil);
-
- return;
- }
-
-
- #pragma mark -
- #pragma mark ••• Utils •••
-
-
- // returns a rect that is a user item in a DITL
-
- void HsoiGetItemRect( short inItem, Rect *outRect )
- {
- DITLHand theDITL;
-
- theDITL = (DITLHand) GetResource('DITL', rCoolAboutDITL);
- *outRect = (**theDITL).theUserItems[inItem - 1].box;
-
- return;
- }
-
- // does just what you think...draws a given PICT into a new gworld
-
- void HsoiDrawPictIntoNewGWorld(short inPICTid, short inDepth, GWorldPtr *outGWorldP)
- {
- PicHandle thePicture;
- Rect picFrame;
- GWorldPtr saveWorld;
- GDHandle saveDevice;
- OSErr err;
-
- // get the picture
-
- thePicture = GetPicture(inPICTid);
-
- // get the size/coordinates of the PICTs frame
-
- picFrame = (**thePicture).picFrame;
-
- // create a gworld for the PICT
-
- err = NewGWorld(outGWorldP, inDepth, &picFrame, nil,
- GetGWorldDevice(gDrawWorldPtr), noNewDevice);
-
- // if we run out of memory, tap temporary memory
-
- if ( err == memFullErr )
- err = NewGWorld( outGWorldP, inDepth, &picFrame, nil,
- GetGWorldDevice( gDrawWorldPtr), noNewDevice + useTempMem );
-
- // get the old gworld and set the new gworld to our pict's
-
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld (*outGWorldP, nil);
-
- // lock the pixels
-
- LockPixels(GetGWorldPixMap(*outGWorldP));
-
- // draw the pict in the new gworld
-
- DrawPicture(thePicture, &picFrame);
-
- // unlock the pixels
-
- UnlockPixels(GetGWorldPixMap(*outGWorldP));
-
- // restore the old gworld
- SetGWorld(saveWorld, saveDevice);
-
- // and dump the pict resource
-
- HsoiForgetResource( (Handle *)&thePicture );
-
- return;
- }
-
- // eventually, i probably ought to change this to use WASTE instead of TextEdit
-
- // this gets our credits (from a 'TEXT' resource) and then draws it into a new gworld
-
- void HsoiDrawTextIntoNewGWorld(short inTEXTid, Rect *ioBounds, short inDepth, GWorldPtr *outGWorldP)
- {
- Handle theText;
- TEHandle theTE;
- StScrpHandle theStyle;
- GWorldPtr saveWorld;
- GDHandle saveDevice;
- OSErr err;
-
- // Put Text in a TERecord
-
- // set a few text characteristics
-
- TextFont(applFont);
- TextSize( FONT_SIZE );
-
- // create a text instance to hold our text
-
- theTE = TEStyleNew(ioBounds, ioBounds);
-
- // get our credits text
-
- theText = GetResource('TEXT', inTEXTid);
-
- // get it's associated style
-
- theStyle = (StScrpHandle) GetResource('styl', inTEXTid);
-
- // lock it down
-
- HLock(theText);
-
- // don't show the pen while we draw
- HidePen();
-
- // insert the TEXT and styl into our TextEdit record
-
- TEStyleInsert(*theText, GetHandleSize(theText), theStyle, theTE);
-
- // show the pen
-
- ShowPen();
-
- // dump the text resource
-
- HsoiForgetResource( &theText );
-
- // dump the styl, if any
-
- if (theStyle != nil)
- {
- HsoiForgetResource( (Handle *)&theStyle );
- }
-
- // set the alignment to a center
-
- TESetAlignment(teJustCenter, theTE);
-
- // recalc the line breaks
-
- TECalText(theTE);
-
- // Determine height of the Text
-
- ioBounds->right = ioBounds->right - ioBounds->left;
- ioBounds->left = ioBounds->top = 0;
- ioBounds->bottom = TEGetHeight((**theTE).nLines, 0, theTE);
-
- // Create new GWorld that is the height of the Text
- err = NewGWorld( outGWorldP, inDepth, ioBounds, nil,
- GetGWorldDevice( gDrawWorldPtr ), noNewDevice );
-
- // tap ttemp mem if needed
-
- if ( err == memFullErr )
- err = NewGWorld(outGWorldP, inDepth, ioBounds, nil,
- GetGWorldDevice(gDrawWorldPtr), noNewDevice + useTempMem);
-
- // set up the gworld
-
- GetGWorld(&saveWorld, &saveDevice);
- SetGWorld (*outGWorldP, nil);
- LockPixels(GetGWorldPixMap(*outGWorldP));
-
- // clean out the rect
-
- EraseRect(ioBounds);
-
- // Draw Text inside GWorld
- (**theTE).viewRect = *ioBounds;
- (**theTE).destRect = *ioBounds;
- (**theTE).inPort = (GrafPtr) *outGWorldP;
-
- // update things
-
- TEUpdate(ioBounds, theTE);
-
- // dispose of the TextEdit record
-
- TEDispose(theTE);
-
- InvertRect(ioBounds); // White letters on black background
-
- // restore the gworlds
-
- UnlockPixels(GetGWorldPixMap(*outGWorldP));
- SetGWorld(saveWorld, saveDevice);
-
- return;
- }
-
-
-