 /*  * C test routines for mfb  * sccsid "%W%  %G%"  *,  * Written by Giles Billingsley, UC Berkeley  */e      K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *r
   * arc.c    * (   * Test of MFBArc and clipping routinesL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdio.h> #include <cad/mfb.h>   main(argc,argv)_
     int argc;      char *argv[];      {e     int x,dx,y,i,j,error,n;)     MFB *mfb,*MFBOpen();     MFBPATH *paths;e     char keyTyped;     int buttonsPressed;c  '     mfb = MFBOpen(argv[1],NULL,&error);=     if(mfb == NULL) { 1         fprintf(stderr,"Can't open your MFB.\n");P( 	fprintf(stderr,"%s\n",MFBError(error));	 	exit(1); 	         }      SetCurrentMFB(mfb);f+     if(mfb->maxColors > mfb->maxLineStyles)n         j = mfb->maxColors;w     else 	j = mfb->maxLineStyles;     MFBSetLineStyle(0);e     MFBLine(250,20,250,350);     MFBLine(250,20,370,20);c     MFBLine(370,20,370,350);     MFBLine(250,350,370,350);o       n=0;H     paths = MFBClipArc(MFBArcPath(318,141,104,13,-37,9),250,20,370,350);,     while(paths[n].nvertices != 0 && n < 4){         MFBDrawPath(&paths[n]);n 	n++;t 	}     n=0;,     MFBDrawPath(MFBArcPath(0,0,200,0,0,40));>     paths = MFBClipArc(MFBArcPath(0,0,200,0,0,9),0,0,370,350);,     while(paths[n].nvertices != 0 && n < 4){         MFBDrawPath(&paths[n]);  	n++;n 	}       MFBLine(100,100,100,350);      MFBLine(100,100,370,100);     MFBLine(370,100,370,350);     MFBLine(100,350,370,350);i     n=0;E     paths = MFBClipArc(MFBArcPath(70,70,200,0,0,14),100,100,370,350); ,     while(paths[n].nvertices != 0 && n < 4){         MFBDrawPath(&paths[n]);: 	n++;  	}     MFBUpdate();     if(mfb->deviceType == TTY)         getchar();/     MFBDrawPath(MFBArcPath(200,200,100,0,0,0));l     MFBUpdate();     if(mfb->deviceType == TTY)         getchar();     MFBClose();e     }         K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *v
   * box.c    *    * Test of MFBBoxL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <cad/mfb.h>   main(argc,argv) 
 	int argc; 	char *argv[]; 	{ 	int i,j,k;a 	int error; 
 	char key; 	MFB *mfb, *MFBOpen();$ 	mfb = MFBOpen(argv[1],NULL,&error); 	if(error < 0) {) 		fprintf(stderr,"%s\n",MFBError(error)); 
 		exit(2); 		}  	SetCurrentMFB(mfb); 	for(j=0; j<7; ++j){ 		if(j)o 			MFBSetColor(j); 		else 			MFBSetColor(1); 		MFBSetFillPattern(j);  		for(i=1; i<=50; ++i){ # 			MFBBox(j*50,j*50,i+j*50,i+j*50);  			} 		}
 	MFBUpdate();u
 	sleep(6); 	MFBClose(); 	}          K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *o   * line.c h   *    * Test of MFBLine L   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "/cad/include/mfb.h"o   main(argc, argv)
 	int argc; 	char *argv[]; 	{ 	int i, j, k, m; 	int X1, X2, Y1, Y2; 	int numcolors;h 	int numlinestyles;  	int button; 	int error; 	MFB *mfb, *MFBOpen();
 	char key; 	char *TypeIn;   	/* open graphics device */ & 	mfb = MFBOpen(argv[1], NULL, &error); 	/* exit on any error */ 	if(error < 0) {3 		fprintf(stderr, "error:  %s\n", MFBError(error));s
 		exit(0); 		}    	/* get device information */e 	X1 = MFBInfo(MAXX)/2; 	X2 = X1/2;  	Y1 = MFBInfo(MAXY)/30;o  	numcolors = MFBInfo(MAXCOLORS); 	if(numcolors > 7) 	    numcolors = 7; ( 	numlinestyles = MFBInfo(MAXLINESTYLES); 	if(numlinestyles > 7) 	    numlinestyles = 7;   5 	/* draw pyramid of lines in different line styles */  	for(j=0; j<28; ++j){   A 		/* set color (increment by one to prevent 'invisible' lines) */r 		k = j % (numcolors - 1); 		MFBSetColor(k + 1);t  ! 		/* define and set line style */e 		m = j % numlinestyles;   		MFBDefineLineStyle(m, j * 6);A 		if(m & 1)o 		    MFBSetLineStyle(m);  		else 		    MFBSetLineStyle(0);1   		/* draw pyramid */ 		MFBLine(0, 0, X2, Y1*j+2*j); 		MFBLine(X1, 0, X2, Y1*j+2*j);  		}r   	/* flush output and wait */
 	MFBUpdate(); 
 	sleep(6);   	MFBClose(); 	}          bK  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *e   * logo.c     * +   * Test of MFBDefineColor and VLT routines L   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*2  * LOGO display as an example of use of FB package  * G.Billingsley  */    #include <cad/mfb.h>   struct color {
     int R;
     int G;
     int B;$     } colormap [] = {	255,  0,    0, 			180,  180,  0,  			0,    255,  0,e 			0,    180,  180,t 			0,    0,    255,  			180,  0,    180,  			220,  200,  180,  			0,    0,    0 			};    MFB mfb;   main(argc,argv) 
     int argc;      char *argv[];      {;     int count;     int error;!     MFBOpen(argv[1],NULL,&error);;     Init();p       /* Create the logo */(*     MFBSetFillPattern(0);	/* solid fill */
     SetMap();	     SetPattern();t  O     /* Set and rotate colors ad nauseum (but trap "escape" and exit cleanly) */B,     for (count = 0;count < 10000; ++count) {         RedoMap();	         }*       MFBClose();5     }	   Init() {     srand(time(0));6     }B   DisplayOff() {     int pixel;&     for (pixel=0; pixel<=7; pixel++) {$         MFBDefineColor(pixel,0,0,0);	         }      }o  
 SetMap() {     int pixel;&     for (pixel=0; pixel<=7; pixel++) {A         MFBDefineColor(pixel,colormap[pixel].R,colormap[pixel].G,g 	    colormap[pixel].B);	         }i     },   RedoMap() {,
    int pixel;i    double nrand();&    for ( pixel=0; pixel<=7; pixel++) {)        colormap[pixel].R = 255.0*nrand();c)        colormap[pixel].G = 255.0*nrand(); )        colormap[pixel].B = 255.0*nrand();/        }    SetMap();    }   SetPattern() {     double nrand();%     /*B     Put a random number of random sized blocks on pixel planes 0-7     */1     int locx, locy, xlen, ylen, pixel, maxblocks;/     int xmax, ymax;B     int nblocks;     double maxlen;     char mode;&     for (pixel=0; pixel<=7; pixel++) {%         maxblocks = 300.0*nrand()+10;m:         maxlen        = 0.1*(512.0/(sqrt(maxblocks)+1.0));8         for (nblocks=0; nblocks<=maxblocks; nblocks++) {!             locx = 512.0*nrand();b!             locy = 512.0*nrand();s)             xlen = maxlen*nrand() + 10.0;n)             ylen = maxlen*nrand() + 10.0;s.             if ( locx+xlen > 500 ) xmax = 500;"             else xmax = locx+xlen;.             if ( locy+ylen > 500 ) ymax = 500;"             else ymax = locy+ylen;*             if ( nrand()<0.7 ) mode = 'f';             else mode = 'o';             MFBSetColor(pixel);;+             MFBBox(locx, locy, xmax, ymax); 
             } 	         }      }    double nrand() {     float scale=2147483647.0;      return rand()/scale;     }r          K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *    * point.c    *    * Test of MFBPointL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <cad/mfb.h>   main(argc,argv) 
 	int argc; 	char *argv[]; 	{ 	int i,j,k,X1,X2,Y1,Y2,but;  	int error;	 	char key,buffer[80];  	MFB *mfb, *MFBOpen();$ 	mfb = MFBOpen(argv[1],NULL,&error); 	if(error < 0) {' 		fprintf(stderr,"error = %d\n",error);  		sleep(2);r 		}' 	SetCurrentMFB(mfb); 	for(j=0; j<21; ++j){" 		k = j % 7; 		MFBSetColor(1);  		MFBDefineLineStyle(k, j * 6);f 		MFBSetLineStyle(k);  		MFBPoint(&X1,&Y1,&key,&but); 		MFBSetColor(0);w
 		MFBFlood();= 		MFBSetColor(1);;) 		sprintf(buffer,"point = %d, %d",X1,Y1);, 		MFBText(buffer,100,100,0); 		MFBPoint(&X2,&Y2,&key,&but); 		MFBSetColor(0);L
 		MFBFlood();, 		MFBSetColor(1);  		MFBLine(X1,Y1,X2,Y2);B) 		sprintf(buffer,"point = %d, %d",X2,Y2);0 		MFBText(buffer,100,100,0); 		} 
 	MFBUpdate(); 
 	sleep(6); 	MFBClose(); 	}            K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *A   * polygon.c    *,,   * Test of MFBPolygon and clipping routinesL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <cad/mfb.h>   main(arg, argv)0	 	int arg; 	char *argv[]; 	{ 	int i,j,k;  	int xy[20];
 	int xy1[20];i 	int error;  	MFBPOLYGON poly,poly1;r 	MFB *mfb, *MFBOpen(); 	poly.xy = xy; 	poly1.xy = xy1;& 	poly.nvertices = poly1.nvertices = 4;
 	xy[0] = 200;t
 	xy[1] = 200; 
 	xy[2] = 300;d
 	xy[3] = 200;m
 	xy[4] = 350;=
 	xy[5] = 300; 
 	xy[6] = 250; 
 	xy[7] = 300;A$ 	mfb = MFBOpen(argv[1],NULL,&error); 	if(error < 0) {' 		fprintf(stderr,"error = %d\n",error);; 		sleep(2);e 		}  	SetCurrentMFB(mfb); 	for(j=0; j<24; ++j){  		k = j % 7; 		MFBSetColor(k);  		MFBSetFillPattern(k);  		MFBPolygon(&poly); 		MFBUpdate();' 		for(i=0; i < 2 * poly.nvertices; ++i)  			poly1.xy[i] = poly.xy[i];' 		poly.nvertices = poly1.nvertices = 4;h) 		MFBPolygonClip(&poly1,390,250,220,250);n 		MFBSetColor(1);e 		MFBPolygon(&poly1);; 		MFBUpdate();' 		for(i=0; i < 2 * poly.nvertices; ++i)i 			poly1.xy[i] = poly.xy[i];' 		poly.nvertices = poly1.nvertices = 4; ) 		MFBPolygonClip(&poly1,390,250,260,345);t 		MFBSetColor(2);i 		MFBPolygon(&poly1);  		MFBUpdate();' 		for(i=0; i < 2 * poly.nvertices; ++i)  			poly1.xy[i] = poly.xy[i];' 		poly.nvertices = poly1.nvertices = 4; ) 		MFBPolygonClip(&poly1,240,150,210,250);c 		MFBSetColor(3);  		MFBPolygon(&poly1);; 		MFBUpdate();' 		for(i=0; i < 2 * poly.nvertices; ++i)  			poly1.xy[i] = poly.xy[i];' 		poly.nvertices = poly1.nvertices = 4; ) 		MFBPolygonClip(&poly1,240,150,260,310);  		MFBSetColor(4);  		MFBPolygon(&poly1);  		MFBFlash(440,240,35,5);n 		MFBUpdate(); 		}g
 	MFBUpdate();[
 	sleep(5); 	MFBClose(); 	}          K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *g
   * raster.c r   *i"   * Test of MFB raster op routinesL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "/cad/include/mfb.h"t   main(argc,argv)f
 	int argc; 	char *argv[]; 	{ 	int i,j,k;) 	int error;t 	char buffer[80];; 	MFB *mfb, *MFBOpen();$ 	mfb = MFBOpen(argv[1],NULL,&error);4 	sprintf(buffer,"font height = %d",mfb->fontHeight); 	MFBText(buffer,200,50); 	if(error < 0) {' 		fprintf(stderr,"error = %d\n",error);	 		sleep(2);) 		}	 	SetCurrentMFB(mfb); 	for(j=0; j<21; ++j){n 		k = j % 7; 		MFBSetColor(k+1);f 		MFBDefineLineStyle(k, j * 6);) 		MFBSetLineStyle(k);s 		MFBLine(0,0,200,50*k+2*j); 		MFBLine(400,0,200,50*k+2*j);) 		MFBText("this is a test",200,50*k+2*j);o 		}. 	 
 	MFBUpdate();o 	MFBGetchar(); 	MFBSetALUMode(MFBALUJAM);& 	MFBRasterCopy(50,50,200,250,150,120);
 	MFBUpdate();  	MFBGetchar(); 	MFBSetALUMode(MFBALUOR);a& 	MFBRasterCopy(50,50,200,250,180,150);
 	MFBUpdate();  	MFBGetchar(); 	MFBSetALUMode(MFBALUEOR);& 	MFBRasterCopy(50,50,200,250,210,170);
 	MFBUpdate();l 	MFBGetchar(); 	MFBSetALUMode(MFBALUNOR);& 	MFBRasterCopy(50,50,200,250,240,200);
 	MFBUpdate();  	MFBGetchar(); 	MFBClose(); 	}          K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *N   * text.c     *r   * Test of MFBText and MFBMoreoL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "/cad/include/mfb.h"o   main(argc,argv)i
 	int argc; 	char *argv[]; 	{ 	int i,j,k;d 	int error;( 	char buffer[80];v 	MFB *mfb, *MFBOpen();$ 	mfb = MFBOpen(argv[1],NULL,&error);4 	sprintf(buffer,"font height = %d",mfb->fontHeight); 	MFBText(buffer,200,50,0); 	if(error < 0) {' 		fprintf(stderr,"error = %d\n",error);i 		sleep(2);v 		}e 	SetCurrentMFB(mfb); 	for(j=0; j<21; ++j){y 		k = j % 7; 		MFBSetColor(k+1);  		MFBDefineLineStyle(k, j * 6);6 		MFBSetLineStyle(k);( 		MFBLine(0,0,200,50*k+2*j); 		MFBLine(400,0,200,50*k+2*j);
 		MFBAudio();e+ 		MFBText("this is a test",200,50*k+2*j,0);	 		}n
 	MFBUpdate();n: 	MFBMore(100,100,400,300,popen("cat /cad/lib/mfb.a","r"));
 	sleep(2);9 	MFBScroll(100,100,400,300,fopen("/cad/lib/mfbcap","r"));;A 	MFBText("this is a test ABCDEFGHIJKLMNOPQRSTUVWXYZ",200,200,20);0B 	MFBText("this is a test ABCDEFGHIJKLMNOPQRSTUVWXYZ",200,200,110);B 	MFBText("this is a test ABCDEFGHIJKLMNOPQRSTUVWXYZ",200,200,210);B 	MFBText("this is a test ABCDEFGHIJKLMNOPQRSTUVWXYZ",200,200,290);@ 	MFBText("this is a test ABCDEFGHIJKLMNOPQRSTUVWXYZ",200,200,0);
 	MFBUpdate();r
 	sleep(8); 	MFBClose(); 	}          K  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *n   * xform.c    *a+   * Test of MFBSetWindow and MFBSetViewportnL   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "/cad/include/mfb.h"x   main(argc, argv)
 	int argc; 	char *argv[]; 	{ 	int i, j, k, m; 	int X1, X2, Y1, Y2; 	int numcolors;  	int numlinestyles;r 	int button; 	int error;  	MFB *mfb, *MFBOpen();
 	char key; 	char *TypeIn;   	/* open graphics device */c) 	mfb = MFBOpen(argv[1], argv[2], &error);n 	/* exit on any error */ 	if(error < 0) {3 		fprintf(stderr, "error:  %s\n", MFBError(error)); 
 		exit(0); 		}*   	/* get device information */( 	X1 = MFBInfo(MAXX); 	Y1 = MFBInfo(MAXY);  	numcolors = MFBInfo(MAXCOLORS);( 	numlinestyles = MFBInfo(MAXLINESTYLES); 	if(numcolors > 7) 		numcolors = 7; 	if(numlinestyles > 7) 		numlinestyles = 7; 	/* set window and viewport */5 	MFBSetViewport( X1/4 , Y1/4 , (X1/4)*3 , (Y1/4)*3 );	) 	MFBSetWindow(-15000,-15000,15000,15000);F  5 	/* draw pyramid of lines in different line styles */  	for(j=0; j<28; ++j){;  A 		/* set color (increment by one to prevent 'invisible' lines) */x 		k = j % (numcolors - 1); 		MFBSetColor(k + 1);c  ! 		/* define and set line style */, 		m = j % numlinestyles;   		MFBDefineLineStyle(m, j * 6);	 		if(m & 1)2 			MFBSetLineStyle(m); 		else 			MFBSetLineStyle(0);   		/* draw pyramid */) 		MFBLine(MFBScaleX(-15000),MFBScaleY(0),[" 			MFBScaleX(15000),MFBScaleY(0));( 		MFBLine(MFBScaleX(0),MFBScaleY(15000),# 			MFBScaleX(0),MFBScaleY(-15000));;% 		MFBLine(MFBScaleX(0), MFBScaleY(0),b' 			MFBScaleX(5000), MFBScaleY(j*200) );;) 		MFBLine(MFBScaleX(10000), MFBScaleY(0), ' 			MFBScaleX(5000), MFBScaleY(j*200) );t 		}n   	/* flush output and wait */
 	MFBUpdate();;
 	sleep(6);   	MFBClose(); 	}  