home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / WebSTAR / PPSendPartial CGI / Source / Credits.c next >
Encoding:
Text File  |  1996-10-11  |  6.4 KB  |  237 lines  |  [TEXT/CWIE]

  1. /***
  2.     File:        Credits.c
  3.  
  4.  
  5.     Contains:    Generic code for credits splash
  6.  
  7.  
  8.     Written by:    Ken Wieschhoff
  9.  
  10.  
  11.     Copyright:    ©1996 Siren Enterprises, All Rights Reserved.
  12.  
  13.  
  14.     Change History (most recent first):
  15.  
  16.  
  17.  
  18.        <1>     9/5/96  kw     Original
  19.  
  20. ***/
  21.  
  22.  
  23.  
  24. long        gNextCredits;
  25. short        gTextOffset;
  26. long        gNextCredits;
  27.  
  28. pascal void DrawCredits(DialogPtr theDialog,PicHandle creditsPicture, short *textOffset);
  29. pascal QDErr MyNewGWorld(GWorldPtr *offscreenGWorld,short PixelDepth,const Rect *boundsRect,
  30.                         CTabHandle cTable,GDHandle aGDevice,GWorldFlags flags);
  31. short FindStringHeight( Str255 theString, short theFont, short theFace, short theSize );
  32. short FindChar( char theChar, Str255 theString, short index, Str255 partialString );
  33. void MyDrawString( Str255 theString, Point topLeft, short theFont, short theFace, short theSize );
  34.  
  35. /*==================================================================================*/
  36. pascal void DrawCredits(DialogPtr theDialog,PicHandle creditsPicture, short *textOffset) {
  37.  
  38.     Rect            itsRect;
  39.     Rect            creditsWorldRect;
  40.     Str255            credits;
  41.     short            itsID;
  42.     Point            where;
  43.     GWorldPtr        creditsGWorld = NULL;
  44.     PixMapHandle    creditsPixmap;
  45.     OSErr            err = noErr;
  46.     CGrafPtr        oldPort = NULL;
  47.     GDHandle        oldGDevice;
  48.     RGBColor        oldColor;
  49.     RGBColor        briteWhite = { 0xFFFF, 0xFFFF, 0xFFFF };
  50.     RgnHandle        itsClip = NewRgn();
  51.     RgnHandle        oldClip = NewRgn();
  52.     short            stringHeight;
  53.     
  54.     if ( TickCount() < gNextCredits) 
  55.         return;
  56.             
  57.     gNextCredits = TickCount() + 5;
  58.  
  59.     GetFNum("\pPalatino", &itsID);
  60.         
  61.     // Get the credits from a string resource.
  62.     GetIndString( credits, 128, 4);
  63.     
  64.     // Get the rect of this dialog item (GetDitem)
  65.     itsRect = creditsWorldRect = (**creditsPicture).picFrame;
  66.     
  67.     // Create a GWorld in which to image the picture offscreen.
  68.     err = MyNewGWorld( &creditsGWorld, 0, &creditsWorldRect, NULL, NULL, 0);
  69.  
  70.     if ( err == noErr) {
  71.     
  72.         // Save the old GWorld
  73.         GetGWorld( &oldPort, &oldGDevice);
  74.         
  75.         // Set to our new GWorld
  76.         SetGWorld( creditsGWorld, NULL);
  77.  
  78.         // Set up ahead of time by "gCreditsPicture = (PicHandle)GetResource( 'PICT', 128);"
  79.         if ( creditsPicture)
  80.             DrawPicture( creditsPicture, &(**creditsPicture).picFrame);
  81.         else
  82.             EraseRect( &creditsWorldRect);
  83.  
  84.         // Routine to find the text height for a string with embedded carriage returns
  85.         stringHeight = FindStringHeight( credits, itsID, bold, 12);
  86.             
  87.         if (*textOffset < (itsRect.top - stringHeight)) {
  88.             *textOffset = itsRect.bottom;
  89.             }
  90.             
  91.         SetPt( &where, itsRect.left, itsRect.top + (*textOffset)--);
  92.         
  93.         GetForeColor( &oldColor);
  94.         RGBForeColor( &briteWhite);
  95.  
  96.         GetClip( oldClip);
  97.         RectRgn( itsClip, &itsRect);
  98.  
  99.         // Clip to this area
  100.         SetClip( itsClip);
  101.         
  102.         // Draws the string
  103.         MyDrawString( credits, where, itsID, bold, 12);
  104.  
  105.         SetClip( oldClip);
  106.         RGBForeColor( &oldColor);
  107.         
  108.         // Blast the GWorld onto the dialog.
  109.         creditsPixmap = GetGWorldPixMap( creditsGWorld);
  110.         if ( LockPixels( creditsPixmap)) {
  111.             CopyBits ( (BitMap *)*creditsPixmap,  &theDialog->portBits,
  112.                         &creditsWorldRect, &creditsWorldRect, srcCopy, nil);
  113.             UnlockPixels( creditsPixmap);
  114.             }
  115.         }
  116.         
  117.     if ( creditsGWorld)
  118.         DisposeGWorld( creditsGWorld);
  119.  
  120.     if ( oldPort)
  121.         SetGWorld( oldPort, oldGDevice);
  122.     
  123.     if ( itsClip)
  124.         DisposeRgn( itsClip);
  125.  
  126.     if ( oldClip)
  127.         DisposeRgn( oldClip);
  128.         
  129.     return;
  130.  
  131. }
  132.  
  133. /*======================================================================*/
  134. pascal QDErr MyNewGWorld(GWorldPtr *offscreenGWorld,short PixelDepth,const Rect *boundsRect,
  135.     CTabHandle cTable,GDHandle aGDevice,GWorldFlags flags) {
  136.     
  137.     QDErr    err = noErr;
  138.  
  139.     err = NewGWorld(offscreenGWorld, PixelDepth, boundsRect,
  140.                 cTable, aGDevice, flags);
  141.     if ( err == memFullErr)
  142.         err = NewGWorld(offscreenGWorld, PixelDepth, boundsRect,
  143.                         cTable, aGDevice, flags | useTempMem);
  144.     return( err);
  145.     }
  146.  
  147. /*==================================================================================*/
  148. short FindStringHeight( Str255 theString, short theFont, short theFace, short theSize ) {
  149.  
  150.     GrafPtr thePort;
  151.     short saveFont;
  152.     short saveFace;
  153.     short saveSize;
  154.     FontInfo fInfo;
  155.     short lineHeight;
  156.     short lineBase;
  157.     short crIndex;
  158.     Str255 lineString;
  159.  
  160.     GetPort( &thePort );
  161.     saveFont = thePort->txFont;
  162.     saveFace = thePort->txFace;
  163.     saveSize = thePort->txSize;
  164.     TextFont( theFont );
  165.     TextFace( theFace );
  166.     TextSize( theSize );
  167.     GetFontInfo( &fInfo );
  168.     lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  169.     lineBase = fInfo.ascent + fInfo.descent;
  170.     crIndex = FindChar( 0x0D, theString, 1, lineString );
  171.     while( crIndex < theString[0] ) {
  172.         lineBase += lineHeight;
  173.         crIndex = FindChar( 0x0D, theString, crIndex + 1, lineString );
  174.         }
  175.     thePort->txFont = saveFont;
  176.     thePort->txFace = saveFace;
  177.     thePort->txSize = saveSize;
  178.     
  179.     return( lineBase);
  180.  
  181.     }
  182. /*==================================================================================*/
  183. short FindChar( char theChar, Str255 theString, short index, Str255 partialString ) {
  184. /* Searches for the specified char from the indexth mark in theString. Also stops    */
  185. /* at the strings end. partialString will be set to a pascal string with all the    */
  186. /* intermediate chars (it does not include the one being searched for).                */
  187.  
  188.     short newIndex;
  189.  
  190.     newIndex = index;
  191.     while( newIndex <= theString[0] && theString[newIndex] != theChar )
  192.         newIndex++;
  193.  
  194.     partialString[0] = newIndex - index;
  195.     BlockMove( &theString[index], &partialString[1], partialString[0] );
  196.  
  197.     return( newIndex );
  198.     }
  199. /*==================================================================================*/
  200. void MyDrawString( Str255 theString, Point topLeft, short theFont, short theFace, short theSize ) {
  201.  
  202.     GrafPtr thePort;
  203.     short saveFont;
  204.     short saveFace;
  205.     short saveSize;
  206.     FontInfo fInfo;
  207.     short lineHeight;
  208.     short lineBase;
  209.     short crIndex;
  210.     Str255 lineString;
  211.  
  212.     GetPort( &thePort );
  213.     saveFont = thePort->txFont;
  214.     saveFace = thePort->txFace;
  215.     saveSize = thePort->txSize;
  216.     TextFont( theFont );
  217.     TextFace( theFace );
  218.     TextSize( theSize );
  219.     GetFontInfo( &fInfo );
  220.     lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  221.     lineBase = fInfo.ascent + fInfo.descent;
  222.     MoveTo( topLeft.h, topLeft.v + lineBase );
  223.     crIndex = FindChar( 0x0D, theString, 1, lineString );
  224.     while( crIndex < theString[0] ) {
  225.         DrawString( lineString );
  226.         lineBase += lineHeight;
  227.         MoveTo( topLeft.h, topLeft.v + lineBase );
  228.         crIndex = FindChar( 0x0D, theString, crIndex + 1, lineString );
  229.         }
  230.     DrawString( lineString );
  231.     thePort->txFont = saveFont;
  232.     thePort->txFace = saveFace;
  233.     thePort->txSize = saveSize;
  234.     }
  235. /*==================================================================================*/
  236.  
  237.