#include #include #include "lib\gsx.h" static struct ws_attr *ws; /* Work Station Attributes */ /* Function that creates a random box on the screen. Returns null if no * valid box was created */ int *box_points() { int *return_val; int i; long temp; /* Allocate the 4-point array */ return_val = (int *)malloc(4*sizeof(int)); /* Randomly assign the begin points */ for(i=0;i<2;i++) { return_val[i] = rand(); } /* Leave room for text on the bottom */ if(return_val[1] < 2500) return_val[1] = 2500; /* Assign the two end points */ for(i=2;i<4;i++) { /* Make 1000 by 1000 boxes */ return_val[i] = return_val[i-2]+1000; /* Check for any strange overruns */ if(return_val[i] > 32767 || return_val[i] < 0) { /* A problem - return NULL */ free(return_val); return_val = NULL; break; } } /* Return the array of points */ return return_val; } int main(int argc, char *argv[]) { int i; /* Workstation number to use */ int *boxes; /* Array of box points */ char *s; /* String used for key trapping */ /* Initialize the random number generator */ srand(1097); /* The only command line argument is a workstation number to use. * This program defaults to 3. Check your ASSIGN.SYS file to make * sure this is a valid WS to use. */ if (argc == 2) i = atoi(argv[1]); else i = 3; printf("initializing..\n"); /* Open the graphics WS */ ws = openws(i); printf("opened ws %d...\n",i); /* Assign some colors */ color(0,250,450,380); /* Dark Green - Background */ color(1,1000,1000,1000); /* White - Text */ color(2,1000,200,200); /* Red - Rectangles */ printf("filling...\n"); /* Fill the screen with the background color */ fillcolor(0); /*draw background*/ boxes = (int *)malloc(4*sizeof(int)); boxes[0] = 0; boxes[1] = 0; boxes[2] = 32767; boxes[3] = 32767; bar(boxes); free(boxes); /* Set the input mode for Strings (device=2) to sampling (mode=4) */ setinmode(2,4); /* Set the text on screen */ charht(1000); textcolor(1); text(1,1000,"GSX-86 Test Program - Rectangles!"); /* Reset the fill color for rectangles */ fillcolor(2); /* Loop, drawing random rectangles */ for(;;) { /* Get a random box point array */ boxes = box_points(); /* Error checking */ if(boxes!=NULL) { /* Call the boxes GDP primitive */ bar(boxes); /* Print coordinates if you want */ /* printf("%d %d %d %d\n",boxes[0],boxes[1],boxes[2],boxes[3]);*/ /* Free the boxes until next time */ free(boxes); } /* Get a sample string from the keyboard. This function does * not block because earlier we set the input mode to sample. */ s = sm_string(4,1,0); /* Check if anything has been received from the keyboard */ if(s[0] != NULL) { printf("String -> %s\n",s); break; } /* Free the string for next time throught the loop */ free(s); } /* We're outside the loop, so shut down the workstation */ printf("closing...\n"); closews(); printf("done.\n"); return 1; }