home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / MSG Shell ƒ / msg about.c next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  6.0 KB  |  244 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg about.c
  4.  
  5. Purpose:    This module handles the about boxes and that funky animation
  6.             in the "About MSG" about box.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg about.h"
  30. #include "msg graphics.h"
  31. #include "msg sounds.h"
  32. #include "msg prefs.h"
  33.  
  34. extern Point RawMouse : 0x82C;
  35.  
  36. PicHandle        gAboutColorPict;
  37. PicHandle        gAboutBWPict;
  38.  
  39. void DoTheMSGThing(void)
  40. {
  41.     /* assumes "About MSG" window (gTheWindow[kAboutMSG]) is the front window */
  42.     
  43.     Rect            sourceRect, destRect;
  44.     Rect            mainRect;
  45.     long            lr,tb;
  46.     int                l,t;
  47.     
  48.     mainRect=gMainScreenBounds;
  49.     mainRect.top-=MBarHeight;
  50.     if (PtInRect(RawMouse, &mainRect))
  51.     {
  52.         mainRect=gMainScreenBounds;
  53.         lr=RawMouse.h-mainRect.left;
  54.         lr*=81;
  55.         lr/=mainRect.right-mainRect.left;
  56.         tb=RawMouse.v-mainRect.top;
  57.         tb*=81;
  58.         tb/=mainRect.bottom-mainRect.top;
  59.         if (tb<0)
  60.             tb=0;
  61.         l=RawMouse.h-lr;
  62.         t=RawMouse.v-tb;
  63.         SetRect(&sourceRect, l, t, l+81, t+81);
  64.         SetRect(&destRect, 81, 81, 162, 162);
  65.         CopyBits(&(WMgrPort->portBits), &(gTheWindow[kAboutMSG]->portBits),
  66.             &sourceRect, &destRect, 0, 0L);
  67.     }
  68. }
  69.  
  70. void ShowInformation(void)
  71. {
  72.     OpenTheWindow(kAbout);
  73. }
  74.  
  75. void ShowSplashScreen(void)
  76. {
  77.     DoSound(sound_aboutMSG, TRUE);
  78.     OpenTheWindow(kAboutMSG);
  79. }
  80.  
  81. void DrawTheCarpet(void)
  82. {
  83.     int                row;
  84.     Rect            sourceRect, destRect;
  85.     GrafPtr            curPort;
  86.     
  87.     GetPort(&curPort);
  88.     EraseRect(&(curPort->portRect));
  89.     
  90.     DrawCarpet(9,234,3);
  91.     SetRect(&sourceRect, 0, 216, 27, 243);
  92.     destRect=sourceRect;
  93.     OffsetRect(&destRect, 27, 0);
  94.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  95.         &sourceRect, &destRect, 0, 0L);
  96.     OffsetRect(&destRect, -27, -27);
  97.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  98.         &sourceRect, &destRect, 0, 0L);
  99.     OffsetRect(&destRect, 0, -27);
  100.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  101.         &sourceRect, &destRect, 0, 0L);
  102.     OffsetRect(&destRect, 27, 0);
  103.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  104.         &sourceRect, &destRect, 0, 0L);
  105.     SetRect(&sourceRect, 0, 162, 27, 243);
  106.     destRect=sourceRect;
  107.     OffsetRect(&destRect, 54, 0);
  108.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  109.         &sourceRect, &destRect, 0, 0L);
  110.     SetRect(&sourceRect, 0, 162, 81, 243);
  111.     destRect=sourceRect;
  112.     OffsetRect(&destRect, 81, 0);
  113.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  114.         &sourceRect, &destRect, 0, 0L);
  115.     OffsetRect(&destRect, -81, -81);
  116.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  117.         &sourceRect, &destRect, 0, 0L);
  118.     OffsetRect(&destRect, 0, -81);
  119.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  120.         &sourceRect, &destRect, 0, 0L);
  121.     OffsetRect(&destRect, 81, 0);
  122.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  123.         &sourceRect, &destRect, 0, 0L);
  124.     SetRect(&sourceRect, 0, 0, 81, 243);
  125.     destRect=sourceRect;
  126.     OffsetRect(&destRect, 162, 0);
  127.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  128.         &sourceRect, &destRect, 0, 0L);
  129.     
  130.     TextFont(geneva);
  131.     TextSize(9);
  132.     TextMode(srcXor);
  133.     row=92;
  134.     DrawTheString("\pMerriMac", &row);
  135.     DrawTheString("\pSoftware", &row);
  136.     DrawTheString("\pGroup ’94", &row);
  137.     DrawTheString("\p", &row);
  138.     DrawTheString("\pStill enhancing", &row);
  139.     DrawTheString("\pthe flavor of", &row);
  140.     DrawTheString("\pyour Macintosh.", &row);
  141. }
  142.  
  143. void DrawTheString(Str255 theString, int* theRow)
  144. {
  145.     MoveTo((gWindowWidth[kAboutMSG]-StringWidth(theString))/2, *theRow);
  146.     DrawString(theString);
  147.     *theRow+=11;
  148. }
  149.  
  150. void DrawCarpet(int x, int y, int len)
  151. {
  152.     Rect            box;
  153.     int                iter;
  154.  
  155.     x-=len*2;
  156.     y+=len*2;
  157.     for (iter=0; iter<8; iter++)
  158.     {
  159.         box.left=x-len;
  160.         box.right=x+2*len;
  161.         box.top=y-2*len;
  162.         box.bottom=y+len;
  163.         FillRect(&box, black);
  164.         if (len>1) DrawCarpet(x,y,len/3);
  165.         box.left=x;
  166.         box.right=x+len;
  167.         box.bottom=y;
  168.         box.top=y-len;
  169.         FillRect(&box, white);
  170.         switch (iter)
  171.         {
  172.             case 0:
  173.             case 1: x+=len*3; break;
  174.             case 2:
  175.             case 3: y-=len*3; break;
  176.             case 4:
  177.             case 5: x-=len*3; break;
  178.             case 6:
  179.             case 7: y+=len*3; break;
  180.         }
  181.     }
  182. }
  183.  
  184. void DrawTheAboutBox(Boolean isColor)
  185. {
  186.     int                row;
  187.     Handle            textHandle;
  188.     Str255            theLine;
  189.     unsigned long    pos;
  190.     unsigned long    theSize;
  191.     GrafPtr            curPort;
  192.     
  193.     GetPort(&curPort);
  194.     EraseRect(&(curPort->portRect));
  195.     DrawThePicture(isColor ? &gAboutColorPict : &gAboutBWPict, isColor ? kAboutColorID :
  196.         kAboutBWID, 0, 0);
  197.     
  198.     TextFont(geneva);
  199.     TextSize(9);
  200.     TextMode(srcCopy);
  201.     if (isColor)
  202.         ForeColor(blueColor);
  203.     row=16;
  204.     textHandle=GetResource('TEXT', 128);
  205.     if (textHandle==0L)
  206.         return;
  207.     if (*textHandle==0L)
  208.         LoadResource(textHandle);
  209.     if (*textHandle==0L)
  210.         return;
  211.     pos=0L;
  212.     theSize=SizeResource(textHandle);
  213.     do
  214.     {
  215.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  216.         DrawTheAboutString(theLine, &row);
  217.     }
  218.     while (pos<theSize);
  219.     ReleaseResource(textHandle);
  220.     if (isColor)
  221.         ForeColor(redColor);
  222.     DrawTheAboutString("\pThis copy is registered to", &row);
  223.     DrawTheAboutString(gMyName, &row);
  224.     DrawTheAboutString(gMyOrg, &row);
  225.     if (isColor)
  226.         ForeColor(blackColor);
  227. }
  228.  
  229. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  230. {
  231.     unsigned char    theChar;
  232.     
  233.     theLine[0]=0x00;
  234.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  235.         theLine[++theLine[0]]=theChar;
  236. }
  237.  
  238. void DrawTheAboutString(Str255 theString, int *theRow)
  239. {
  240.     MoveTo(293-StringWidth(theString)/2, *theRow);
  241.     DrawString(theString);
  242.     *theRow+=12;
  243. }
  244.