fdfishman@watcgl.UUCP (Flynn D. Fishman) (01/21/87)
FDFISHMAN (Flynn D. Fishman) @ WATCGL UUCP : ...!{decvax|ihnp4|clyde|allegra|utzoo}!watmath!watcgl!fdfishman ARPA : fdfishman%watcgl%waterloo.csnet@csnet-relay.arpa CSNET : fdfishman%watcgl@waterloo.csnet #------------------------------------------------------------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by watcgl!fdfishman on Tue Jan 20 23:24:11 EST 1987 # Contents: main.c func.c three-d.c window.c echo x - main.c sed 's/^@//' > "main.c" <<'@//E*O*F main.c//' /****************************************************************************/ /* Program: Graph It II (The C Program) */ /* SubModule: main.c 1-7-87 */ /* CopyRight By Flynn D. Fishman January 1987 */ /* Feel Free to copy and alter this source */ /****************************************************************************/ /* This module includes most of the major routines and the main loop */ #include "graph.h" /******************************************************/ /* Main Program */ /* This is the main body of the program. */ /******************************************************/ main() { struct Window *Window; struct IntuiMessage *NewMessage; ULONG class; USHORT code, icon_code; SHORT x, y, x1, y1, x2, y2; SHORT minx, miny, maxx, maxy; USHORT MenuNum, ItemNum; SHORT KeepGoing, mode; long int lastx, lasty, startx, starty; struct Graph_Parameters parameters; Window = openstuff(); minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; SetDrMd( Window->RPort, JAM2 ); KeepGoing = TRUE; lastx = 0; lasty = 0; mode = ZOOM; SetDefaults(¶meters); parameters.xon = FALSE; parameters.yon = FALSE; parameters.zon = FALSE; parameters.hidden = FALSE; DrawWindow(Window, ¶meters); PrintPage(Window, 0l); InvertIcon(Window, 1l); while( KeepGoing ) { Wait( 1 << Window->UserPort->mp_SigBit); while( NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort) ) { class = NewMessage->Class; code = NewMessage->Code; x = Window->MouseX; y = Window->MouseY; if( class == SIZEVERIFY ) { Window->Flags &= ( 0xFFFFFFFF ^ RMBTRAP ); } ReplyMsg( NewMessage ); switch( class ) { case MENUPICK: if( code != MENUNULL ) { /* get menu and item numbers from code */ MenuNum = MENUNUM( code ); ItemNum = ITEMNUM( code ); /* determine appropriate action by menu number */ switch ( MenuNum ) { case 0: switch ( ItemNum ) { case 0: /* Load file */ LoadFile(Window, ¶meters); DrawWindow(Window, ¶meters); PlotGraph(Window, ¶meters); DrawVariables(Window, ¶meters, mode); break; case 1: /* save file */ SaveFile(Window, ¶meters); break; case 2: /* About */ PrintPage(Window,0l); break; case 3: /* Quit */ KeepGoing = FALSE; break; default: break; } /* end of menu 0 switch */ break; case 1: icon_code = ItemNum+1; goto do_icon; break; default: /* Menu number unrecognized, do nothing */ break; } /* end of menu switch */ } /* if code not menunull */ case MOUSEMOVE: if (lastx !=0) { if (mode == ZOOM) CrossHair(Window, lastx, lasty); } if (x < maxx && x > miny + 2 && y < maxy && y > miny + 2) { lastx = x; lasty = y; if (mode == ZOOM) CrossHair(Window, lastx, lasty); } else lastx = 0; break; case NEWSIZE: minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; DrawWindow(Window, ¶meters); PlotGraph(Window, ¶meters); break; case CLOSEWINDOW: KeepGoing = FALSE; break; case MOUSEBUTTONS: switch ( code ) { case SELECTUP: break; case SELECTDOWN: if (x > maxx + YEXPANDX + 2) /* it is an icon */ { icon_code = (y - miny) / (ICONY + 2); do_icon: InvertIcon(Window, icon_code); switch ( icon_code ) { case 1: /* Zoom Icon */ if (mode == MOVE) DrawGrid(Window); mode = ZOOM; InvertIcon(Window, icon_code); InvertIcon(Window, 2l); break; case 2: /* Move Icon */ if (mode != MOVE) DrawGrid(Window); mode = MOVE; InvertIcon(Window, icon_code); InvertIcon(Window, 1l); break; case 3: /* command line */ if(GetCommand(Window, ¶meters) != NULL) { Print(Window,"Error Opening Window",0); } DrawWindow(Window, ¶meters); PlotGraph(Window, ¶meters); DrawVariables(Window, ¶meters, mode); break; case 4: /* Hidden lines */ parameters.hidden = (parameters.hidden) ? FALSE : TRUE; InvertIcon(Window, icon_code); if (parameters.zon) { DrawWindow(Window, ¶meters); PlotGraph(Window, ¶meters); DrawVariables(Window, ¶meters, mode); } break; case 5: /* home */ SetDefaults(¶meters); DrawWindow(Window, ¶meters); PlotGraph(Window, ¶meters); DrawVariables(Window, ¶meters, mode); break; case 6: /* quit */ KeepGoing = FALSE; break; case 7: /* help window */ Help(Window, ¶meters); if (mode == MOVE) DrawGrid(Window); InvertIcon(Window, icon_code); break; default: break; } /* end of icon switch */ } /* end of icon if */ else if (x > maxx) /* It is the y-expand */ { yexpand(Window, ¶meters); if (mode == MOVE) DrawGrid(Window); } else if (y > maxy) /* It is the x-expand */ { xexpand(Window, ¶meters); if (mode == MOVE) DrawGrid(Window); } else if (mode == ZOOM) { Zoom(Window, ¶meters, lastx, lasty); lastx = 0; } else if (mode == MOVE) { MoveGraph(Window, ¶meters, lastx, lasty); DrawGrid(Window); lastx = 0; } break; case MENUDOWN: break; default: continue; } break; case INACTIVEWINDOW: /* User has de-selected our window, so a * little bit of cleaning up may be needed * to prevent untoward events when he comes * back to it. */ break; default: /* message class was unrecognized, so do nothing */ break; } } /* this brace ends the while(NewMessage) loop way back when */ } /* It must be time to quit, so we have to clean * up and exit. */ if (parameters.xon) FreeFunction(parameters.x1); if (parameters.yon) FreeFunction(parameters.y1); if (parameters.zon) FreeFunction(parameters.z1); closestuff(Window); exit(TRUE); } PlotGraph(Window, parameters) struct Graph_Parameters *parameters; struct Window *Window; { extern double x,y,z,t; long int x1, x2, y1, y2, xcenter, ycenter; double xconversion, yconversion, steps, tsteps, loop; long int minx, miny, maxx, maxy; double lastx, lasty; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; /* Draw the Graph rectangle area */ DrawRectangle(Window, 1, minx, miny, maxx, maxy); SetDrMd(Window->RPort, JAM2); if (parameters->zon) Plot3dGraph(Window, parameters); xconversion = (maxx - minx) / (parameters->xend - parameters->xstart); yconversion = (maxy - miny) / (parameters->yend - parameters->ystart); xcenter = -parameters->xstart * xconversion + minx + 2; ycenter = -parameters->ystart * yconversion + miny + 2; if (parameters->yon) { z = 0.0; if (!parameters->zon) { /* draw the y axis if needed */ if (parameters->xstart * parameters->xend < 0) Line(Window, 2l, xcenter, miny, xcenter, maxy); /* draw the x axis if needed */ if (parameters->ystart * parameters->yend < 0) Line(Window, 2l, minx, ycenter, maxx, ycenter); } if (parameters->xon) { tsteps= parameters->detail/(parameters->tend -parameters->tstart); t= parameters->tstart; parameters->x1->position = 0; parameters->y1->position = 0; x = Solve(parameters->x1); y = Solve(parameters->y1); x1 = x * xconversion + xcenter + 2; y1 = ycenter - y * yconversion; lastx = x; lasty = y; while ( t < parameters->tend ) { t += tsteps; parameters->x1->position = 0; parameters->y1->position = 0; x = Solve(parameters->x1); y = Solve(parameters->y1); x2 = x * xconversion + xcenter; y2 = ycenter - y * yconversion; if (parameters->zon) Line3d(Window, 3l, lastx, lasty, z, x, y, z); else Line(Window, 1l, x1, y1, x2, y2); x1 = x2; y1 = y2; lastx = x; lasty = y; } /* end of while */ } /* end of xon (parametric) section */ else { parameters->y1->position = 0; x = parameters->xstart; y = Solve(parameters->y1); x1 = x * xconversion + xcenter + 2; y1 = ycenter - y * yconversion; lastx = x; lasty = y; while ( x < parameters->xend ) { parameters->y1->position = 0; x += ( (double) (parameters->detail) ) /xconversion; y = Solve(parameters->y1); x2 = x * xconversion + xcenter; y2 = ycenter - y * yconversion; if (parameters->zon) Line3d(Window, 3l, lastx, lasty, z, x, y, z); else Line(Window, 1l, x1, y1, x2, y2); x1 = x2; y1 = y2; lastx = x; lasty = y; } /* end of while */ } /* of xon else */ } /* end of if */ return(); } Zoom(Window, parameters, firstx, firsty) struct Window *Window; struct Graph_Parameters *parameters; long int firstx, firsty; { long int minx, miny, maxx, maxy, lastx, lasty, x, y; struct IntuiMessage *NewMessage; /* msg structure for GetMsg() */ ULONG class; /* used in message monitor loop */ USHORT code; /* used in message monitor loop */ minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; lastx = 0; for ever { Wait( 1 << Window->UserPort->mp_SigBit); while( NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort) ) { class = NewMessage->Class; code = NewMessage->Code; x = Window->MouseX; y = Window->MouseY; ReplyMsg( NewMessage ); switch( class ) { case MOUSEMOVE: if (lastx !=0) { CrossHair(Window, lastx, lasty); } if (x < maxx && x > miny + 2 && y < maxy && y > miny + 2) { lastx = x; lasty = y; CrossHair(Window, lastx, lasty); } else lastx = 0; break; break; case MOUSEBUTTONS: switch ( code ) { case SELECTUP: if (lastx == 0) return(); Real(Window, parameters, firstx, firsty, lastx, lasty); PlotGraph(Window, parameters); return(); break; default: break; } /* end of mousebutton switch */ default: break; } /* end of the case switch */ } } /* end of forever */ } MoveGraph(Window, parameters, firstx, firsty) struct Window *Window; struct Graph_Parameters *parameters; long int firstx, firsty; { long int minx, miny, maxx, maxy, deltax, deltay, x, y; long int changex, changey; struct IntuiMessage *NewMessage; /* msg structure for GetMsg() */ ULONG class; /* used in message monitor loop */ USHORT code; /* used in message monitor loop */ minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; changex = 0; changey = 0; deltax = 1; deltay = 1; if (firstx > maxx / 3 && firstx < maxx * 2 / 3) deltax = 0; if (firsty > maxy / 3 && firsty < maxy * 2 / 3) deltay = 0; DrawGrid(Window); for ever { Wait( 1 << Window->UserPort->mp_SigBit); while( NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort) ) { class = NewMessage->Class; code = NewMessage->Code; x = Window->MouseX; y = Window->MouseY; ReplyMsg( NewMessage ); switch( class ) { case MOUSEMOVE: if (changex !=0 || changey != 0) { Box(Window, changex, changey); } if (x < maxx && x > miny + 2 && y < maxy && y > miny + 2) { changex = (x - firstx) * deltax; changey = (y - firsty) * deltay; Box(Window, changex, changey); } else changex = 0; break; break; case MOUSEBUTTONS: switch ( code ) { case SELECTUP: if (changex == 0 && changey == 0) return(); Shift(Window, parameters, changex, changey); DrawWindow(Window, parameters); PlotGraph(Window, parameters); return(); break; default: break; } default: break; } } } } xexpand(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { struct IntuiMessage *NewMessage; /* msg structure for GetMsg() */ ULONG class; /* used in message monitor loop */ USHORT code; /* used in message monitor loop */ long int minx, miny, maxx, maxy, x, y, xlast; double xfactor, xfloat, maxfloat; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; xlast = minx + XEXPANDX + 1; for ever { Wait( 1 << Window->UserPort->mp_SigBit); while( NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort) ) { class = NewMessage->Class; code = NewMessage->Code; x = Window->MouseX; y = Window->MouseY; ReplyMsg( NewMessage ); switch( class ) { case MOUSEMOVE: EraseButton(Window, xlast, maxy + 3); if ( x < minx + XEXPANDX + 1) x = minx + XEXPANDX + 1; if ( x > maxx - XEXPANDX - BALLWIDTH - 1) x = maxx - XEXPANDX - BALLWIDTH - 1; xlast = x; DrawButton(Window, xlast, maxy + 3); break; case MOUSEBUTTONS: switch ( code ) { case SELECTUP: xfloat = xlast; maxfloat = maxx; xfactor = xfloat/ maxfloat * (parameters->xend - parameters->xstart); parameters->xstart = parameters->xstart - xfactor; parameters->xend = parameters->xend + xfactor; DrawWindow(Window, parameters); PlotGraph(Window, parameters); return(); break; default: break; } default: break; } } } } yexpand(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { struct IntuiMessage *NewMessage; /* msg structure for GetMsg() */ ULONG class; /* used in message monitor loop */ USHORT code; /* used in message monitor loop */ long int minx, miny, maxx, maxy, x, y, ylast; double yfactor, yfloat, maxfloat; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; ylast = maxy - YEXPANDY - BALLHEIGHT - 1; for ever { Wait( 1 << Window->UserPort->mp_SigBit); while( NewMessage=(struct IntuiMessage *)GetMsg(Window->UserPort) ) { class = NewMessage->Class; code = NewMessage->Code; x = Window->MouseX; y = Window->MouseY; ReplyMsg( NewMessage ); switch( class ) { case MOUSEMOVE: EraseButton(Window, maxx + 3, ylast); if ( y < miny + YEXPANDY + 1) y = miny + YEXPANDY + 1; if ( y > maxy - YEXPANDY - BALLHEIGHT -1 ) y = maxy - YEXPANDY - BALLHEIGHT - 1; ylast = y; DrawButton(Window, maxx + 3 , ylast); break; case MOUSEBUTTONS: switch ( code ) { case SELECTUP: yfloat = maxy - ylast; maxfloat = maxy; yfactor = yfloat/ maxfloat * (parameters->yend - parameters->ystart); parameters->ystart = parameters->ystart - yfactor; parameters->yend = parameters->yend + yfactor; DrawWindow(Window, parameters); PlotGraph(Window, parameters); return(); break; default: break; } default: break; } } } } DrawVariables(Window, parameters, mode) struct Window *Window; struct Graph_Parameters *parameters; int mode; { if (mode == MOVE) { DrawGrid(Window); InvertIcon(Window, 2l); } else InvertIcon(Window, 1l); if (parameters->hidden) InvertIcon(Window, 4l); } @//E*O*F main.c// chmod u=rw,g=rw,o=r main.c echo x - func.c sed 's/^@//' > "func.c" <<'@//E*O*F func.c//' /****************************************************************************/ /* Program: Graph It II (The C Program) */ /* SubModule: func.c 1-7-87 */ /* CopyRight By Flynn D. Fishman January 1987 */ /* Feel Free to copy and alter this source */ /****************************************************************************/ /* This function includes all of the math related subroutines to solve all the graph related problems */ #include "graph.h" static char *(functions[]) = {"xx", "tt", "yy", "zz", "((", "))", "++", "--", "//", "^^", "==", "**", "ccos", "ssin", "Ttan", "eexp", "PPI", "EE", "aatan", "Sasin", "Cacos", "lln", "Aabs", "Ll", "end"}; double Solve(formula) struct Formula_Master *formula; { extern double x, y, z, t; double lop, a, b, total; char func; a = 0; b = 0; total = Value(formula); while (formula->equation[formula->position] != '0' ) { func = formula->equation[formula->position++]; if (func == 0) break; switch (func) { case '+': total = total + Value(formula); break; case '-': total = total - Value(formula); break; case '*': total = total * Value(formula); break; case '/': a = Value(formula); if (a != 0) total = total / a; else total = INFINITY; break; case '^': total = pow(total, Value(formula) ); break; case '=': total = (total == Value(formula) ); break; case '\)': return(total); break; default: formula->error = INVALID; return(0); } /* end of case */ } /* end of while */ return (total); } /* end of Solve */ double Value(formula) struct Formula_Master *formula; { extern double x, y, z, t; int whichfunc, position; double a,b; char test, bitmask, tmp, lowmask, highbit; position = formula->position; test = formula->equation[formula->position]; if (test == '\(') { formula->position++; return(Solve(formula)); } tmp = (test & HIGHBIT); if (tmp != 0) { return ( formula->constants[ LOWMASK & formula->equation[formula->position++] ] ); } formula->position++; switch (test) { case '\(': /* ( */ return(Solve(formula)); break; case 'x': /* X */ return(x); break; case 'y': /* Y */ return(y); break; case 't': /* T */ return(t); break; case 'z': /* Z */ return(z); break; case 'c': /* Cos */ return (cos ( Value (formula) ) ); break; case 's': /* Sin */ return (sin ( Value (formula) ) ); break; case 'T': /* Tan */ return (tan ( Value (formula) ) ); break; case 'e': /* E to the x */ return ( exp ( Value(formula) ) ); break; case 'P': /* PI */ return ( PI ); break; case 'E': /* E to the x */ return ( exp (1.0) ); break; case 'l': /* ln */ return ( log ( Value(formula) ) ); break; case 'a': /* Atan */ return ( atan ( Value(formula) ) ); break; case 'S': /* Asin */ return ( asin ( Value(formula) ) ); break; case 'C': /* Acos */ return ( acos ( Value(formula) ) ); break; case 'A': /* abs */ return ( abs ( Value(formula) ) ); break; default: formula->error = UNKNOWN; return(0); } /* end of switch */ } /* end of routine */ GetFunction(infile, formula) FILE *infile; struct Formula_Master *formula; { char text[50], inchar; double a; int position, lasttype, function, constants, whichfunc; position = 0; function = 0; constants = 0; while ( (inchar = getc(infile) ) == ' '); lasttype = Type(inchar); for ever { if ((lasttype == Type(inchar)) && (inchar != ' ')) { text[position++] = inchar; } else { text[position] = 0; if (lasttype == ALPHA) { for (whichfunc = 0; strcmp(text, &functions[whichfunc][1]) ; whichfunc++) { if (!strcmp( functions[whichfunc], "end") ) { return(FALSE); } } formula->equation[function++] = functions[whichfunc][0]; } if (lasttype == NUMERIC) { formula->equation[function++] = (HIGHBIT | constants); sscanf(text, "%f", &a ); formula->constants[constants++] = a; } if (lasttype == OTHER) { position = 0; while (text[position] !=0) { formula->equation[function++] = text[position++]; } } if (inchar == ' ') while ( (inchar = getc(infile) ) == ' '); position = 0; text[position++] = inchar; lasttype = Type(inchar); } /* end of else */ if (lasttype == END) break; inchar = getc(infile); } /* end of forever */ formula->equation[function] = 0; if (function == 0) { FreeFunction(formula); return(FALSE); } return(TRUE); } /* end of routine */ Type(character) char character; { if(character >= 'a' && character <= 'z') return (ALPHA); if(character >= 'A' && character <= 'Z') return (ALPHA); if(character >= '0' && character <= '9') return (NUMERIC); if(character == '.') return (NUMERIC); if(character == ';' || character == '\n' || character == '\r' || character == EOF) return(END); return(OTHER); } SetDefaults(parameters) struct Graph_Parameters *parameters; { parameters->end = FALSE; parameters->xstart = -5.0; parameters->ystart = -5.0; parameters->zstart = -5.0; parameters->tstart = -5.0; parameters->xend = 5.0; parameters->yend = 5.0; parameters->zend = 5.0; parameters->tend = 5.0; parameters->xlabels = 1.0; parameters->ylabels = 1.0; parameters->zlabels = 1.0; parameters->detail = 1.0; } GetVariables(Window, parameters, infile) struct Window *Window; struct Graph_Parameters *parameters; FILE *infile; { char inchar, variable, command; double number; long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; for ever { DrawRectangle(Window, 1l, minx, miny, maxx, miny+110); DisplayVariables(Window, parameters); variable = getc(infile); if (variable == '\r' || variable == '\n' || variable == 'e') break; if (variable != 'd' || variable != 'h' ) command = getc(infile); if (command == '=' || variable == 'h') command = '1'; else while ( (inchar = getc(infile) ) != '=' ); if (command < '0' || command > '9') { number = GetNum(infile); if (number != 0.0) { if(variable== 'd') parameters->detail = number; if(variable== 'h') parameters->hidden = (parameters->hidden) ? FALSE : TRUE; if(variable== 'x' && command== 's')parameters->xstart = number; if(variable== 'x' && command== 'e')parameters->xend = number; if(variable== 'x' && command== 'l')parameters->xlabels =number; if(variable== 'y' && command== 's')parameters->ystart = number; if(variable== 'y' && command== 'e')parameters->yend = number; if(variable== 'y' && command== 'l')parameters->ylabels =number; if(variable== 'z' && command== 's')parameters->zstart = number; if(variable== 'z' && command== 'e')parameters->zend = number; if(variable== 'z' && command== 'l')parameters->zlabels =number; if(variable== 't' && command== 's')parameters->tstart = number; if(variable== 't' && command== 'e')parameters->tend = number; } /* end of 0.0 else */ } /* end of if not equation */ else /* Its a formula */ { if (variable == 'x') { if (!parameters->xon) parameters->x1 = AllocateFunction(); if (parameters->x1 != NULL) { if (!GetFunction(infile, parameters->x1)) { parameters->xon = FALSE; error(Window, FALSE); } else { parameters->xon = TRUE; parameters->x1->position=0; parameters->x1->error = FALSE; Solve(parameters->x1); if (parameters->x1->error != FALSE) error(Window, parameters->x1->error); } } } /* end of x = */ if (variable == 'y') { if (!parameters->yon) parameters->y1 = AllocateFunction(); if (parameters->y1 != NULL) { if (!GetFunction(infile, parameters->y1)) { parameters->yon = FALSE; error(Window, FALSE); } else { parameters->yon = TRUE; parameters->y1->position=0; parameters->y1->error = FALSE; Solve(parameters->y1); if (parameters->y1->error != FALSE) error(Window, parameters->y1->error); } } } /* end of y = */ if (variable == 'z') { if (!parameters->zon) parameters->z1 = AllocateFunction(); if (parameters->z1 != NULL) { if (!GetFunction(infile, parameters->z1)) { parameters->zon = FALSE; error(Window, FALSE); } else { parameters->zon = TRUE; parameters->z1->position=0; parameters->z1->error = FALSE; Solve(parameters->z1); if (parameters->z1->error != FALSE) error(Window, parameters->z1->error); } } } /* end of z = */ } /* end of else */ } /* end of for ever */ } /* end of command */ error(Window, error) struct Window *Window; int error; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; DrawRectangle(Window, 3l, minx, miny+10, maxx, miny+115); SetAPen(Window->RPort, 1l); if (error == INVALID) Print(Window, "Invalid Function was entered", 13l); else if (error == UNKNOWN) Print(Window, "An unknown Function was entered", 13l); else if (error == FALSE) Print(Window, "An unknown Function was entered", 13l); } double GetNum(infile) FILE *infile; { char inchar, text[20]; int position; double a; position = 0; inchar = getc(infile); while (Type(inchar) != END) { text[position++] = inchar; inchar = getc(infile); } text[position] = 0; sscanf(text, "%f", &a ); return(a); } char *AllocateFunction() { struct Formula_Master *formula; formula = AllocMem( (long) sizeof(struct Formula_Master), 0); if (formula == NULL) return(0); formula->equation = AllocMem(sizeof(char) * FSIZE , 0); if (formula->equation == NULL) return(0); formula->constants = AllocMem(sizeof(double) * CONSTANTS , 0); if (formula->constants == NULL) return(0); return(formula); } FreeFunction(formula) struct Formula_Master *formula; { FreeMem(formula->equation, sizeof(char) * FSIZE); FreeMem(formula->constants, sizeof(double) * CONSTANTS); FreeMem(formula, sizeof (struct Formula_Master) ); } GetCommand(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { FILE *infile; char list[80]; infile = fopen("con:0/140/640/36/Enter Command", "r"); if (infile == NULL) { parameters->error = WINDOW; return(0); } GetVariables(Window, parameters, infile); fclose(infile); } LoadFile(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { FILE *infile; char line[80], file[40]; GetFileName(line); infile = fopen(line, "r"); if (infile == NULL) return(); GetVariables(Window, parameters, infile); fclose(infile); } SaveFile(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { FILE *outfile; char line[80], file[40]; GetFileName(line); outfile = fopen(line, "w"); if (outfile == NULL) return(); fprintf(outfile, "xstart=%f\n", parameters->xstart); fprintf(outfile, "ystart=%f\n", parameters->ystart); fprintf(outfile, "zstart=%f\n", parameters->zstart); fprintf(outfile, "tstart=%f\n", parameters->tstart); fprintf(outfile, "xend=%f\n", parameters->xend); fprintf(outfile, "yend=%f\n", parameters->yend); fprintf(outfile, "zend=%f\n", parameters->zend); fprintf(outfile, "tend=%f\n", parameters->tend); fprintf(outfile, "xlabels=%f\n", parameters->xlabels); fprintf(outfile, "ylabels=%f\n", parameters->ylabels); fprintf(outfile, "zlabels=%f\n", parameters->zlabels); fprintf(outfile, "detail=%f\n", parameters->detail); if(parameters->xon) { Expand(parameters->x1, line); fprintf(outfile, "x1=%s\n", line); } if(parameters->yon) { Expand(parameters->y1, line); fprintf(outfile, "y1=%s\n", line); } if(parameters->zon) { Expand(parameters->z1, line); fprintf(outfile, "z1=%s\n", line); } fprintf(outfile,"e\n"); fclose(outfile); } GetFileName(line) char line[]; { FILE *infile; char inchar; int position; infile = fopen("con:0/140/640/24/Please Enter Filename:", "r"); if (infile == NULL) return(0); position = 0; inchar = getc(infile); while ( Type(inchar) != END) { line[position++] = inchar; inchar = getc(infile); } line[position] = 0; fclose(infile); } DisplayVariables(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { char line[80], tmp[80]; SetAPen(Window->RPort, 3l); SetBPen(Window->RPort, 0l); SetDrMd(Window->RPort, JAM2); Print(Window, "Current Variable Settings", 0); sprintf(line, " start end labels other "); Print(Window, line, 1); sprintf(line,"x:%4.6f %4.6f %4.6f",parameters->xstart, parameters->xend, parameters->xlabels); Print(Window, line, 2); sprintf(line, "y:%4.6f %4.6f %4.6f", parameters->ystart, parameters->yend, parameters->ylabels); Print(Window, line, 3); sprintf(line, "z:%4.6f %4.6f %4.6f", parameters->zstart, parameters->zend, parameters->zlabels); Print(Window, line, 4); sprintf(line, "t:%4.6f %4.6f N/A", parameters->tstart, parameters->tend); Print(Window, line, 5); sprintf(line, "Detail is %4.6f", parameters->detail); Print(Window, line, 6); if(parameters->hidden) Print(Window, "Hidden lines is ON ", 7); else Print(Window, "Hidden lines is OFF", 7); if (parameters->xon) { Expand(parameters->x1, line); sprintf(tmp, "x="); strcat (tmp, line); strcat (tmp, " "); Print(Window, tmp, 9); } if (parameters->yon) { Expand(parameters->y1, line); sprintf(tmp, "y="); strcat (tmp, line); strcat (tmp, " "); Print(Window, tmp, 10); } if (parameters->zon) { Expand(parameters->z1, line); sprintf(tmp, "z="); strcat (tmp, line); strcat (tmp, " "); Print(Window, tmp, 11); } } Expand(formula, line) struct Formula_Master *formula; char line[]; { int loop, position; char tmp[30]; line[0]=0; for (position = 0; position < strlen(formula->equation); position++) { if ((formula->equation[position] & HIGHBIT) != 0) { sprintf(tmp, "%f", formula->constants[LOWMASK & formula->equation[position]]); strcat(line, tmp); } else { loop = 0; /* is this wrong ? */ while (strcmp(functions[loop], "end") ) { if (functions[loop][0] == formula->equation[position]) strcat(line, &functions[loop][1]); loop++; } /* end of while */ } /* end of else */ } /* end of for */ } /* end of the routine */ @//E*O*F func.c// chmod u=rw,g=rw,o=r func.c echo x - three-d.c sed 's/^@//' > "three-d.c" <<'@//E*O*F three-d.c//' #include "graph.h" #define ANGLEX 45 long int xcenter, ycenter; long int minx, miny, maxx, maxy; double xconversion, yconversion; double SINX, COSX; Plot3dGraph(Window, parameters) struct Graph_Parameters *parameters; struct Window *Window; { extern double x,y,z,t; extern long int xcenter, ycenter; extern double xconversion, yconversion; extern double SINX, COSX; extern long int minx, miny, maxx, maxy; double a, x1, x2, y1, y2, z1, z2, xnext, ynext, xtemp, ytemp; double xstep, ystep, minz, maxz; double xsize, ysize, top, bottom, left, right; /* the stuff needed for hidden lines */ WORD *areabuffer; struct TmpRas tmpras; struct TmpRas *lasttmp; struct AreaInfo myAreaInfo; char *raster; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; /* setup things for whats is needed for hidden */ if (parameters->hidden) { areabuffer = AllocMem(sizeof(WORD) * 750l, MEMF_CHIP); if (areabuffer == NULL) parameters->hidden = FALSE; else { InitArea(&myAreaInfo, areabuffer, 300l); Window->RPort->AreaInfo = &myAreaInfo; raster = AllocRaster(maxx, maxy); if (raster == NULL) parameters->hidden = FALSE; else { lasttmp = Window->RPort->TmpRas; Window->RPort->TmpRas = InitTmpRas(&tmpras, raster, RASSIZE(maxx, maxy)); } } } a=ANGLEX * PI / 180; /* I hate to do this but my doubles do not */ SINX = sin(a); /* work right under Manx 3.30 */ COSX = cos(a); left = 0; right = 0; if (parameters->xend > 0 ) left = parameters->xend * COSX; if (parameters->xstart < 0 ) right = -parameters->xstart * COSX; if (parameters->ystart < 0) left -= parameters->ystart; if (parameters->yend > 0) right += parameters->yend; xsize = left + right; ysize = parameters->yend - parameters->ystart; xconversion = (maxx - minx) / xsize; yconversion = (maxy - miny) / ysize; xstep = parameters->detail / xconversion; ystep = parameters->detail / yconversion; /* analyze the graph to determine the max hight and min hight */ minz = INFINITY; maxz = -INFINITY; SetAPen(Window->RPort, 1l); SetBPen(Window->RPort, 0l); SetDrMd(Window->RPort, JAM2); Print(Window, "Please Wait Analyzing Graph", 1); y = parameters->ystart; while ( y < parameters->yend ) { x = parameters->xstart; while ( x < parameters->xend ) { parameters->z1->position = 0; z1 = Solve(parameters->z1); x += xstep; z = (z1 - x * COSX); minz = min(minz, z); maxz = max(maxz, z); } /* end of xwhile */ y += parameters->ylabels; } /* end of y loop */ ysize = maxz - minz; yconversion = (maxy - miny) / ysize; ystep = parameters->detail / yconversion; if (left > 0 ) xcenter = left * xconversion + minx + 2; else xcenter = -left * xconversion + minx + 2; ycenter = maxy + minz * yconversion; /* Draw the Graph rectangle area */ SetAPen(Window->RPort, 0); SetOPen(Window->RPort, 2); SetDrMd(Window->RPort, JAM2); DrawRectangle(Window, 1, minx, miny, maxx, maxy); xconversion *= 0.90; yconversion *= 0.90; Line3d(Window, 2l, 0.0, 0.0, 0.0, parameters->xend, 0.0, 0.0); Line3d(Window, 2l, 0.0, 0.0, 0.0, 0.0, parameters->yend, 0.0); Line3d(Window, 2l, 0.0, 0.0, 0.0, 0.0, 0.0, parameters->zend); ynext = parameters->ystart; while (ynext < parameters->yend) { xnext = parameters->xstart; while (xnext < parameters->xend) { parameters->z1->position = 0; x = xnext; y = ynext; x1 = x; y1 = y; z1 = Solve(parameters->z1); InitVertices(Window, parameters, 1l, x1, y1, z1); while (x < xnext + parameters->xlabels) { parameters->z1->position = 0; x += xstep; x1 = x; y1 = y; z1 = Solve(parameters->z1); AddVertice(Window, parameters, x1, y1, z1); } /* end of xblock while */ xtemp = x1; while (y < ynext + parameters->ylabels) { parameters->z1->position = 0; y += ystep; x1 = x; y1 = y; z1 = Solve(parameters->z1); AddVertice(Window, parameters, x1, y1, z1); } /* end of yblock while */ ytemp = y1; if (parameters->hidden || xnext == parameters->xstart || y >= parameters->yend) { while (x > xnext) { parameters->z1->position = 0; x -= xstep; x1 = x; y1 = y; z1 = Solve(parameters->z1); AddVertice(Window, parameters, x1, y1, z1); } /* end of xblock while */ } /* end of the check to see if valid */ if (parameters->hidden || xnext == parameters->xstart) { while (y > ynext) { parameters->z1->position = 0; y -= ystep; x1 = x; y1 = y; z1 = Solve(parameters->z1); AddVertice(Window, parameters, x1, y1, z1); } /* end of yblock while */ } /* end of the if */ DrawVertices(Window, parameters); xnext = xtemp; } /* end of xmaster */ ynext = ytemp; } /* end of ymaster */ if (parameters->hidden) { FreeRaster(raster, maxx, maxy); FreeMem(areabuffer, sizeof(WORD) * 750l); Window->RPort->TmpRas = lasttmp; } return(); } Line3d(Window, colour, x1, y1, z1, x2, y2, z2) struct Window *Window; long int colour; double x1, y1, z1, x2, y2, z2; { extern long int xcenter, ycenter; extern double xconversion, yconversion; extern double SINX, COSX; long int xa, ya, xb, yb; xa = xcenter + (x1 * SINX - y1) * xconversion; ya = ycenter - (x1 * COSX - z1) * yconversion; xb = xcenter + (x2 * SINX - y2) * xconversion; yb = ycenter - (x2 * COSX - z2) * yconversion; Line(Window, colour, xa, ya, xb, yb); } long int lastx, lasty; int points; InitVertices(Window, parameters, colour, x1, y1, z1) struct Window *Window; struct Graph_Parameters *parameters; long int colour; double x1, y1, z1; { extern long int xcenter, ycenter; extern double xconversion, yconversion; extern double SINX, COSX; extern long minx, miny, maxx, maxy; extern int lastx, lasty; extern int points; long int xa, ya; xa = xcenter + (x1 * SINX - y1) * xconversion; ya = ycenter - (x1 * COSX - z1) * yconversion; lastx = xa; lasty = ya; if (!(xa > minx && xa < maxx && ya > miny && ya < maxy) ) return(); SetOPen(Window->RPort, colour); SetAPen(Window->RPort, 0l); points = 1; if (parameters->hidden) AreaMove(Window->RPort, xa, ya); else { Move(Window->RPort, xa, ya); SetAPen(Window->RPort, colour); } } AddVertice(Window, parameters, x1, y1, z1) struct Window *Window; struct Graph_Parameters *parameters; double x1, y1, z1; { extern long int xcenter, ycenter; extern double xconversion, yconversion; extern double SINX, COSX; extern long minx, miny, maxx, maxy; extern long int lastx, lasty; extern int points; long int xa, ya; xa = xcenter + (x1 * SINX - y1) * xconversion; ya = ycenter - (x1 * COSX - z1) * yconversion; if (lastx == xa && lasty == ya) return(); lastx = xa; lasty = ya; if (!(xa > minx && xa < maxx && ya > miny && ya < maxy) ) return(); if (parameters->hidden) { AreaDraw(Window->RPort, xa, ya); points++; } else Draw(Window->RPort, xa, ya); } DrawVertices(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { extern int points; if (parameters->hidden) AreaEnd(Window->RPort); } @//E*O*F three-d.c// chmod u=rw,g=rw,o=r three-d.c echo x - window.c sed 's/^@//' > "window.c" <<'@//E*O*F window.c//' /****************************************************************************/ /* Program: Graph It II (The C Program) */ /* SubModule: window.c 1-20-87 */ /* CopyRight By Flynn D. Fishman January 1987 */ /* Feel Free to copy and alter this source */ /****************************************************************************/ /* This module contains some of the more "primitive" graphic routines such as Line, DrawImages, DrawWindow */ #include "graph.h" #define MAXMENU 2 struct Menu menu[MAXMENU]; /* Image data structures (Icons) */ USHORT Move_Icon[] = { 0xffff, 0x8001, 0x8001, 0x8181, 0x8d81, 0x8db1, 0x8db1, 0xedb5, 0xeffd, 0xbffd, 0x9ffd, 0x8ff1, 0x8001, 0x8001, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- 22-2 2--- ---1 */ 0x8001, /* 1--- 22-2 2-22 ---1 */ 0x8001, /* 1--- 22-2 2-22 ---1 */ 0x8001, /* 122- 22-2 2-22 -2-1 */ 0x8001, /* 122- 2222 2222 22-1 */ 0x8001, /* 1-22 2222 2222 22-1 */ 0x8001, /* 1--2 2222 2222 22-1 */ 0x8001, /* 1--- 2222 2222 2--1 */ 0x9ffd, /* 1--3 3333 3333 33-1 */ 0x9ffd, /* 1--3 3333 3333 33-1 */ 0xffff /* 1111 1111 1111 1111 */ }; USHORT Zoom_Icon[] = { 0xffff, 0x8001, 0x83c1, 0x8661, 0x8c31, 0x8c31, 0x8661, 0x83c1, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0x8001, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- --33 33-- ---1 */ 0x8001, /* 1--- -332 233- ---1 */ 0x8001, /* 1--- 33-- 2233 ---1 */ 0x8001, /* 1--- 33-- -233 ---1 */ 0x8001, /* 1--- -33- -33- ---1 */ 0x8001, /* 1--- --33 33-- ---1 */ 0x8001, /* 1--- ---3 3--- ---1 */ 0x8001, /* 1--- ---3 3--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---3 3--- ---1 */ 0x8001, /* 1--- ---3 3--- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0xffff, /* 1111 1111 1111 1111 */ }; USHORT Command_Icon[] = { 0xffff, 0x8001, 0x8001, 0xe0c1, 0xe0c1, 0xb19f, 0x9b1f, 0x8e01, 0x8c1f, 0x8c1f, 0x8c01, 0x8c01, 0x8001, 0x8001, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 122- ---- 22-- ---1 */ 0x8001, /* 122- ---- 22-- ---1 */ 0x8001, /* 1-22 ---2 2--2 2221 */ 0x8001, /* 1--2 2-22 ---2 2221 */ 0x8001, /* 1--- 222- ---- ---1 */ 0x8001, /* 1--- 22-- ---2 2221 */ 0x8001, /* 1--- 22-- ---2 2221 */ 0x8001, /* 1--- 22-- ---- ---1 */ 0x8001, /* 1--- 22-- ---- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0xffff /* 1111 1111 1111 1111 */ }; USHORT Help_Icon[] = { 0xffff, 0x8001, 0x83e1, 0x87e1, 0x8c71, 0x80e1, 0x80e1, 0x81c1, 0x81c1, 0x8001, 0x8081, 0x81c1, 0x8081, 0x8001, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- --22 222- ---1 */ 0x8001, /* 1--- -222 2222 ---1 */ 0x8001, /* 1--- 22-- -222 ---1 */ 0x8001, /* 1--- ---- 222- ---1 */ 0x8001, /* 1--- ---- 222- ---1 */ 0x8001, /* 1--- ---2 22-- ---1 */ 0x8001, /* 1--- ---2 22-- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- ---- 2--- ---1 */ 0x8001, /* 1--- ---2 22-- ---1 */ 0x8001, /* 1--- ---- 2--- ---1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0xffff, /* 1111 1111 1111 1111 */ }; USHORT Hidden_Icon[] = { 0xffff, 0x8001, 0x8001, 0x8001, 0x83cf, 0x8301, 0x8301, 0x8301, 0x8001, 0x8301, 0x8301, 0x8301, 0x83ff, 0x8001, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---- ---- ---1 */ 0xbff1, /* 1-22 2222 2222 ---1 */ 0xb031, /* 1-22 ---- --22 ---1 */ 0xb03f, /* 1-22 --11 1122 3331 */ 0xb031, /* 1-22 --11 --22 ---1 */ 0xb031, /* 1-22 --11 --22 ---1 */ 0xb031, /* 1-22 --11 --22 ---1 */ 0xbff1, /* 1-22 2222 2222 ---1 */ 0x8301, /* 1--- --33 ---- ---1 */ 0x8301, /* 1--- --33 ---- ---1 */ 0x8301, /* 1--- --33 ---- ---1 */ 0x83ff, /* 1--- --33 3333 3331 */ 0x8001, /* 1--- ---- ---- ---1 */ 0xffff, /* 1111 1111 1111 1111 */ }; USHORT Home_Icon[] = { 0xffff, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0xffff, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0x8181, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1222 2222 2222 2221 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0x8001, /* 1--- ---2 2--- ---1 */ 0xffff /* 1111 1111 1111 1111 */ }; USHORT Quit_Icon[] = { 0xffff, 0x8001, 0x83c1, 0x8661, 0x8c31, 0x8c31, 0x9819, 0x9819, 0x9999, 0x9db9, 0x8cf1, 0x8679, 0x83cd, 0x8001, 0xffff, 0xffff, /* 1111 1111 1111 1111 */ 0x8001, /* 1--- ---- ---- ---1 */ 0x8001, /* 1--- --22 22-- ---1 */ 0x8001, /* 1--- -22- -22- ---1 */ 0x8001, /* 1--- 22-- --22 ---1 */ 0x8001, /* 1--- 22-- --22 ---1 */ 0x8001, /* 1--2 2--- ---2 2--1 */ 0x8001, /* 1--2 2--- ---2 2--1 */ 0x8001, /* 1--2 2--2 2--2 2--1 */ 0x8001, /* 1--- 22-2 2-22 ---1 */ 0x8001, /* 1--- 22-- 2222 ---1 */ 0x8001, /* 1--- -22- -222 2--1 */ 0x8001, /* 1--- --22 22-- 22-1 */ 0x8001, /* 1--- ---- ---- ---1 */ 0xffff /* 1111 1111 1111 1111 */ }; #define BALLHEIGHT 5 #define BALLWIDTH 6 struct Image Icons = { 0,0, /* left Top */ 16, ICONY, 2, /* width hieght, depth */ &Move_Icon[0], /* image date */ 0x3, 0x0, /* PlanePick, PlaneOnOff */ NULL, /* Next Image */ }; struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; struct TextAttr MyFont = { "topaz.font", /* Font Name */ TOPAZ_SIXTY, /* Font Height */ FS_NORMAL, /* Style */ FPF_ROMFONT, /* Preferences */ }; struct NewWindow NewWindow = { 0l, 0l, XSIZE, YSIZE, 0l, 1l, CLOSEWINDOW | MOUSEMOVE | MOUSEBUTTONS | MENUPICK | NEWSIZE | INACTIVEWINDOW | SIZEVERIFY, WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWDRAG | WINDOWDEPTH | WINDOWSIZING | REPORTMOUSE, NULL, NULL, "Graph It II Beta 1.0 By Flynn D. Fishman", NULL, NULL, 100l, 35l, NULL, NULL, WBENCHSCREEN, }; openstuff() { struct Window *Window; IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", INTUITION_REV); if( IntuitionBase == NULL ) { printf("Error: opening Intuition\n"); exit(FALSE); } GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",GRAPHICS_REV); if( GfxBase == NULL ) { printf("Error: opening graphics\n"); exit(FALSE); } if(( Window = (struct Window *)OpenWindow(&NewWindow) ) == NULL) { printf("Error: opening window\n"); exit(FALSE); } InitMenu(); SetMenuStrip( Window, &menu[0] ); return(Window); } closestuff(Window) struct Window *Window; { if (Window != NULL) { CloseWindow( Window ); ClearMenuStrip( Window ); } } DrawWindow(Window, parameters) struct Window *Window; struct Graph_Parameters *parameters; { long int minx, miny, maxx, maxy; long int y; char line[80]; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; ClearWindow(Window); /* Place the data */ SetAPen(Window->RPort, 3); Move(Window->RPort, minx, maxy + 9); sprintf(line,"%2.2f", parameters->xstart); Text(Window->RPort, line, strlen(line) ); Move(Window->RPort, maxx - XEXPANDX + 3, maxy + 9); sprintf(line,"%2.2f", parameters->xend); Text(Window->RPort, line, strlen(line) ); Move(Window->RPort, maxx, maxy - YEXPANDY + 9); sprintf(line,"%3.0f", parameters->ystart); Text(Window->RPort, line, strlen(line) ); Move(Window->RPort, maxx, miny + 9); sprintf(line,"%3.0f", parameters->yend); Text(Window->RPort, line, strlen(line) ); /* Draw the Graph rectangle area */ DrawRectangle(Window, 1, minx, miny, maxx, maxy); /* Draw the X-Expand area */ DrawRectangle(Window, 3, minx + XEXPANDX, maxy + 2, maxx - XEXPANDX, maxy + XEXPANDY); /* Draw the Y-Expand area */ DrawRectangle(Window, 3, maxx + 2, miny + YEXPANDY, maxx + YEXPANDX, maxy - YEXPANDY); /* Draw the Icon Area */ for (y = miny + YEXPANDY; y < maxy - YEXPANDX - ICONY; y += ICONY + 2) DrawRectangle(Window, 3, maxx + YEXPANDX + 2, y, maxx + XBORDER - 1, y + ICONY); DrawImages(Window, maxx + YEXPANDX + 2, miny + YEXPANDY); DrawButton(Window, minx + XEXPANDX + 1, maxy + 3); DrawButton(Window, maxx + 3, maxy - YEXPANDY - BALLHEIGHT - 1 ); } ClearWindow(Window) struct Window *Window; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight; maxy = Window->Height - Window->BorderBottom; SetAPen(Window->RPort, 0l); SetOPen(Window->RPort, 0l); SetDrMd(Window->RPort, JAM2); RectFill(Window->RPort, minx, miny, maxx, maxy); } DrawRectangle(Window, colour, x1, y1, x2, y2) struct Window *Window; long int colour, x1, y1, x2, y2; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight; maxy = Window->Height - Window->BorderBottom; x1 = (x1 < minx) ? minx : x1; y1 = (y1 < miny) ? miny : y1; x2 = (x2 > maxx) ? maxx : x2; y2 = (y2 > maxy) ? maxy : y2; if (x1 > x2) return(FALSE); if (y1 > y2) return(FALSE); SetDrMd(Window->RPort, JAM2); SetOPen(Window->RPort, colour); SetAPen(Window->RPort, 0l); RectFill(Window->RPort, x1, y1, x2, y2); } DrawImages(Window, x, y) struct Window *Window; long int x, y; { USHORT *icon; int loop; Icons.Height = ICONY; Icons.Width = ICONX; Icons.PlanePick = 0x3; Icons.PlaneOnOff = 0x0; icon = AllocMem( (long) sizeof(USHORT) * ICONY * Icons.Depth + 10, MEMF_CHIP); Icons.ImageData = icon; for (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Zoom_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); y += ICONY + 2; for (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Move_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); y += ICONY + 2; for (loop=0; loop<ICONY * Icons.Depth; loop++) icon[loop] = Command_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); y += ICONY + 2; for (loop=0; loop< ICONY * Icons.Depth; loop++) icon[loop] = Hidden_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); y += ICONY + 2; /* future location of home icon */ for (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Home_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); y += ICONY + 2; /* future location of quit icon */ for (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Quit_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); y += ICONY + 2; for (loop=0; loop < ICONY * Icons.Depth; loop++) icon[loop] = Help_Icon[loop]; DrawImage(Window->RPort, &Icons, x, y); FreeMem( icon, (long) sizeof(USHORT) * ICONY * Icons.Depth); } InvertIcon(Window, icon) struct Window *Window; long int icon; { long int x, y; long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; SetDrMd(Window->RPort, COMPLEMENT); SetAPen(Window->RPort, 3l); SetOPen(Window->RPort, 0l); y = miny + YEXPANDY + (icon - 1) * (ICONY + 2); RectFill(Window->RPort, maxx + YEXPANDX +2, y, maxx +XBORDER -1, y +ICONY); } DrawButton(Window, x, y) struct Window *Window; long int x,y; { long int minx, miny, maxx, maxy; SetDrMd(Window->RPort, JAM2); SetAPen(Window->RPort, 2l); SetOPen(Window->RPort, 2l); RectFill(Window->RPort, x, y, x + BALLWIDTH - 1, y + BALLHEIGHT - 1); } EraseButton(Window, x, y) struct Window *Window; long int x,y; { long int minx, miny, maxx, maxy; SetDrMd(Window->RPort, JAM2); SetAPen(Window->RPort, 0l); SetOPen(Window->RPort, 0l); RectFill(Window->RPort, x, y, x + BALLWIDTH - 1, y + BALLHEIGHT - 1); } swap (x1, x2) long int *x1, *x2; { long int tmp; tmp = *x1; *x1 = *x2; *x2 = tmp; } Line(Window, colour, x1, y1, x2, y2) struct Window *Window; long int colour, x1, y1, x2, y2; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; /* Clip the edges of the graph */ /* start with the horizontal borders */ if (y1 >= miny && y1 <= maxy && y2 >= miny && y2 <= maxy);/* Do nothing */ else if ( (y1 - miny) * (y2 - miny) < 0 ) { /* Clip against top edge */ if (y2 > miny) { swap(&x1, &x2); swap(&y1, &y2); } x2 = (miny - y1)*(x1-x2)/(y1-y2)+x1; y2 = miny; } else if ( (y1 - maxy) * (y2 - maxy) < 0 ) { /* Clip against bottom edge */ if (y2 < maxy) { swap(&x1, &x2); swap(&y1, &y2); } x2 = (maxy - y1)*(x1-x2)/(y1-y2)+x1; y2 = maxy; } else return(); /* and know the vertical edges */ if (x1 >= minx && x1 <= maxx && x2 >= minx && x2 <= maxx);/* Do nothing */ else if ( (x1 - minx) * (x2 - minx) < 0 ) { /* Clip against top edge */ if (x2 > minx) { swap(&x1, &x2); swap(&y1, &y2); } y2 = (minx - x1)*(y1-y2)/(x1-x2)+y1; x2 = minx; } else if ( (x1 - maxx) * (x2 - maxx) < 0 ) { /* Clip against bottom edge */ if (x2 < maxx) { swap(&x1, &x2); swap(&y1, &y2); } y2 = (maxx - x1)*(y1-y2)/(x1-x2)+y1; x2 = maxx; } else return(); SetAPen(Window->RPort, colour); Move(Window->RPort, x1, y1); Draw(Window->RPort, x2, y2); } CrossHair(Window, x, y) struct Window *Window; long int x, y; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; SetDrMd(Window->RPort, COMPLEMENT); Line(Window, 3l, x, miny, x, maxy); Line(Window, 3l, minx, y, maxx, y); SetDrMd(Window->RPort, JAM2); } Box(Window, deltax, deltay) struct Window *Window; long int deltax, deltay; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; SetDrMd(Window->RPort, COMPLEMENT); if (deltax > 0) Line(Window, 3l, minx + deltax, miny, minx + deltax, maxy); if (deltax < 0) Line(Window, 3l, maxx + deltax, miny, maxx + deltax, maxy); if (deltay > 0) Line(Window, 3l, minx, miny + deltay, maxx, miny + deltay); if (deltay < 0) Line(Window, 3l, minx, maxy + deltay, maxx, maxy + deltay); SetDrMd(Window->RPort, JAM2); } DrawGrid(Window) struct Window *Window; { long int minx, miny, maxx, maxy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; SetDrMd(Window->RPort, COMPLEMENT); Line(Window, 1l, maxx / 3, miny, maxx / 3, maxy); Line(Window, 1l, maxx * 2/ 3, miny, maxx * 2 / 3, maxy); Line(Window, 1l, minx, maxy / 3, maxx, maxy / 3); Line(Window, 1l, minx, maxy * 2 / 3, maxx, maxy * 2 / 3); SetDrMd(Window->RPort, JAM2); } Real(Window, parameters, x1, y1, x2, y2) struct Window *Window; struct Graph_Parameters *parameters; long int x1, y1, x2, y2; { long int minx, miny, maxx, maxy; double xsize, ysize, xstart, ystart, xend, yend, xconversion, yconversion; if (x1 == x2 || y1 == y2) return(); minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; x1 = x1 - minx; x2 = x2 - minx; y1 = y1 - miny; y2 = y2 - miny; xsize = parameters->xend - parameters->xstart; ysize = parameters->yend - parameters->ystart; xstart = parameters->xstart; ystart = parameters->ystart; xend = parameters->xend; yend = parameters->yend; xconversion = xsize /(maxx - minx); yconversion = ysize /(maxy - miny); if (x1 > x2) swap (&x1, &x2); if (y1 > y2) swap (&y1, &y2); parameters->xstart = xstart + xconversion * x1; parameters->ystart = ystart + yconversion * y1; parameters->xend = xstart + xconversion * x2; parameters->yend = ystart + yconversion * y2; DrawWindow(Window, parameters); } Shift(Window, parameters, dx, dy) struct Window *Window; struct Graph_Parameters *parameters; long int dx, dy; { long int minx, miny, maxx, maxy; double xsize, ysize, xstart, ystart, xend, yend, xconversion, yconversion; double deltax, deltay; deltax = dx; deltay = dy; minx = Window->BorderLeft; miny = Window->BorderTop; maxx = Window->Width - Window->BorderRight - XBORDER; maxy = Window->Height - Window->BorderBottom - YBORDER; xsize = parameters->xend - parameters->xstart; ysize = parameters->yend - parameters->ystart; xstart = parameters->xstart; ystart = parameters->ystart; xend = parameters->xend; yend = parameters->yend; xconversion = xsize /(maxx - minx); yconversion = ysize /(maxy - miny); parameters->xstart = xstart + xconversion * deltax; parameters->ystart = ystart + yconversion * deltay; parameters->xend = xend + xconversion * deltax; parameters->yend = yend + yconversion * deltay; } /* define maximum number of menu items */ #define MENU0MAX 4 #define MENU1MAX 7 struct MenuItem ItemText0[MENU0MAX]; struct MenuItem ItemText1[MENU1MAX]; struct IntuiText MenuItem0[MENU0MAX]; struct IntuiText MenuItem1[MENU1MAX]; InitMenu() { InitMenu0(); InitMenu1(); menu[0].NextMenu = &menu[1]; menu[0].LeftEdge = 10; menu[0].TopEdge = 0; menu[0].Width = 80; menu[0].Height = 10; menu[0].Flags = MENUENABLED; menu[0].MenuName = "Project"; /* text for menu-bar display */ menu[0].FirstItem = &ItemText0[0]; /* pointer to first item in list */ menu[1].NextMenu = NULL; menu[1].LeftEdge = 100; menu[1].TopEdge = 0; menu[1].Width = 100; menu[1].Height = 10; menu[1].Flags = MENUENABLED; menu[1].MenuName = "Functions"; /* text for menu-bar display */ menu[1].FirstItem = &ItemText1[0]; /* pointer to first item in list */ } InitMenu0() { short n; /* initialize each meu item and IntuiText with loop */ for( n=0; n<MENU1MAX; n++ ) { ItemText0[n].NextItem = &ItemText0[n+1]; ItemText0[n].LeftEdge = 0; ItemText0[n].TopEdge = 10 * n; ItemText0[n].Width = 80; ItemText0[n].Height = 10; ItemText0[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP; ItemText0[n].MutualExclude = 0; ItemText0[n].ItemFill = (APTR)&MenuItem0[n]; ItemText0[n].SelectFill = NULL; ItemText0[n].Command = 0; ItemText0[n].SubItem = NULL; ItemText0[n].NextSelect = 0; MenuItem0[n].FrontPen = 0; MenuItem0[n].BackPen = 1; MenuItem0[n].DrawMode = JAM2; /* render in fore and background */ MenuItem0[n].LeftEdge = 0; MenuItem0[n].TopEdge = 1; MenuItem0[n].ITextFont = NULL; MenuItem0[n].NextText = NULL; } ItemText0[MENU0MAX-1].NextItem = NULL; /* initialize text for specific menu items */ MenuItem0[0].IText = (UBYTE *)"Load"; MenuItem0[1].IText = (UBYTE *)"Save"; MenuItem0[2].IText = (UBYTE *)"About"; MenuItem0[3].IText = (UBYTE *)"Quit"; } InitMenu1() { short n; /* initialize each meu item and IntuiText with loop */ for( n=0; n<MENU1MAX; n++ ) { ItemText1[n].NextItem = &ItemText1[n+1]; ItemText1[n].LeftEdge = 0; ItemText1[n].TopEdge = 10 * n; ItemText1[n].Width = 120; ItemText1[n].Height = 10; ItemText1[n].Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP; ItemText1[n].MutualExclude = 0; ItemText1[n].ItemFill = (APTR)&MenuItem1[n]; ItemText1[n].SelectFill = NULL; ItemText1[n].Command = 0; ItemText1[n].SubItem = NULL; ItemText1[n].NextSelect = 0; MenuItem1[n].FrontPen = 0; MenuItem1[n].BackPen = 1; MenuItem1[n].DrawMode = JAM2; /* render in fore and background */ MenuItem1[n].LeftEdge = 0; MenuItem1[n].TopEdge = 1; MenuItem1[n].ITextFont = NULL; MenuItem1[n].NextText = NULL; } ItemText1[MENU1MAX-1].NextItem = NULL; /* initialize text for specific menu items */ MenuItem1[0].IText = (UBYTE *)"Zoom"; MenuItem1[1].IText = (UBYTE *)"Move"; MenuItem1[2].IText = (UBYTE *)"Command"; MenuItem1[3].IText = (UBYTE *)"Hidden Lines"; MenuItem1[4].IText = (UBYTE *)"Home"; MenuItem1[5].IText = (UBYTE *)"Quit"; MenuItem1[6].IText = (UBYTE *)"Help"; } @//E*O*F window.c// chmod u=rw,g=rw,o=r window.c exit 0