home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / MacSource / AboutBox.c next >
Encoding:
C/C++ Source or Header  |  1997-01-26  |  11.4 KB  |  408 lines  |  [TEXT/CWIE]

  1. /*==============================================================================
  2. Project:    POV
  3.  
  4. Version:    3
  5.  
  6. File:        AboutBox.c
  7.  
  8. Description:
  9.     Routines to Display the About Box.
  10. ------------------------------------------------------------------------------
  11. Author:
  12.     Eduard [esp] Schwan
  13. ------------------------------------------------------------------------------
  14.     from Persistence of Vision(tm) Ray Tracer
  15.     Copyright 1996 Persistence of Vision Team
  16. ------------------------------------------------------------------------------
  17.     NOTICE: This source code file is provided so that users may experiment
  18.     with enhancements to POV-Ray and to port the software to platforms other 
  19.     than those supported by the POV-Ray Team.  There are strict rules under
  20.     which you are permitted to use this file.  The rules are in the file
  21.     named POVLEGAL.DOC which should be distributed with this file. If 
  22.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  23.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  24.     Forum.  The latest version of POV-Ray may be found there as well.
  25.  
  26.     This program is based on the popular DKB raytracer version 2.12.
  27.     DKBTrace was originally written by David K. Buck.
  28.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  29. ------------------------------------------------------------------------------
  30. Change History:
  31.     950420    [esp]    Made really cool scrolling about box for 3.0.
  32.     960101    [esp]    Handle multiple depth monitors properly
  33.     960122    [esp]    rearranged toolbox calls so it wasn't dreadfully slow
  34.     960520    [esp]    Enlarge text-scroll area so text smoothly scrolls onto screen
  35. ==============================================================================*/
  36.  
  37. #define ABOUTBOX_C
  38.  
  39. #include "AboutBox.h"
  40.  
  41. #include <windows.h>
  42. #include <dialogs.h>
  43. #include <resources.h>    // GetResource
  44. #include <TextUtils.h>    // GetIndString
  45. #include <string.h>        // strcpy
  46. #include <strings.h>    // c2pstr
  47.  
  48. #include "UtilLib.h"
  49. #include "PovMac.h"        // gp2wWindow
  50. #include "fileprefs.h"    // g_prefs2use
  51. #include "OptOut.h"        // POV_RAY_VERSION
  52.  
  53.  
  54. #define    STR_ABOUT_ID    130
  55. #define    DITL_PICT_ID    1
  56.  
  57. // how many pixels to scroll per update
  58. #define SCROLL_PIXELS        1
  59.  
  60. // how many ticks to wait between updates
  61. #define kInterScrollTicks    3
  62.  
  63. static    FontInfo    gFontInfo;
  64. static    GWorldPtr    gTextGW;    // foreground scrolling text area
  65. static    GWorldPtr    gImageGW;    // background image area
  66. static    GWorldPtr    gDestGW;    // final mixing area
  67. static    short        gStringIndex;
  68. static    short        gScrollCount;
  69. static    short        gFontHeight;
  70. static    Rect        gTextR;
  71. static    Rect        gPictR;
  72. static    PicHandle    gPictH;
  73.  
  74.  
  75. // ---------------------------------------------------------------------
  76. // Returns the short version string in the application's version resource
  77. void GetAppVersionPString(short versID, Str31 versionString)
  78. {
  79.     short            oldRefNum;
  80.     VersRecHndl        versHandle;        // VersRecHndl declared in types.h
  81.  
  82.     oldRefNum = CurResFile();
  83.     
  84.     /* Get the resource string from app, 'vers' versID (1 or 2) resource! */
  85.     UseResFile(gAppRefNum); // gAppRefNum is from pov.c
  86.     versHandle = (VersRecHndl)Get1Resource('vers',versID);
  87.     if (versHandle)
  88.     {
  89.         HLock((Handle)versHandle);
  90.         BlockMove((**versHandle).shortVersion, versionString, (**versHandle).shortVersion[0]+1);
  91.         ReleaseResource((Handle)versHandle);
  92. /*
  93.         if ( (**gPrefs2Use_h).progress >= eProgDebug )
  94.             printf("-d vers rsrcID=%d, vers#=%d.%d[%d]%d versStr=%p\n",
  95.                     versID,
  96.                     (**versHandle).numericVersion.majorRev,
  97.                     (**versHandle).numericVersion.minorAndBugRev,
  98.                     (**versHandle).numericVersion.stage,
  99.                     (**versHandle).numericVersion.nonRelRev,
  100.                     versionString);
  101. */
  102.     }
  103.     else
  104.         {
  105.         versionString[0] = 0;
  106.         SysBeep(1); // minor problem
  107.         }
  108.     // return to original resfile
  109.     UseResFile(oldRefNum);
  110. } // GetAppVersionPString
  111.  
  112.  
  113. // ------------------------------------------------------------------
  114. static void SetupPortFont(GWorldPtr theGWorld)
  115. {
  116.     SetGWorld(theGWorld, NULL); // 32bit QD
  117.     // set the font in the grafport
  118.     TextFont(times);
  119.     TextSize(14);
  120.     // find out font size info
  121.     GetFontInfo(&gFontInfo);
  122.     gFontHeight = gFontInfo.descent + gFontInfo.ascent +  gFontInfo.leading;
  123. } // SetupPortFont
  124.  
  125.  
  126. // ---------------------------------------------------------------------
  127. static OSErr CreateOffScreens(WindowPtr screenWindow, Rect *theRect)
  128. {
  129.     OSErr    anError;
  130.     // determine current screen depth
  131.     short    screenDepth = (**((CGrafPtr)screenWindow)->portPixMap).pixelSize;
  132.     // create foreground text offscreen
  133.     anError = NewGWorld(&gTextGW, screenDepth, theRect, NULL, NULL, 0);
  134.     // create background image offscreen
  135.     if (!anError)
  136.         anError = NewGWorld(&gImageGW, screenDepth, theRect, NULL, NULL, 0);
  137.     // create final mixing offscreen
  138.     if (!anError)
  139.         anError = NewGWorld(&gDestGW, screenDepth, theRect, NULL, NULL, 0);
  140.     return anError;
  141. } // CreateOffScreens
  142.  
  143.  
  144. // ---------------------------------------------------------------------
  145. static void KillOffScreens(void)
  146. {
  147.     if (gTextGW)
  148.     {
  149.         DisposeGWorld(gTextGW); // 32bit QD
  150.         gTextGW = NULL;
  151.     }
  152.     if (gImageGW)
  153.     {
  154.         DisposeGWorld(gImageGW); // 32bit QD
  155.         gImageGW = NULL;
  156.     }
  157.  
  158.     if (gDestGW)
  159.     {
  160.         DisposeGWorld(gDestGW); // 32bit QD
  161.         gDestGW = NULL;
  162.     }
  163. } // KillOffScreens
  164.  
  165.  
  166. // ---------------------------------------------------------------------
  167. static OSErr SetupMarquee(DialogPtr myDialog, short pictID)
  168. {
  169.     OSErr        anError;
  170.     GWorldPtr    saveGWorld;
  171.     GDHandle    saveGD;
  172.     short        pItemType;
  173.  
  174.     GetGWorld(&saveGWorld, &saveGD);
  175.  
  176.     // Find font size information (Warning: ugly side-effect changes dialog's font!)
  177.     SetupPortFont((GWorldPtr)myDialog);
  178.     
  179.     // find the pict and its rectangle size
  180.     GetDialogItem(myDialog, pictID, &pItemType, (Handle*)&gPictH, &gPictR);
  181.  
  182.     // Create another Rect that is a little longer than the Pict, by one text line.
  183.     // This will allow us to write the text just under the bottom of the window,
  184.     // and scroll it into view.
  185.     gTextR = gPictR;
  186.     gTextR.bottom += gFontHeight;
  187.     
  188.     // set up offscreens with this rect
  189.     anError = CreateOffScreens(myDialog, &gTextR);
  190.  
  191.     if (!anError)
  192.         {
  193.         // change text offscreen font to correct font
  194.         SetupPortFont(gTextGW);
  195.         // Clear text offscreen to white
  196.         SetGWorld((CGrafPtr)gTextGW, NULL);
  197.         LockPixels(((CGrafPtr)gTextGW)->portPixMap);
  198.         EraseRect(&gTextR);
  199.         UnlockPixels(((CGrafPtr)gTextGW)->portPixMap);
  200.         // Fill image offscreen to white (in case there is transparent area)
  201.         SetGWorld((CGrafPtr)gImageGW, NULL);
  202.         LockPixels(((CGrafPtr)gImageGW)->portPixMap);
  203.         EraseRect(&gTextR);
  204.         // fill gworld with picture
  205.         SetGWorld((CGrafPtr)gImageGW, NULL);
  206.         HLock((Handle)gPictH);
  207.         DrawPicture(gPictH, &gPictR);
  208.         HUnlock((Handle)gPictH);
  209.         UnlockPixels(((CGrafPtr)gImageGW)->portPixMap);
  210.         }
  211.  
  212.     gScrollCount = 0;
  213.     gStringIndex = 0;
  214.  
  215.     SetGWorld((CGrafPtr)saveGWorld, saveGD); // 32bit QD
  216.     return anError;
  217. } // SetupMarquee
  218.  
  219.  
  220. // ---------------------------------------------------------------------
  221. static void KillMarquee(void)
  222. {
  223.     KillOffScreens();
  224. } // KillMarquee
  225.  
  226.  
  227. // ---------------------------------------------------------------------
  228. static void UpdateMarquee(WindowPtr theAboutBox)
  229. {
  230.     short        strH, strV;
  231.     short        theTextMode = srcBic;
  232.     RGBColor    rgbBlack    = {0x0000, 0x0000, 0x0000};
  233. //    RGBColor    rgbDrkBlue    = {0x0000, 0x0000, 0x2000};
  234.     RGBColor    rgbCream    = {0xfcff, 0xfeff, 0xffff};
  235.     RGBColor    rgbWhite    = {0xffff, 0xffff, 0xffff};
  236.     Str255        theString;
  237.  
  238.     // refill dest gworld with picture
  239.     SetGWorld((CGrafPtr)gDestGW, NULL);
  240.     RGBBackColor(&rgbWhite);
  241.     RGBForeColor(&rgbBlack);
  242.     CopyBits(    (BitMap *)(*((CGrafPtr)gImageGW)->portPixMap),
  243.                 (BitMap *)(*((CGrafPtr)gDestGW)->portPixMap),
  244.                 &gPictR,
  245.                 &gPictR,
  246.                 ditherCopy, NULL);
  247.  
  248.     // scroll text up slowly
  249.     SetGWorld((CGrafPtr)gTextGW, NULL);
  250.     ScrollRect(&gTextR, 0, -SCROLL_PIXELS, NULL);
  251.     gScrollCount += SCROLL_PIXELS;
  252.     if (gScrollCount > gFontHeight)
  253.     {
  254.         // get next string
  255.         gStringIndex++;
  256.         GetIndString(theString, STR_ABOUT_ID, gStringIndex);
  257.         if (!theString[0]) // past last string?
  258.             gStringIndex = 0;
  259.         // if string has a leading space, it is a heading, make it bold
  260.         if (theString[1] == ' ') // Pascal string, remember!
  261.             TextFace(bold);
  262.         else
  263.             TextFace(0);
  264.         // center it
  265.         strH = (gTextR.right - gTextR.left - StringWidth(theString)) >> 1;
  266.         strV = gTextR.bottom-gFontInfo.descent-gFontInfo.leading-2;
  267.         MoveTo(strH, strV);
  268.         RGBBackColor(&rgbWhite);
  269.         RGBForeColor(&rgbBlack);
  270.         // display it
  271.         DrawString(theString);
  272.         gScrollCount = 0;  // reset counter, wait for another word height
  273.     }
  274.  
  275.     // Copy text over dest
  276.     SetGWorld((CGrafPtr)gDestGW, NULL);
  277.     RGBBackColor(&rgbCream);
  278.     RGBForeColor(&rgbWhite);
  279.     CopyBits(    (BitMap *)(*((CGrafPtr)gTextGW)->portPixMap),
  280.                 (BitMap *)(*((CGrafPtr)gDestGW)->portPixMap),
  281.                 &gTextR,
  282.                 &gTextR,
  283.                 theTextMode, NULL);
  284.  
  285.     //
  286.     // blast the offscreen to the window
  287.     //
  288.  
  289.     SetGWorld((CGrafPtr)theAboutBox, NULL);
  290.     RGBBackColor(&rgbWhite);
  291.     RGBForeColor(&rgbBlack);
  292.     CopyBits(    (BitMap *)(*((CGrafPtr)gDestGW)->portPixMap),
  293.                 (BitMap *)*(((CGrafPtr)theAboutBox)->portPixMap),
  294.                 &gPictR,
  295.                 &gPictR,
  296.                 srcCopy, NULL);
  297.  
  298.  
  299. } // UpdateMarquee
  300.  
  301.  
  302. // ---------------------------------------------------------------------
  303. // Display Application About Box
  304. void DoAboutBox(void)
  305. {
  306.     OSErr        anError;
  307.     long        nextTick;
  308.     Boolean        allDone = false;
  309.     Boolean        specialAbout = false;
  310.     DialogPtr    myDialog;
  311.     EventRecord    anEvent;
  312.     char        povVers[16],
  313.                 compilerName[16],
  314.                 compDate[32];
  315.     GWorldPtr    saveGWorld;
  316.     GDHandle    saveGD;
  317.  
  318.     GetGWorld(&saveGWorld, &saveGD);
  319.  
  320.     // grab the dialog into memory
  321.     myDialog = GetNewDialog(130, NULL, (WindowPtr) -1);
  322.     if (myDialog)
  323.     {
  324. /*
  325.         // check for special info-key for about box
  326.         if (gTheEvent.modifiers & optionKey)
  327.         {
  328.             specialAbout = true;
  329.             PlayNotifySound();
  330.         }
  331. */
  332.         strcpy(compDate, "Compiled: ");
  333.         strcat(compDate, __DATE__);
  334.         c2pstr(compDate);
  335.  
  336.         strcpy(povVers, POV_RAY_VERSION);
  337.         c2pstr(povVers);
  338.  
  339.         strcpy(compilerName, COMPILER_VER);
  340.         c2pstr(compilerName);
  341.  
  342.         GetAppVersionPString(1, (StringPtr)povVers);
  343.  
  344.         ParamText(    (StringPtr)povVers,
  345.                     (StringPtr)compilerName,
  346.                     (StringPtr)compDate,
  347.                     (StringPtr)gDistMessage);
  348.  
  349.         /* set up marquee graphics stuff */
  350.         anError = SetupMarquee(myDialog, DITL_PICT_ID);
  351.  
  352.         /* Get into dialog's port & fiddle with fonts.. */
  353.         SetPort((GrafPtr)myDialog);
  354.         SetDialogFont(geneva); // Hack, should use GetFNum()
  355.         TextFont(geneva); // Hack, should use GetFNum()
  356.         TextSize(9);
  357.  
  358.         PositionWindow(myDialog, ewcDoCentering, eSameAsPassedWindow, (WindowPtr)gp2wWindow);
  359.  
  360.         ShowWindow(myDialog);
  361.         DrawDialog(myDialog);
  362.         nextTick = TickCount()+3*60; // wait several seconds before starting
  363.  
  364.     // lock down the pixmap memory
  365.     LockPixels( ((CGrafPtr)gTextGW)->portPixMap );
  366.     LockPixels( ((CGrafPtr)gImageGW)->portPixMap );
  367.     LockPixels( ((CGrafPtr)gDestGW)->portPixMap );
  368.  
  369.         if (!anError)
  370.             do {
  371.                 if (TickCount() >= nextTick)
  372.                     {
  373.                     nextTick = TickCount()+kInterScrollTicks; // wait N ticks between scrolls
  374.                     UpdateMarquee(myDialog);
  375.                     }
  376.                 if (Button() || EventAvail(mDownMask+keyDownMask, &anEvent))
  377.                     {
  378.                     FlushEvents(mDownMask+keyDownMask, 0);
  379.                     allDone = true;
  380.                     }
  381.             } while (!allDone);
  382.  
  383.         UnlockPixels( ((CGrafPtr)gTextGW)->portPixMap );
  384.         UnlockPixels( ((CGrafPtr)gImageGW)->portPixMap );
  385.         UnlockPixels( ((CGrafPtr)gDestGW)->portPixMap );
  386.  
  387.         // Let some events sneak through before tearing down window.
  388.         // This lets users do FKEY3 screen snapshots of about box, for example.
  389.         {
  390.         int    k;
  391.         for (k=1; k<5; k++)
  392.             Cooperate(true);
  393.         }
  394.  
  395.         KillMarquee();
  396.  
  397.         SetDialogFont(0); // Hack, should use GetFNum()
  398.  
  399.         DisposeDialog(myDialog);
  400.     }
  401.  
  402.     // restore previous Grafport
  403.     SetGWorld((CGrafPtr)saveGWorld, saveGD); // 32bit QD
  404.  
  405. } // DoAboutBox
  406.  
  407.  
  408.