// This program records the X-Y coordinates of every mouse click while the program // is running. Loosely based on Apple's Simple Color QuickDraw Sample Application // SillyBalls. The program uses the QuickDraw and MacOS Carbon/Classic // Initialization routines from SillyBalls.c from Apple. #include #include #include #include #include #include #include /* Globals */ Rect windRect; /* Prototypes */ void InitVariables(int *x, short *s, int *p, int *c, int *xx); void Initialize(void); void BlankScreen(short t); void OutputFile(int p, int c, int dx[], int dy[]); void GetCoord(int dx[], int dy[], int *c); char * intToString(int num); //Program works best in MacOS Classic void main(void) { int x,xx; short stop; EventRecord theEvent; int theChar; int Datax[5000],Datay[5000]; int perframe, clickcounter; Initialize(); InitVariables(&x,&stop,&perframe,&clickcounter,&xx); // Event Loop do { // Key Press Section if (GetNextEvent (keyDownMask,&theEvent)) { theChar=theEvent.message & charCodeMask; if (theChar==29) //right arrow-> first frame { perframe=clickcounter; //number of clicks per frame clickcounter=0; //reset clickcounter to get data } if (theChar==28) //left arrow-> done { stop=1; //trip flag to end event loop } } // Mouse Click Section if (!Button()) { x=1; } if (Button()&x==1) { GetCoord(Datax, Datay, &clickcounter); x=0; xx=0; } // End of Frame Indicator if ((clickcounter)%(perframe)==0& xx==0) { SysBeep(50); //Beep extra time for end of frame xx=1; BlankScreen(0); } } while (!stop); // File Output OutputFile(perframe, clickcounter, Datax, Datay); } void GetCoord(int Datax[], int Datay[], int *clickcounter) { Point globalMouse; //mouse object GetGlobalMouse(&globalMouse); SysBeep(50); //Beep to acknowledge click Datax[(*clickcounter)]=globalMouse.h; //set x coord Datay[(*clickcounter)]=globalMouse.v; //set y coord //Create area to click for occluded points //Area is lower-right hand corner with dimensions: // one-tenth screen width by one-tenth screen height if((Datax[(*clickcounter)]>(windRect.right-(windRect.right*.1))) && (Datay[(*clickcounter)]>(windRect.bottom-(windRect.bottom*.1)))) { SysBeep(50); //Beep again to indicate occluded point Datax[(*clickcounter)]=0; //set occluded point to 0,0 Datay[(*clickcounter)]=0; } BlankScreen(1); (*clickcounter)++; //update number of clicks } void OutputFile(int perframe, int clickcounter, int Datax[], int Datay[]) { FILE * out = NULL; FILE * in = NULL; int fileNum = 0; char *fileNumStr=""; char *NameOfNewFile ="MyData"; int i=0; int nameLen=0; //Get unique file number in = fopen("HowManyFiles", "r"); //File that contains a number fscanf(in,"%d", &fileNum); fclose(in); fileNum++; //increment file number //Set file number for future unique filenames out = fopen("HowManyFiles", "w"); fprintf(out, "%d\n", fileNum); //Update file number fclose(out); //Make unique filename fileNumStr=intToString(fileNum); //need a string to concat to base filename strcat(NameOfNewFile, fileNumStr); //Output data to file out = fopen(NameOfNewFile, "a"); fprintf(out,"%d\n%d\n",perframe, (clickcounter)/perframe); for(i=0;i=0;j--) { ans[k]=temp[j]; //reorder string correctly k++; } ans[i]='\0'; //add null char for end of string return (char *)ans; } void InitVariables(int *x, short *s, int *p, int *c, int *xx) { *x=0; *s=0; *p=0; *c=0; *xx=0; } // type = 0, black, type = 1, blank void BlankScreen(short type) { RGBColor winColor; Rect winRect; int newLeft, newTop; if(type==1) //blank screen (white) { winColor.red = 65535; winColor.green = 65535; winColor.blue = 65535; } else //blank screen (black) { winColor.red = 0; winColor.green = 0; winColor.blue = 0; } RGBForeColor(&winColor); newTop = 0; newLeft = 0; SetRect(&winRect, newLeft, newTop, newLeft+windRect.right, newTop+windRect.bottom); MoveTo(newLeft, newTop); PaintRect (&winRect); } // // Initialize everything for the program, make sure we can run // //MW specified argument and return type. void Initialize(void) { //MW added to support new Carbon routines #if TARGET_API_MAC_CARBON BitMap theScreenBits; #endif WindowPtr mainPtr; unsigned long theDateTime; OSErr error; SysEnvRec theWorld; InitCursor(); // // Make a new window for drawing in, and it must be a color window. // The window is full screen size, made smaller to make it more visible. // //MW added !TARGET_API_MAC_CARBON for Carbon version #if TARGET_API_MAC_CARBON GetQDGlobalsScreenBits( &theScreenBits ); /* carbon accessor */ windRect = theScreenBits.bounds; #else windRect = qd.screenBits.bounds; #endif InsetRect(&windRect, 50, 50); mainPtr = NewCWindow(nil, &windRect, "\pDotter - Carbon!", true, documentProc, (WindowPtr) -1, false, 0); //MW added for Carbon version #if TARGET_API_MAC_CARBON SetPortWindowPort( mainPtr ); /* carbon accessor */ #else SetPort( mainPtr ); /* set window to current graf port */ #endif }