home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
- * test.c
- *
- * Color Test Management Package
- *
- * Written by Paco Xander Nathan
- * ⌐1990, Motorola Inc. Public domain source code.
- ********************************************************************************/
-
- #include "applic.h"
- #include "window.h"
- #include "dialog.h"
- #include "string.h"
-
- #include "test.h"
- #include "gnosis.h"
- #include "analysis.h"
-
-
- #define MAXBANG 40
-
-
- /* External Data Structures
- */
- Boolean
- testUser = TRUE,
- testBCraig = FALSE,
- testJDavis = FALSE;
-
- PaletteHandle
- testPal = NULL;
-
- TestPhases
- testPhase = tstPhase1;
-
- TestPadType
- testPad[MAXPAD];
-
-
- /* Local Data Structures
- */
- static short
- testOrder = 0;
-
-
- /* Local Function Prototypes
- */
- #ifdef PROTOTYPES
- #endif
-
-
- /* Setup the color test window
- */
- void
- TestSetup ()
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(wPtrTest);
-
- /* Setup for color drawing using a palette
- */
- if (laMachine.hasColor && (testPal = GetNewPalette(RSRCBASE)) && wPtrTest)
- SetPalette(wPtrTest, testPal, TRUE);
-
- TextFont(systemFont);
- testJDavis = !laMachine.hasColor;
- TestReset();
-
- TestTitleInfo();
-
- /* Prepare to draw, pardner!
- */
- InvalRect(&wPtrTest->portRect);
- WindSwitch(wPtrTest, TRUE);
-
- SetPort(savePort);
- }
-
-
- /* Reset the color test window for another test
- */
- void
- TestReset ()
- {
- register short i, width, height, tempColor, tempIndex;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(wPtrTest);
-
- /* Setup the color pads
- */
- width = (wPtrTest->portRect.right - wPtrTest->portRect.left) / (MAXPAD / 2);
- height = (wPtrTest->portRect.bottom - wPtrTest->portRect.top) / 2;
-
- for (i = 0; i < MAXPAD; i++) {
- if (i < (MAXPAD / 2)) {
- testPad[i].bounds.left = i * width;
- testPad[i].bounds.top = 0;
- }
- else {
- testPad[i].bounds.left = (i - (MAXPAD / 2)) * width;
- testPad[i].bounds.top = height;
- }
-
- testPad[i].bounds.right = testPad[i].bounds.left + width;
- testPad[i].bounds.bottom = testPad[i].bounds.top + height;
-
- /* Since it's not the default
- */
- if (testBCraig)
- InsetRect(&testPad[i].bounds, 5, 5);
-
- testPad[i].color = i + 2;
- testPad[i].order = i;
- testPad[i].selected = FALSE;
- }
-
- /* Randomize the order of the color pads
- */
- for (i = 0; i < MAXPAD; i++) {
- tempIndex = DlogRandom(MAXPAD);
- tempColor = testPad[i].color;
- testPad[i].color = testPad[tempIndex].color;
- testPad[tempIndex].color = tempColor;
- }
-
- /* Reset the test info and the analysis buffer
- */
- testOrder = 0;
-
- if (testUser) {
- AnalStub();
- AnalWriteWind();
- }
-
- SetPort(savePort);
- }
-
-
- /* Update the info string
- */
- void
- TestTitleInfo ()
- {
- Str255 blabText;
- GrafPtr savePort;
-
- GetPort(&savePort);
-
- /* Update the info prompt string
- */
- GetIndString(blabText, strsInfo, testPhase);
- SetWTitle(wPtrTest, blabText);
-
- SetPort(savePort);
- }
-
-
- /* Redraw the color test window. Note: modified to show color and values,
- * not order - Jim
- */
- void
- TestDraw ()
- {
- register short i, j, dh, dv;
- Rect bounds;
- Str255 nameText, ordText;
- GrafPtr savePort;
-
- /* Save the current state
- */
- GetPort(&savePort);
- SetPort(wPtrTest);
-
- /* Draw the pads in color
- */
- dh = testPad[0].bounds.right / MAXBANG;
- dv = testPad[0].bounds.bottom / MAXBANG;
-
- for (i = 0; i < MAXPAD; i++) {
- /* Draw the pad color
- */
- if (!testPad[i].selected && !testJDavis) {
- PenMode(patOr);
- PmForeColor(testPad[i].color);
- PaintRect(&testPad[i].bounds);
- }
- else if (testPad[i].selected && !testJDavis) {
- PenMode(patOr);
- PmForeColor(testPad[i].color);
- bounds = testPad[i].bounds;
-
- for (j = 0; j < MAXBANG; j++) {
- InsetRect(&bounds, dh, dv);
- FrameRect(&bounds);
- }
-
- PenMode(patCopy);
- PmForeColor(1);
-
- GetIndString(nameText, strsColors , testPad[i].color - 1);
- sprintf((char *) ordText, "%s: %d", PtoCstr((char *) nameText), testPad[i].color - 2);
-
- MoveTo(testPad[i].bounds.left + 10, testPad[i].bounds.bottom - 16);
- DrawString(CtoPstr((char *) ordText));
- }
- else {
- EraseRect(&testPad[i].bounds);
-
- GetIndString(nameText, strsColors , testPad[i].color - 1);
- sprintf((char *) ordText, "%s: %d", PtoCstr((char *) nameText), testPad[i].color - 2);
-
- MoveTo(testPad[i].bounds.left + 10, testPad[i].bounds.bottom - 16);
- DrawString(CtoPstr((char *) ordText));
-
- if (testPad[i].selected) {
- bounds = testPad[i].bounds;
-
- for (j = 0; j < MAXBANG; j++) {
- InsetRect(&bounds, dh, dv);
- FrameRect(&bounds);
- }
- }
- }
- }
-
- SetPort(savePort);
- }
-
-
- /* Handle a color selection
- */
- void
- TestClick (thePoint)
- register Point thePoint;
- {
- register short i;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(wPtrTest);
-
- /* Check the non-pad states
- */
- for (i = 0; i < MAXPAD; i++) {
- if ((!testPad[i].selected) && PtInRect(thePoint, &testPad[i].bounds)) {
- testPad[i].order = testOrder++;
- testPad[i].selected = TRUE;
- InvalRect(&testPad[i].bounds);
-
- if (testOrder == MAXPAD) {
- if (testPhase == tstPhase1) {
- testPhase++;
- AnalPass(testPass0);
-
- TestReset();
- InvalRect(&(wPtrTest->portRect));
- }
- else if (testPhase == tstPhase2) {
- testPhase++;
- AnalPass(testPass1);
- AnalReport();
-
- if (testUser)
- GnosRecall();
- }
- }
- }
- }
-
- TestTitleInfo();
- SetPort(savePort);
- }
-
-
- /* Execute test menu selections
- */
- void
- TestMenu (theItem)
- register short theItem;
- {
- GrafPtr savePort;
- register long waitTime;
- register short i;
-
- GetPort(&savePort);
- SetPort(wPtrTest);
-
- switch (theItem) {
- case testReset:
- for (i = 0; i < MAXPAD; i++) {
- TestReset();
- TestDraw();
-
- for (waitTime = TickCount() + 2L; TickCount() < waitTime; ) ;
- }
-
- testPhase = tstPhase1;
- TestTitleInfo();
- WindSwitch(wPtrTest, TRUE);
- break;
-
- case testUserMode:
- testUser = !testUser;
- break;
-
- case testBorderless:
- testBCraig = !testBCraig;
-
- for (i = 0; i < MAXPAD; i++)
- if (testBCraig)
- InsetRect(&testPad[i].bounds, 5, 5);
- else
- InsetRect(&testPad[i].bounds, -5, -5);
-
- InvalRect(&wPtrTest->portRect);
- break;
-
- case testInColor:
- if (!testJDavis) {
- PenMode(patCopy);
- PmForeColor(1);
- }
-
- testJDavis = !testJDavis;
- InvalRect(&wPtrTest->portRect);
- break;
-
- case testCleanUp:
- WindTileStack();
- break;
-
- default:
- break;
- }
-
- SetPort(savePort);
- }
-