home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / luschsrc.sit / test.c < prev    next >
Text File  |  1990-05-23  |  6KB  |  342 lines

  1. /********************************************************************************
  2.  *    test.c
  3.  *
  4.  *    Color Test Management Package
  5.  *
  6.  *    Written by Paco Xander Nathan
  7.  *    ⌐1990, Motorola Inc.  Public domain source code.
  8.  ********************************************************************************/
  9.  
  10. #include "applic.h"
  11. #include "window.h"
  12. #include "dialog.h"
  13. #include "string.h"
  14.  
  15. #include "test.h"
  16. #include "gnosis.h"
  17. #include "analysis.h"
  18.  
  19.  
  20. #define MAXBANG        40
  21.  
  22.  
  23. /* External Data Structures
  24.  */
  25. Boolean
  26.     testUser = TRUE,
  27.     testBCraig = FALSE,
  28.     testJDavis = FALSE;
  29.     
  30. PaletteHandle
  31.     testPal = NULL;
  32.  
  33. TestPhases
  34.     testPhase = tstPhase1;
  35.  
  36. TestPadType
  37.     testPad[MAXPAD];
  38.  
  39.  
  40. /* Local Data Structures
  41.  */
  42. static short
  43.     testOrder = 0;
  44.  
  45.  
  46. /* Local Function Prototypes
  47.  */
  48. #ifdef PROTOTYPES
  49. #endif
  50.  
  51.  
  52. /* Setup the color test window
  53.  */
  54. void
  55. TestSetup ()
  56. {
  57.     GrafPtr savePort;
  58.  
  59.     GetPort(&savePort);
  60.     SetPort(wPtrTest);
  61.  
  62.     /* Setup for color drawing using a palette
  63.      */
  64.     if (laMachine.hasColor && (testPal = GetNewPalette(RSRCBASE)) && wPtrTest)
  65.         SetPalette(wPtrTest, testPal, TRUE);
  66.     
  67.     TextFont(systemFont);
  68.     testJDavis = !laMachine.hasColor;
  69.     TestReset();
  70.  
  71.     TestTitleInfo();
  72.  
  73.     /* Prepare to draw, pardner!
  74.      */
  75.     InvalRect(&wPtrTest->portRect);
  76.     WindSwitch(wPtrTest, TRUE);
  77.  
  78.     SetPort(savePort);
  79. }
  80.  
  81.  
  82. /* Reset the color test window for another test
  83.  */
  84. void
  85. TestReset ()
  86. {
  87.     register short i, width, height, tempColor, tempIndex;
  88.     GrafPtr savePort;
  89.  
  90.     GetPort(&savePort);
  91.     SetPort(wPtrTest);
  92.  
  93.     /* Setup the color pads
  94.      */
  95.     width = (wPtrTest->portRect.right - wPtrTest->portRect.left) / (MAXPAD / 2);
  96.     height = (wPtrTest->portRect.bottom - wPtrTest->portRect.top) / 2;
  97.     
  98.     for (i = 0; i < MAXPAD; i++) {
  99.         if (i < (MAXPAD / 2)) {
  100.             testPad[i].bounds.left = i * width;
  101.             testPad[i].bounds.top = 0;
  102.         }
  103.         else {
  104.             testPad[i].bounds.left = (i - (MAXPAD / 2)) * width;
  105.             testPad[i].bounds.top = height;
  106.         }
  107.  
  108.         testPad[i].bounds.right = testPad[i].bounds.left + width;
  109.         testPad[i].bounds.bottom = testPad[i].bounds.top + height;
  110.  
  111.         /* Since it's not the default
  112.          */
  113.         if (testBCraig)
  114.             InsetRect(&testPad[i].bounds, 5, 5);
  115.  
  116.         testPad[i].color = i + 2;
  117.         testPad[i].order = i;
  118.         testPad[i].selected = FALSE;
  119.     }
  120.  
  121.     /* Randomize the order of the color pads
  122.      */
  123.     for (i = 0; i < MAXPAD; i++) {
  124.         tempIndex = DlogRandom(MAXPAD);
  125.         tempColor = testPad[i].color;
  126.         testPad[i].color = testPad[tempIndex].color;
  127.         testPad[tempIndex].color = tempColor;
  128.     }
  129.  
  130.     /* Reset the test info and the analysis buffer
  131.      */
  132.     testOrder = 0;
  133.     
  134.     if (testUser) {
  135.         AnalStub();
  136.         AnalWriteWind();
  137.     }
  138.  
  139.     SetPort(savePort);
  140. }
  141.  
  142.  
  143. /* Update the info string
  144.  */
  145. void
  146. TestTitleInfo ()
  147. {
  148.     Str255 blabText;
  149.     GrafPtr savePort;
  150.     
  151.     GetPort(&savePort);
  152.  
  153.     /* Update the info prompt string
  154.      */
  155.     GetIndString(blabText, strsInfo, testPhase);
  156.     SetWTitle(wPtrTest, blabText);    
  157.     
  158.     SetPort(savePort);
  159. }
  160.  
  161.  
  162. /* Redraw the color test window.  Note: modified to show color and values, 
  163.  * not order - Jim
  164.  */
  165. void
  166. TestDraw ()
  167. {
  168.     register short i, j, dh, dv;
  169.     Rect bounds;
  170.     Str255 nameText, ordText;
  171.     GrafPtr savePort;
  172.     
  173.     /* Save the current state
  174.      */
  175.     GetPort(&savePort);
  176.     SetPort(wPtrTest);
  177.  
  178.     /* Draw the pads in color
  179.      */
  180.     dh = testPad[0].bounds.right / MAXBANG;
  181.     dv = testPad[0].bounds.bottom / MAXBANG;
  182.  
  183.     for (i = 0; i < MAXPAD; i++) {
  184.         /* Draw the pad color
  185.          */
  186.         if (!testPad[i].selected && !testJDavis) {
  187.             PenMode(patOr);
  188.             PmForeColor(testPad[i].color);
  189.             PaintRect(&testPad[i].bounds);
  190.         }
  191.         else if (testPad[i].selected && !testJDavis) {
  192.             PenMode(patOr);
  193.             PmForeColor(testPad[i].color);
  194.             bounds = testPad[i].bounds;
  195.         
  196.             for (j = 0; j < MAXBANG; j++) {
  197.                 InsetRect(&bounds, dh, dv);
  198.                 FrameRect(&bounds);
  199.             }
  200.  
  201.             PenMode(patCopy);
  202.             PmForeColor(1);
  203.  
  204.             GetIndString(nameText, strsColors , testPad[i].color - 1);
  205.             sprintf((char *) ordText, "%s: %d", PtoCstr((char *) nameText), testPad[i].color - 2);
  206.  
  207.             MoveTo(testPad[i].bounds.left + 10, testPad[i].bounds.bottom - 16);
  208.             DrawString(CtoPstr((char *) ordText));
  209.         }
  210.         else {
  211.             EraseRect(&testPad[i].bounds);
  212.  
  213.             GetIndString(nameText, strsColors , testPad[i].color - 1);
  214.             sprintf((char *) ordText, "%s: %d", PtoCstr((char *) nameText), testPad[i].color - 2);
  215.  
  216.             MoveTo(testPad[i].bounds.left + 10, testPad[i].bounds.bottom - 16);
  217.             DrawString(CtoPstr((char *) ordText));
  218.  
  219.             if (testPad[i].selected) {
  220.                 bounds = testPad[i].bounds;
  221.             
  222.                 for (j = 0; j < MAXBANG; j++) {
  223.                     InsetRect(&bounds, dh, dv);
  224.                     FrameRect(&bounds);
  225.                 }
  226.             }
  227.         }
  228.     }
  229.  
  230.     SetPort(savePort);
  231. }
  232.  
  233.  
  234. /* Handle a color selection
  235.  */
  236. void
  237. TestClick (thePoint)
  238.     register Point thePoint;
  239. {
  240.     register short i;
  241.     GrafPtr savePort;
  242.  
  243.     GetPort(&savePort);
  244.     SetPort(wPtrTest);
  245.  
  246.     /* Check the non-pad states
  247.      */
  248.     for (i = 0; i < MAXPAD; i++) {
  249.         if ((!testPad[i].selected) && PtInRect(thePoint, &testPad[i].bounds)) {
  250.             testPad[i].order = testOrder++;
  251.             testPad[i].selected = TRUE;
  252.             InvalRect(&testPad[i].bounds);
  253.             
  254.             if (testOrder == MAXPAD) {
  255.                 if (testPhase == tstPhase1) {
  256.                     testPhase++;
  257.                     AnalPass(testPass0);
  258.  
  259.                     TestReset();
  260.                     InvalRect(&(wPtrTest->portRect));
  261.                 }
  262.                 else if (testPhase == tstPhase2) {
  263.                     testPhase++;
  264.                     AnalPass(testPass1);
  265.                     AnalReport();
  266.  
  267.                     if (testUser)
  268.                         GnosRecall();
  269.                 }
  270.             }
  271.         }
  272.     }
  273.  
  274.     TestTitleInfo();
  275.     SetPort(savePort);
  276. }
  277.  
  278.  
  279. /* Execute test menu selections
  280.  */
  281. void
  282. TestMenu (theItem)
  283.     register short theItem;
  284. {
  285.     GrafPtr savePort;
  286.     register long waitTime;
  287.     register short i;
  288.  
  289.     GetPort(&savePort);
  290.     SetPort(wPtrTest);
  291.  
  292.     switch (theItem) {
  293.     case testReset:
  294.         for (i = 0; i < MAXPAD; i++) {
  295.             TestReset();
  296.             TestDraw();
  297.         
  298.             for (waitTime = TickCount() + 2L; TickCount() < waitTime; ) ;
  299.         }
  300.  
  301.         testPhase = tstPhase1;
  302.         TestTitleInfo();
  303.         WindSwitch(wPtrTest, TRUE);
  304.         break;
  305.  
  306.     case testUserMode:
  307.         testUser = !testUser;
  308.         break;
  309.  
  310.     case testBorderless:
  311.         testBCraig = !testBCraig;
  312.  
  313.         for (i = 0; i < MAXPAD; i++)
  314.             if (testBCraig)
  315.                 InsetRect(&testPad[i].bounds, 5, 5);
  316.             else
  317.                 InsetRect(&testPad[i].bounds, -5, -5);
  318.  
  319.         InvalRect(&wPtrTest->portRect);
  320.         break;
  321.  
  322.     case testInColor:
  323.         if (!testJDavis) {
  324.             PenMode(patCopy);
  325.             PmForeColor(1);
  326.         }
  327.     
  328.         testJDavis = !testJDavis;
  329.         InvalRect(&wPtrTest->portRect);
  330.         break;
  331.  
  332.     case testCleanUp:
  333.         WindTileStack();
  334.         break;
  335.  
  336.     default:
  337.         break;
  338.     }
  339.  
  340.     SetPort(savePort);
  341. }
  342.