home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / about.zip / CREDITSW.CLS < prev    next >
Text File  |  1990-07-19  |  13KB  |  442 lines

  1. /* Puts up the MEDSTAT Credits Window. */!!
  2.  
  3. inherit(Window, #CreditsWindow, #(bitmaps    /* dictionary of bitmaps */
  4. colors      /* dictionary of colors */
  5. font                /* Credits font */), 2, nil)!!
  6.  
  7.  
  8. now(class(CreditsWindow))!!
  9.  
  10. /* Return the default window style for an About. */
  11. Def style(self)
  12. { ^WS_POPUP bitOr WS_DLGFRAME;
  13. }!!
  14.  
  15. /* Create and start a new Credits object. */
  16. Def start(self)
  17. { ^new(self, nil, nil, " ", nil);
  18. }!!
  19.  
  20. /* Return static string for this window class name ("ActorCredits"). */
  21. Def wndClass(self)
  22. { ^"CalmCreditsWindow";
  23. }!!
  24.  
  25. now(CreditsWindow)!!
  26.  
  27. /* This space for rent. */
  28. Def drawText(self, str, fontStyle, rect, style | hDC)
  29. { if alive(self)
  30.   then hDC := getContext(self);
  31.        Call SetTextColor(hDC, 0x000000L);
  32.        Call SetBkMode(hDC, TRANSPARENT);
  33.        Call SelectObject(hDC, fontStyle);
  34.        Call DrawText(hDC, asciiz(str), -1, rect, style);
  35.        releaseContext(self, hDC);
  36.   endif;
  37. }
  38. !!
  39.  
  40. /* This space for rent. */
  41. Def getCredit(self, idx | loadStr, strColl, stream, name)
  42. { loadStr := loadString(idx + 2001);
  43.   stream := streamOver(loadStr);
  44.   strColl := new(OrderedCollection, 4);
  45.   loop
  46.   while name := word(stream, ',')
  47.   begin add(strColl, name);
  48.   endLoop;
  49.  
  50.   ^strColl
  51. }
  52. !!
  53.  
  54. /* Scroll the passed rectangle count times by the amount
  55.    specified by point. */
  56. Def scrollRectSlow(self, rect, point, count);    
  57. { alive(self) cand checkMessage();
  58.   if alive(self)
  59.   then
  60.     loop
  61.       Call ScrollWindow(hWnd, x(point), y(point), rect, rect);
  62.       update(self);
  63.     while (count := count - 1) > 0
  64.       delay(self, 50);
  65.     endLoop;
  66.   endif;
  67. }!!
  68.  
  69. /* Draw the credits in movie form. */
  70. Def drawCredits(self | hDC, count, idx, credit, rect1, rect2)
  71. { rect1 := rect(120, 65, 305, 200);
  72.   rect2 := rect(120, 180, 305, 197);
  73.   idx := -1;
  74.   loop
  75.     checkMessage();
  76.   while alive(self) cand (idx := idx + 1) < 10
  77.     credit := getCredit(self, idx);
  78.     do(credit,
  79.       { using(name)
  80.         if name = credit[0]
  81.         then drawText(self, name, font[1], rect2, 0x25);
  82.         else drawText(self, name, font[0], rect2, 0x25);
  83.         endif;
  84.         scrollRectSlow(self, rect1, point(0, -2), (height(rect2) / 2));
  85.       });
  86.     scrollRectSlow(self, rect1, point(0, -2), (height(rect2) / 2)*4);
  87.   endLoop;
  88.   scrollRectSlow(self, rect1, point(0, -2), (height(rect2) / 2)*4);
  89. }
  90. !!
  91.  
  92. /* Return a valid position in the about box for a firework. */
  93. Def getPos(self | x, y)
  94. { x := random(368);
  95.   y := random(165);
  96.   select
  97.     case x < 45                y := min(y, 134)          endCase
  98.     case x >= 55  and x < 185  y := max(65, y)           endCase
  99.     case x >= 185 and x < 342  y := min(max(65, y), 100) endCase
  100.     case x >= 343              y := min(y, 100)          endCase
  101.   endSelect;
  102.   ^point(x,y)
  103. }!!
  104.  
  105. /* Evaluate the drawing block with the passed parameters. */
  106. Def doDraw(self, bitmap, color, aBlk | hDC, hMemDC)
  107. { if alive(self)
  108.   then hDC := getContext(self);
  109.        hMemDC := Call CreateCompatibleDC(hDC);
  110.        Call SelectObject(hMemDC, bitmap[0]);
  111.        if bitmap[5] = SRCCOPY
  112.        then Call SetBkColor(hDC, Call GetNearestColor(hDC, 0xFFFFFFL));
  113.             Call SetTextColor(hDC, color);
  114.        endif;
  115.        if bitmap[5] = NOTSRCCOPY
  116.        then Call SetBkColor(hDC, Call GetNearestColor(hDC, 0x000000L));
  117.             Call SetTextColor(hDC, 0x000000L);
  118.        endif;
  119.        eval(aBlk, bitmap, hDC, hMemDC);
  120.        Call DeleteDC(hMemDC);
  121.        releaseContext(self, hDC);
  122.   endif;
  123. }!!
  124.  
  125. /* Draw the version number bitmap. */
  126. Def drawFirework(self | color, pos, pos)
  127. { color := colors[#(#red, #green, #blue, #purple)[random(4)]];
  128.   pos := getPos(self);
  129.   do(2,
  130.     { using(count)
  131.       doDraw(self, bitmaps[#firework], color,
  132.               { using(bitmapArray, hDC, hMemDC)
  133.                 Call BitBlt(hDC, x(pos)+18, y(pos)+18, 9, 9,
  134.                             hMemDC, 18, 18, bitmapArray[5]);
  135.               });
  136.       delay(self, 250);
  137.           doDraw(self, bitmaps[#firework], color,
  138.               { using(bitmapArray, hDC, hMemDC)
  139.                 Call BitBlt(hDC, x(pos)+9, y(pos)+9, 27, 27, 
  140.                             hMemDC, 9, 9, bitmapArray[5]);
  141.               });
  142.       delay(self, 250);
  143.          doDraw(self, bitmaps[#firework], color,
  144.               { using(bitmapArray, hDC, hMemDC)
  145.                 Call BitBlt(hDC, x(pos), y(pos), 45, 45, 
  146.                             hMemDC, 0, 0, bitmapArray[5]);
  147.               });
  148.       if alive(self) bitmaps[#firework][5] := NOTSRCCOPY; endif;
  149.     });
  150.   if alive(self) bitmaps[#firework][5] := SRCCOPY; endif;
  151. }!!
  152.  
  153. /* Draw the copyright information. */
  154. Def drawCopyright(self | hDC, count, idx, str, rect1, rect2)
  155. { rect1 := rect(265, 145, 400, 200);
  156.   rect2 := rect(265, 180, 400, 197);
  157.   idx := -1;
  158.   loop
  159.     checkMessage();
  160.   while alive(self) cand (idx := idx + 1) < 3
  161.     scrollRect(self, rect1, point(0, -2), height(rect2) / 2);
  162.     drawText(self, loadString(idx + 1996), font[0], rect2, 0x22);
  163.   endLoop;
  164.   scrollRect(self, rect1, point(0, -2), 2);
  165. }
  166. !!
  167.  
  168. /* Draw the copyright information. */
  169. Def drawVersion(self | hDC, rect1, rect2, path, dir, bounce)
  170. { rect1 := rect(305, 0, 412, 210);
  171.   rect2 := rect(0, 70, 412, 210);
  172.   path := new(Array, 7);
  173.   path[0] := point(-3, -9);  path[4] := point(-3, 1);
  174.   path[1] := point(-3, -4);  path[5] := point(-3, 4);
  175.   path[2] := point(-3, -1);  path[6] := point(-3, 9);
  176.   path[3] := point(-3,  0);
  177.   bounce := #( #(8,8,5,4,5,8,8)
  178.                #(6,6,3,2,3,6,6)
  179.                #(4,4,2,1,2,4,4));
  180.   
  181.   hDC := getContext(self);
  182.   Call SetTextColor(hDC, 0x000000L);
  183.   Call SetBkMode(hDC, TRANSPARENT);
  184.   Call DrawText(hDC, asciiz(loadString(1999)), -1, rect1, 0x22 /*DT_SINGLELINE*/);
  185.   releaseContext(self, hDC);
  186.  
  187.   dir := 5;                         /* Drop it */
  188.   do(#(8,16),
  189.      { using(amount)
  190.        scrollRect(self, rect1, path[dir], amount);
  191.        dir := dir + 1;
  192.      }); 
  193.  
  194.   do(bounce,                         /* bounce it */
  195.        { using(count)
  196.          dir := 0;
  197.          do(count,
  198.            { using(amount)
  199.              scrollRect(self, rect2, path[dir], amount);
  200.              dir := dir + 1;
  201.            })
  202.     });
  203. }!!
  204.  
  205. /* Draw the version number bitmap. */
  206. Def drawLogo(self | bitmapSize, frontCol, tmp)
  207. { bitmapSize := bitmaps[#version][3] / 3;
  208.   frontCol := 0;
  209.   tmp := -1;
  210.   do(overBy(34, 0, -1),
  211.     { using(col)
  212. /* Do a strip of MED */
  213.       doDraw(self, bitmaps[#version], colors[#blue],
  214.             { using(bitmapArray, hDC, hMemDC)
  215.               Call BitBlt(hDC, bitmapArray[1] + (col * 3), bitmapArray[2],
  216.                           3, bitmapArray[4], hMemDC, (col * 3), 0, bitmapArray[5]);
  217.             });
  218.       tmp := tmp + 2;
  219.       frontCol := col + tmp;
  220. /* Do a strip of STAT */
  221.       doDraw(self, bitmaps[#version], colors[#red],
  222.            { using(bitmapArray, hDC, hMemDC)
  223.              Call BitBlt(hDC, bitmapArray[1] + (frontCol * 3), bitmapArray[2],
  224.                          3, bitmapArray[4], hMemDC, (frontCol * 3), 0, bitmapArray[5]);
  225.            });
  226.       delay(self, 75);
  227.   });
  228. /* Finish off STAT */
  229.   do(over(frontCol, bitmapSize),
  230.     { using(col)
  231.       doDraw(self, bitmaps[#version], colors[#red],
  232.             { using(bitmapArray, hDC, hMemDC)
  233.               Call BitBlt(hDC, bitmapArray[1] + (col * 3), bitmapArray[2],
  234.                           3, bitmapArray[4], hMemDC, (col * 3), 0, bitmapArray[5]);
  235.             });
  236.     });
  237. }!!
  238.  
  239. /* Draw the copyright information. */
  240. Def drawSystem2(self | hDC, rect1)
  241. { rect1 := rect(0, 50, 305, 65);
  242.   hDC := getContext(self);
  243.   Call SetTextColor(hDC, 0x000000L);
  244.   Call SetBkMode(hDC, TRANSPARENT);
  245.   Call DrawText(hDC, asciiz("System2"), -1, rect1, 0x20 /*DT_SINGLELINE*/);
  246.   releaseContext(self, hDC);
  247.   scrollRect(self, rect1, point(2, 0), 125);
  248. }!!
  249.  
  250. /* If the window is not closed, then close it. */
  251. Def close(self)
  252. { deleteBitmaps(self);
  253.   close(self:ancestor);
  254. }!!
  255.  
  256. /* Check if window still on screen. */
  257. Def alive(self)
  258. { ^hWnd cand bitmaps cand font
  259. }!!
  260.  
  261. /* Inform the class that there is no longer an
  262.    about window object in the system. */
  263. Def WM_NCDESTROY(self, wp, lp | ret)
  264. { ret := WM_NCDESTROY(self:ancestor, wp, lp);
  265.   ^ret
  266. }!!
  267.  
  268. /* Initialize the window characteristics before showing
  269.    the window. */
  270. Def winit(self | x, y, hDC, logFont)
  271. { x := (x(screenSize()) - 425) / 2;
  272.   y := (y(screenSize()) - 210) / 2;
  273.   setCRect(self, rect(x, y, x+425, y+210));
  274.   moveWindow(self);
  275.  
  276.   /* Set the background to the color nearest dark blue */
  277.   hDC := Call GetDC(0);
  278.   Call SetClassWord(getHWnd(self), GCW_HBRBACKGROUND,
  279.     Call CreateSolidBrush(Call GetNearestColor(hDC, 0xFFFFFFL))
  280.   );
  281.   Call ReleaseDC(0, hDC);
  282.  
  283.   Call SetCapture(hWnd);
  284.   colors := new(Dictionary, 4);
  285.   colors[#red] := 0x0000FF;
  286.   colors[#green] := 0x20FF00;
  287.   colors[#blue] := 0xFF0000;
  288.   colors[#purple] := 0xFF009F;
  289.  
  290.   font := new(Array, 2);
  291.   logFont := new(Struct, 30);  /* Select a variable-pitch font. */
  292.   putWord(logFont, 18, 0);
  293.   putLSB(logFont, 2, 17);
  294.   font[0] := Call CreateFontIndirect(lP(logFont));
  295.   freeHandle(logFont);
  296.  
  297.   putWord(logFont, 700, 8);       /* 700 = bold */
  298.   putWord(logFont, 1, 11);      /* Underline on */
  299.   font[1] := Call CreateFontIndirect(lP(logFont));
  300.   freeHandle(logFont);
  301. }!!
  302.  
  303. /* Paint the about window */
  304. Def WM_TIMER(self, wP, lP)
  305. { Call KillTimer(getHWnd(self), wP);
  306.   if alive(self)
  307.   then update(self);
  308.     drawBox(self);
  309.   endif;
  310.   close(self);
  311. }!!
  312.  
  313. /* Close window when the left mouse button is pressed. */
  314. Def WM_LBUTTONDOWN(self, wP, lP | hDC, x)
  315. { deleteBitmaps(self);
  316. }!!
  317.  
  318. /* Close window when focus is given to another window. */
  319. Def WM_KILLFOCUS(self, wP, lP)
  320. { deleteBitmaps(self);
  321. }!!
  322.  
  323. /* Close window when any key is pressed. */
  324. Def WM_KEYDOWN(self, wP, lP)
  325. { if not(wP in #(16 17))
  326.   then deleteBitmaps(self);
  327.   endif;
  328. }!!
  329.  
  330. /* If bitmaps still exists when the window is destroyed,
  331.   get rid of them. */
  332. Def WM_DESTROY(self, wp, lp)
  333. { if alive(self)
  334.   then deleteBitmaps(self);
  335.   endif;
  336.   Call CloseSound();
  337.   Call DeleteObject(
  338.     Call SetClassWord(hWnd, GCW_HBRBACKGROUND, COLOR_WINDOW + 1)
  339.   );
  340.   Call ReleaseCapture();
  341.   ^WM_DESTROY(self:ancestor, wp, lp);
  342. }!!
  343.  
  344. /* Scroll the passed rectangle count times by the amount
  345.    specified by point. */
  346. Def scrollRect(self, rect, point, count);    
  347. { alive(self) cand checkMessage();
  348.   if alive(self)
  349.   then
  350.     loop
  351.       Call ScrollWindow(hWnd, x(point), y(point), rect, rect);
  352.       update(self);
  353.     while (count := count - 1) > 0
  354.     endLoop;
  355.   endif;
  356. }!!
  357.  
  358. /* Draw the items in the window. */
  359. Def drawBox(self)
  360. { alive(self) cand drawLogo(self);
  361.   delay(self, 1000);
  362.   alive(self) cand drawSystem2(self); 
  363.   delay(self, 1000);
  364.   alive(self) cand drawVersion(self);
  365.   alive(self) cand drawCredits(self); 
  366.   alive(self) cand drawCopyright(self);
  367.   loop
  368.     alive(self) cand drawFirework(self); 
  369.     delay(self, 750);
  370.     while alive(self)    
  371.   endLoop;
  372. }!!
  373.  
  374. /* Delete all the allocated bitmaps. */
  375. Def deleteBitmaps(self)
  376. { do(bitmaps,
  377.   {using(i | hBitmap)
  378.     if (hBitmap := i[0]) <> 0
  379.     then Call DeleteObject(hBitmap);
  380.     endif;
  381.   });
  382.   bitmaps := nil;
  383.   do(size(font),
  384.     { using(idx) Call DeleteObject(font[idx]);
  385.     });
  386.   font := nil;
  387. }!!
  388.  
  389. /* Setup all the bitmaps. */
  390. Def setBitmaps(self | bitmap, struct, mode, hDC)
  391. { bitmaps := new(Dictionary, 8);
  392.   struct := new(Struct, 14);
  393.   
  394.   hDC := Call GetDC(0);
  395.   if (Call GetDeviceCaps(hDC, 24 /*NUMCOLORS*/) < 3)
  396.   then mode := NOTSRCCOPY;
  397.   else mode := SRCCOPY;
  398.   endif;
  399.   Call ReleaseDC(0, hDC);
  400.   
  401.  
  402.   if (bitmap := Call LoadBitmap(HInstance, 900)) <> 0
  403.   then Call GetObject(bitmap, size(struct), struct);
  404.     bitmaps[#version] := tuple(bitmap, 100, 10, wordAt(struct, 2), wordAt(struct, 4), mode);
  405.   else ^nil;
  406.   endif;
  407.  
  408.   if (bitmap := Call LoadBitmap(HInstance, 901)) <> 0
  409.   then Call GetObject(bitmap, size(struct), struct);
  410.     bitmaps[#firework] := tuple(bitmap, 0, 0, wordAt(struct, 2), wordAt(struct, 4), mode);
  411.   else ^nil;
  412.   endif;
  413. }!!
  414.  
  415. /* Initialize the about window object. */
  416. Def init(self | x, y, hDC)
  417. { if not(setBitmaps(self))
  418.   then destroy(self);
  419.     ^nil
  420.   endif;
  421. }!!
  422.  
  423. /* Create and run an Credits Box. */
  424. Def runModal(self, dummy, par)
  425. { parent := par;
  426.   winit(self);
  427.   show(self, 1);
  428.   Call SetTimer(getHWnd(self), 0x17, 1, 0);
  429. }!!
  430.  
  431. /* Routine for causing a delay. */
  432. Def delay(self, count | sT, lCount)
  433. { if alive(self)
  434.   then sT := asLong(Call GetCurrentTime());
  435.     lCount := asLong(count);
  436.     loop
  437.       alive(self) cand checkMessage();
  438.     while alive(self) cand ((Call GetCurrentTime() - sT:Long) bitAnd 0x7FFFFFFFL) < lCount:Long
  439.     endLoop;
  440.   endif;
  441. }!!
  442.