home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-12-19 | 8.0 KB | 334 lines | [TEXT/CWIE] |
- ///--------------------------------------------------------------------------------------
- // About.c
- //
- // By: Tony Myles
- //
- // Copyright: © 1993-94 Tony Myles, All rights reserved worldwide.
- ///--------------------------------------------------------------------------------------
-
-
- #include <SWIncludes.h> // Automatically include all SpriteWorld.h files
- #include <SWApplication.h>
-
- #ifndef __DIALOGUTILS__
- #include <SWDialogUtils.h>
- #endif
-
- #ifndef __SPRITETEST__
- #include "SpriteTest.h"
- #endif
-
- #ifndef __APPLICATION__
- #include "Application.h"
- #endif
-
- #ifndef __ABOUT__
- #include "About.h"
- #endif
-
-
- extern SpriteTestPtr gSpriteTestP;
-
-
- ///--------------------------------------------------------------------------------------
- // DisplayAboutBox
- ///--------------------------------------------------------------------------------------
-
- void DisplayAboutBox(void)
- {
- OSErr err;
- GrafPtr savePort;
- DialogPtr aboutDialogP;
- SpriteWorldPtr spriteWorldP = NULL;
- SpriteLayerPtr spriteLayerP = NULL;
- SpritePtr earthSpriteP = NULL;
- SpritePtr shadowSpriteP = NULL;
- Rect itemRect, moveBoundsRect;
- short itemHit, itemType;
- Handle itemHandle;
- ModalFilterUPP spriteWorldDialogFilter;
- UserItemUPP procForVersUserItem;
-
- aboutDialogP = GetNewDialog(kAboutDialogID, NULL, (WindowPtr)-1L);
-
- procForVersUserItem = NewUserItemProc(DrawVersionProc);
- GetDialogItem(aboutDialogP, 6, &itemType, &itemHandle, &itemRect);
- SetDialogItem(aboutDialogP, 6, itemType, (Handle)procForVersUserItem, &itemRect);
-
- if (aboutDialogP != NULL)
- {
- GetPort(&savePort);
- SetPort(aboutDialogP);
-
- // create the sprite world
- err = SWCreateSpriteWorldFromWindow(&spriteWorldP, (CWindowPtr)aboutDialogP, NULL, NULL, 0);
-
- if (err == noErr)
- {
- // create the sprite layer
- err = SWCreateSpriteLayer(&spriteLayerP);
- }
-
- if (err == noErr)
- {
- err = SWCreateSpriteFromCicnResource(
- spriteWorldP,
- &earthSpriteP,
- NULL,
- kEarthCIconID,
- 1,
- kRegionMask);
- }
-
- if (err == noErr)
- {
- err = SWCreateSpriteFromCicnResource(
- spriteWorldP,
- &shadowSpriteP,
- NULL,
- kShadowCIconID,
- kNumberOfShadowFrames,
- kRegionMask);
- }
-
- if (err == noErr)
- {
- shadowSpriteP->userData = (long)earthSpriteP;
-
- SWAddSprite(spriteLayerP, shadowSpriteP);
- SWAddSprite(spriteLayerP, earthSpriteP);
- SWAddSpriteLayer(spriteWorldP, spriteLayerP);
-
- GetDItemRect(aboutDialogP, 4, &itemRect);
- moveBoundsRect = aboutDialogP->portRect;
- moveBoundsRect.bottom = itemRect.top + ((itemRect.bottom-itemRect.top)/2);
-
- // set the sprite’s movement characteristics
- SWSetSpriteMoveBounds(earthSpriteP, &moveBoundsRect);
- SWSetSpriteMoveDelta(earthSpriteP, 0, kInitialSpeed);
- SWSetSpriteMoveProc(earthSpriteP, EarthMoveProc);
- SWSetSpriteMoveTime(earthSpriteP, 55);
- SWSetSpriteMoveTime(shadowSpriteP, -1); // never move
- SWSetSpriteFrameTime(shadowSpriteP, 0);
- SWSetSpriteFrameRange(shadowSpriteP, 0, 4);
- SWSetSpriteFrameProc(shadowSpriteP, ShadowFrameProc);
- SWSetCurrentFrameIndex(shadowSpriteP, 2);
-
- // set the sprite’s initial location
- SWSetSpriteLocation(shadowSpriteP, itemRect.left, itemRect.top);
- GetDItemRect(aboutDialogP, 5, &itemRect);
- SWSetSpriteLocation(earthSpriteP, itemRect.left, itemRect.top);
-
- ((WindowPeek)aboutDialogP)->refCon = (long)spriteWorldP;
-
- ShowWindow(aboutDialogP);
- SetPort(aboutDialogP);
- DrawDialog(aboutDialogP);
- EraseRect(&itemRect);
- OutlineDefaultButton(aboutDialogP, ok);
-
- SWLockSpriteWorld(spriteWorldP);
-
- // Copy contents of dialog to SpriteWorld's backFrame
- CopyBits(&aboutDialogP->portBits,
- (BitMap*)spriteWorldP->backFrameP->framePix,
- &aboutDialogP->portRect,
- &aboutDialogP->portRect,
- srcCopy, NULL);
-
-
- spriteWorldDialogFilter = NewModalFilterProc(AboutDialogFilter);
-
- do
- {
- ModalDialog(spriteWorldDialogFilter, &itemHit);
- } while (itemHit != ok);
-
- DisposeRoutineDescriptor(spriteWorldDialogFilter);
- DisposeRoutineDescriptor(procForVersUserItem);
- SWUnlockSpriteWorld(spriteWorldP);
- }
-
- DisposeDialog(aboutDialogP);
- SWDisposeSpriteWorld(&spriteWorldP);
-
- SetPort(savePort);
-
- if (err != noErr)
- {
- FatalError(err);
- }
- }
- else
- {
- CantFindResource();
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // EarthMoveProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void EarthMoveProc(
- SpritePtr srcSpriteP)
- {
- // gravity
- if (srcSpriteP->vertMoveDelta < (short)kMaxSpeed)
- srcSpriteP->vertMoveDelta++;
-
- SWOffsetSprite( srcSpriteP, 0, srcSpriteP->vertMoveDelta );
- // bounce
- if (srcSpriteP->destFrameRect.bottom > srcSpriteP->moveBoundsRect.bottom)
- {
- srcSpriteP->vertMoveDelta = -srcSpriteP->vertMoveDelta;
-
- SWMoveSprite( srcSpriteP, srcSpriteP->destFrameRect.left,
- srcSpriteP->moveBoundsRect.bottom -
- (srcSpriteP->curFrameP->frameRect.bottom -
- srcSpriteP->curFrameP->frameRect.top));
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // ShadowFrameProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void ShadowFrameProc(
- SpritePtr srcSpriteP,
- FramePtr curFrameP,
- long* curFrameIndex)
- {
- #pragma unused(curFrameP)
- SpritePtr earthSpriteP = (SpritePtr)srcSpriteP->userData;
- short distanceFromTop = earthSpriteP->destFrameRect.top - srcSpriteP->moveBoundsRect.top;
- short height = earthSpriteP->moveBoundsRect.bottom - earthSpriteP->moveBoundsRect.top;
-
- *curFrameIndex = (long)((distanceFromTop * 5) / height);
-
- // lets not index past the last frame!
- // (even though SpriteWorld will not allow it to happen)
- if (*curFrameIndex > 4L) *curFrameIndex = 4L;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // AboutDialogFilter
- ///--------------------------------------------------------------------------------------
-
- pascal Boolean AboutDialogFilter(
- DialogPtr aboutDialogP,
- EventRecord *event,
- short *itemHit)
- {
- Boolean eventHandled = false;
- SpriteWorldPtr spriteWorldP = (SpriteWorldPtr)((WindowPeek)aboutDialogP)->refCon;
-
- switch (event->what)
- {
- case nullEvent:
- {
- // run the about box animation
- SWProcessSpriteWorld(spriteWorldP);
- SWAnimateSpriteWorld(spriteWorldP);
-
- // keep the title animation going!
- SpriteTestIdle(gSpriteTestP);
- break;
- }
-
- case keyDown:
- case autoKey:
- {
- char key = (char)(event->message & charCodeMask);
-
- if (key == kReturnChar || (key == kEnterChar))
- {
- *itemHit = ok;
- eventHandled = true;
- ClickDialogButton(aboutDialogP, ok);
- }
-
- break;
- }
-
- case updateEvt:
- {
- if ((DialogPtr)event->message == aboutDialogP)
- {
- SetPort(aboutDialogP);
- BeginUpdate(aboutDialogP);
-
- SWUpdateSpriteWorld(spriteWorldP, true);
-
- EndUpdate(aboutDialogP);
- eventHandled = true;
- }
- else
- {
- HandleUpdateEvent((WindowPtr)event->message);
- }
-
- break;
- }
- }
-
- return eventHandled;
- }
-
- /********************************** DrawVersionProc *******/
- pascal void DrawVersionProc (DialogPtr theDialog, short itemNo)
-
- {
- Rect itemRect;
- short itemType;
- Handle itemHandle;
- unsigned long versNum;
- short majorNum;
- short betaNum;
- char versDigit1, versDigit2, versDigit3;
-
-
-
- GetDialogItem ( theDialog, itemNo, &itemType, &itemHandle, &itemRect );
-
- versNum = SWGetSpriteWorldVersion();
-
- majorNum = HiWord( versNum );
- majorNum>>=8;
- versDigit1 = majorNum | '0';
- majorNum = (HiWord( versNum ))&0x00FF;
- majorNum >>=4;
- versDigit2 = majorNum | '0';
- majorNum = (HiWord( versNum ))&0x000F;
- versDigit3 = majorNum | '0';
-
- MoveTo( itemRect.left, itemRect.top + 9 );
- TextFont(applFont);
- TextSize(9);
- DrawChar( versDigit1 );
- DrawChar( '.' );
- DrawChar( versDigit2 );
- if ( versDigit3 > '0' )
- {
- DrawChar( '.' );
- DrawChar( versDigit3 );
- }
-
- betaNum = LoWord( versNum );
- if ( betaNum )
- {
- ForeColor( blueColor );
- DrawString( "\p beta" );
- DrawChar( '0'+betaNum );
- ForeColor( blackColor );
- }
- DrawString( "\p by" );
- TextFace( 0 );
- TextFont(systemFont);
- TextSize(12);
- }
-
-
-