home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware in MacFormat / brailler0.5b / brlr ƒ / Shell ƒ / about MSG.c next >
Encoding:
C/C++ Source or Header  |  1994-12-20  |  5.3 KB  |  191 lines  |  [TEXT/MMCC]

  1. #include "about MSG.h"
  2. #include "styled text.h"
  3. #include "pict utilities.h"
  4. #include "window layer.h"
  5. #include "graphics.h"
  6.  
  7. /*-----------------------------------------------------------------------------------*/
  8. /* internal stuff for about MSG.c                                                    */
  9.  
  10. static    void DoTheMSGThing(WindowPtr theWindow);
  11. static    void AboutMSGEventLoop(WindowPtr theWindow);
  12.  
  13. static    PicHandle    gAboutPict=0L;
  14. static    CharHandle    gAboutText=0L;
  15. static    StylHandle    gAboutStyle=0L;
  16.  
  17. static    Ptr            gOffscreenBitMap=0L;
  18. static    GrafPort    gOffscreenGrafPort;
  19. static    GrafPtr        gOffscreenGrafPtr=0L;
  20.  
  21. static    Boolean        gSetupDone=FALSE;
  22.  
  23. #define MAX_OFFSCREEN_LINES    5
  24. #define kOffscreenWidth        130
  25. #define kOffscreenHeight    ((MAX_OFFSCREEN_LINES*12)+1)
  26. #define RIGHT_SLOP            13
  27. #define TOP_SLOP            29
  28.  
  29. #define    kAboutTextID        150
  30.  
  31. void SetupTheAboutMSGWindow(WindowPtr theWindow)
  32. {
  33.     long            offRowBytes, sizeOfOff;
  34.     unsigned char    *titleStr="\p";
  35.     
  36.     SetWindowWidth(theWindow, 324);
  37.     SetWindowHeight(theWindow, 199);
  38.     SetWindowType(theWindow, plainDBox);
  39.     SetWindowTitle(theWindow, titleStr);
  40.     SetWindowHasCloseBox(theWindow, FALSE);
  41.     SetWindowMaxDepth(theWindow, 8);
  42.     SetWindowDepth(theWindow, 8);
  43.     SetWindowIsFloat(theWindow, FALSE);
  44.     SetWindowAutoCenter(theWindow, TRUE);
  45.     
  46.     if (gSetupDone)
  47.         return;
  48.     
  49.     gAboutText=(CharHandle)GetResource('TEXT', kAboutTextID);
  50.     gAboutStyle=(StylHandle)GetResource('styl', kAboutTextID);
  51.  
  52.     gOffscreenGrafPtr=&gOffscreenGrafPort;
  53.     OpenPort(&gOffscreenGrafPort);    /* make a new port */
  54.     
  55.     /* calculate the size of the offscreen bitmap from the boundsrect */
  56.     offRowBytes=((GetWindowWidth(theWindow)+15)>>4)<<1;
  57.     sizeOfOff=(long)(GetWindowHeight(theWindow)*offRowBytes);
  58.     
  59.     gOffscreenBitMap=NewPtr(sizeOfOff);        /* allocate space for bitmap */
  60.     
  61.     gOffscreenGrafPort.portBits.baseAddr=gOffscreenBitMap;    /* --> our bitmap */
  62.     gOffscreenGrafPort.portBits.rowBytes=offRowBytes;        /* bitmap size */
  63.     SetRect(&gOffscreenGrafPort.portBits.bounds, 0, 0, kOffscreenWidth, kOffscreenHeight);
  64.     gOffscreenGrafPort.portRect=gOffscreenGrafPort.portBits.bounds;
  65.     
  66.     SetPort(gOffscreenGrafPtr);
  67.     
  68.     gSetupDone=TRUE;
  69. }
  70.  
  71. void ShutDownTheAboutMSGWindow(void)
  72. {
  73.     gAboutPict=ReleaseThePict(gAboutPict);
  74.     if (gOffscreenBitMap!=0L)
  75.     {
  76.         DisposePtr(gOffscreenBitMap);
  77.         ClosePort(&gOffscreenGrafPort);
  78.     }
  79. }
  80.  
  81. void OpenTheMSGWindow(WindowPtr theWindow)
  82. {
  83.     UpdateTheWindow(theWindow);
  84.     AboutMSGEventLoop(theWindow);
  85. }
  86.  
  87. void AboutMSGEventLoop(WindowPtr theWindow)
  88. {
  89.     GrafPtr            oldPort;
  90.     GrafPtr            curPort;
  91.     short            startLine, numLines;
  92.     short            i;
  93.     Rect            sourceRect, destRect;
  94.     Rect            mirrorSourceRect, mirrorDestRect;
  95.     Rect            newSourceRect, newDestRect;
  96.     long            dummy;
  97.     RgnHandle        scrollRgn;
  98.     Rect            ovalRect;
  99.     Boolean            notDoneYet;
  100.     
  101.     GetPort(&oldPort);
  102.     SetPort(curPort=(GrafPtr)theWindow);
  103.     startLine=0;
  104.     numLines=CountLines(gAboutText, gAboutStyle, kCenter, srcXor, gOffscreenGrafPort.portRect);
  105.     SetRect(&sourceRect, curPort->portRect.right-RIGHT_SLOP-kOffscreenWidth,
  106.         TOP_SLOP, curPort->portRect.right-RIGHT_SLOP,
  107.         (curPort->portRect.bottom-curPort->portRect.top)/2);
  108.     OffsetRect(&sourceRect, 0, 1);
  109.     destRect=sourceRect;
  110.     OffsetRect(&destRect, 0, -1);
  111.     mirrorSourceRect=sourceRect;
  112.     mirrorSourceRect.top=sourceRect.bottom-1;
  113.     mirrorSourceRect.bottom=sourceRect.bottom-sourceRect.top+mirrorSourceRect.top;
  114.     mirrorDestRect=mirrorSourceRect;
  115.     OffsetRect(&mirrorDestRect, 0, 1);
  116.     newDestRect=sourceRect;
  117.     newDestRect.top=newDestRect.bottom-1;
  118.     SetRect(&ovalRect, 173, 28, 315, 171);
  119.     scrollRgn=NewRgn();
  120.     OpenRgn();
  121.         FrameOval(&ovalRect);
  122.     CloseRgn(scrollRgn);
  123.     notDoneYet=TRUE;
  124.     
  125.     while (notDoneYet)
  126.     {
  127.         SetPort(gOffscreenGrafPtr);
  128.         FillRect(&(gOffscreenGrafPtr->portRect), &qd.black);
  129.         DrawThePartialText(gAboutText, gAboutStyle, kCenter, srcXor, gOffscreenGrafPort.portRect,
  130.             startLine, startLine+MAX_OFFSCREEN_LINES+1);
  131.         SetPort(curPort);
  132.         
  133.         newSourceRect.top=newSourceRect.left=0;
  134.         newSourceRect.right=kOffscreenWidth;
  135.         newSourceRect.bottom=1;
  136.         for (i=0; ((i<kOffscreenHeight) && ((notDoneYet=(!Button()))==TRUE)); i++)
  137.         {
  138.             CopyBits(&(curPort->portBits), &(curPort->portBits), &sourceRect, &destRect, 0,
  139.                 scrollRgn);
  140.             CopyBits(&(curPort->portBits), &(curPort->portBits), &mirrorSourceRect,
  141.                 &mirrorDestRect, 0, scrollRgn);
  142.             CopyBits(&(gOffscreenGrafPort.portBits), &(curPort->portBits), &newSourceRect,
  143.                 &newDestRect, 0, 0L);
  144.             newSourceRect.top++;
  145.             newSourceRect.bottom++;
  146.             Delay(7, &dummy);
  147.         }
  148.         
  149.         startLine+=MAX_OFFSCREEN_LINES;
  150.         if (startLine>numLines)
  151.             startLine=0;
  152.     }
  153.     
  154.     DisposeRgn(scrollRgn);
  155.     SetPort(oldPort);
  156.     FlushEvents(mouseDown+mouseUp+keyDown+keyUp+autoKey, 0);
  157.     
  158.     CloseTheWindow(theWindow);
  159. }
  160.  
  161. void DrawTheAboutMSGWindow(WindowPtr theWindow, short theDepth)
  162. {
  163.     short            h, w, i;
  164.     Rect            sourceRect, destRect;
  165.     GrafPtr            curPort;
  166.     
  167.     gAboutPict=DrawThePicture(gAboutPict, (theDepth>2) ? 128 : 129, 0, 0);
  168.     if (gAboutPict==0L)
  169.         return;
  170.     
  171.     h=(**gAboutPict).picFrame.bottom-(**gAboutPict).picFrame.top;
  172.     w=(**gAboutPict).picFrame.right-(**gAboutPict).picFrame.left;
  173.     GetPort(&curPort);
  174.     
  175.     SetRect(&sourceRect, 0, 0, w, 1);
  176.     SetRect(&destRect, 0, 2*h-2, w, 2*h-1);
  177.     for (i=0; i<h; i++)
  178.     {
  179.         CopyBits(&(curPort->portBits), &(curPort->portBits), &sourceRect, &destRect, 0, 0L);
  180.         sourceRect.top++;
  181.         sourceRect.bottom++;
  182.         destRect.top--;
  183.         destRect.bottom--;
  184.     }
  185. }
  186.  
  187. void ChangeDepthTheAboutMSGWindow(WindowPtr theWindow, short newDepth)
  188. {
  189.     gAboutPict=ReleaseThePict(gAboutPict);
  190. }
  191.