예제 #1
0
파일: r4tosgi.c 프로젝트: hollasch/ray4
void  InitSGI  ()
{
   ginit ();		/* Initialize the display. */
   ginit_done = true;

   cursoff ();

   RGBmode ();		/* Select RGB mode (24-bit color). */
   gconfig ();
   RGBcolor (0, 0, 0);
   clear ();

   qdevice (KEYBD);
}
예제 #2
0
/**************************** BUTTONS ********************************/
gl_button *create_gl_button(double x, double y, double width, double height,
			    int fg, int bg, int active_c, int *state, int type,
			    char *label, void (*callback)(gl_button *, int)) {
    gl_button *newbutton;

    if ((newbutton = (gl_button *)malloc(sizeof(gl_button))) == NULL) 
      return(NULL);
    
    if (firstbutton == NULL) {
	/* initialization */
	check_vers();
	qdevice(LEFTMOUSE);
	tie(LEFTMOUSE, MOUSEX, MOUSEY);
	firstbutton = actbutton = newbutton;
    } 
	
    actbutton->nextp = newbutton;
    actbutton = newbutton;
    
    actbutton->nextp    = NULL;
    actbutton->win      = winget();
    actbutton->x        = x;
    actbutton->y        = y;
    actbutton->width    = width;
    actbutton->height   = height;
    actbutton->fg       = fg;
    actbutton->bg       = bg;
    actbutton->active_c = active_c;
    actbutton->type     = type;
    actbutton->changed     = FALSE;

    if (state != NULL)  actbutton->state = state;
    else {
	if ((actbutton->state = (int *)malloc(sizeof(int))) == NULL) return(NULL);
	*(actbutton->state) = 0;
    }
	
    if (label != NULL) {
	if ((actbutton->label = (char *)malloc(strlen(label) + 2)) != NULL) {
	    *(actbutton->label) = ' ';
	    strcpy(actbutton->label + 1, label);
	}
    } else actbutton->label = NULL;
    actbutton->callback = callback;

    drawbutton(actbutton);
    
    return(actbutton);
}
예제 #3
0
/*
 * display all the hershey fonts and demonstrate textang
 */
main()
{
	char	buf[50];
	char	*str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
	char	*str2 = "abcdefghijklmnopqrstuvwxyz" ;
	char	*str3 = "1234567890+-=!@#$%^&*(){}[]" ;
	char	*str4 = "<>,./?~`\\|_BONK,blark" ;
	int	i;
	short	val;

	vinit("mswin");
	winopen("circtxt");

	hleftjustify(1);

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);
	clear();

	ortho2(-14.0, 14.0, -14.0, 14.0);	/* define the world space */

	for(i = 0; i < 22; i++) {

		/*
		 * textang is used to specify the orientation of text. As
		 * we want the title to come out straight we make sure it is
		 * zero each time we go through this loop.
		 */
		htextang(0.0);

		/*
		 * do the title
		 */
		color(YELLOW);
		hfont("futura.m");
		sprintf(buf, "This is hershey font %s", fonts[i]);
		hboxtext(-11.0, 12.0, 20.0, 1.0, buf);

		/*
		 * draw a box around the title
		 */
		rect(-11.0, 12.0, 9.0, 13.0);

		color(GREEN);

		hfont(fonts[i]);		/* grab a font from the table */

		htextsize(1.5, 1.5);		/* show the outer ring */
		ShowCircularText(11.0, str1);

		htextsize(1.3, 1.3);		/* show the second ring */
		ShowCircularText(8.5, str2);

		htextsize(1.1, 1.1);		/* show the third ring */
		ShowCircularText(7.0, str3);

		htextsize(0.9, 0.9);		/* show the inside ring */
		ShowCircularText(5.0, str4);

		if (qread(&val)) {
			if (val == 'q') {
				gexit();
				exit(0);
			}
		}

		color(BLACK);
		clear();
	}

	gexit();
}
예제 #4
0
void main()
{
	short val;
	int menu, pres;
	float p, mx, my;

	curmass = 0.5;
	curdrag = 0.15;
	prefsize(800,640);
	initbuzz();
	winopen("dynadraw");
	glcompat(GLC_OLDPOLYGON,1);
	subpixel(1);
	shademodel(FLAT);
	gconfig();
	qdevice(LEFTMOUSE);
	qdevice(MIDDLEMOUSE);
	qdevice(MENUBUTTON);
	qdevice(RIGHTSHIFTKEY); 
	qdevice(UPARROWKEY); 
	qdevice(DOWNARROWKEY); 
	qdevice(RIGHTSHIFTKEY); 
	makeframe();
	menu = defpup("dynadraw %t|toggle line style|save PostScript");
	width = initwidth;
	mouse.fixedangle = 1;
	while(1) {
		switch(qread(&val)) {
		case REDRAW:
			makeframe();
			break;
		case MIDDLEMOUSE:
			if(val) 
				clearscreen();
			break;
		case UPARROWKEY:
			if(val) 
				initwidth *= 1.414213;
			width = initwidth;
			break;
		case DOWNARROWKEY:
			if(val) 
				initwidth /= 1.414213;
			width = initwidth;
			break;
		case MENUBUTTON:
			if(val) {
				switch(dopup(menu)) {
				case 1: 
					mouse.fixedangle = 1-mouse.fixedangle;
					break;
				case 2: 
					savepolys();
					break;
				}
			}
			break;
		case LEFTMOUSE:
			if(val) {
				my = getmousey();
				if(my>0*SLIDERHIGH && my<2*SLIDERHIGH) {
					if(my>SLIDERHIGH) {
						while(getbutton(LEFTMOUSE)) {
							p = paramval();
							if(p != curmass) {
								curmass = p;
								showsettings();
							}
						}
					} else {
						while(getbutton(LEFTMOUSE)) {
							p = paramval();
							if(p != curdrag) {
								curdrag = p;
								showsettings();
							}
						}
					}
				} else {
					mx = 1.25*fgetmousex();
					my = fgetmousey();
					filtersetpos(&mouse,mx,my);
					odelx = 0.0;
					odely = 0.0;
					while(getbutton(LEFTMOUSE)) {
						mx = 1.25*fgetmousex();
						my = fgetmousey();
						if(filterapply(&mouse,mx,my)) {
							drawsegment(&mouse);
							color(0);
							buzz();
						}
					}
				}
			}
			break;
		}
	}
}
예제 #5
0
/*
 * using curves
 */
main()
{
	char	dev[20];
	int	i;
	short	val;

	vinit("mswin");
	winopen("curves");

	qdevice(KEYBD);
	unqdevice(INPUTCHANGE);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	ortho2(-200.0, 400.0, -100.0, 500.0);

	color(BLACK);
	clear();

	color(YELLOW);

	/*
	 * label the control points in geom1
	 */
        for (i = 0; i < 4; i++) {
		cmov2(geom1[i][0], geom1[i][1]);
		sprintf(dev, "%d", i);
		charstr(dev);
	}
								 
	/*
	 * label the control points in geom2
	 */
	for (i = 0; i < 6; i++) {
		cmov2(geom2[i][0], geom2[i][1]);
		sprintf(dev, "%d", i);
		charstr(dev);
	}

	/*
	 * set the number of line segments appearing in each curve to 20
	 */
	curveprecision((short)20);

	/*
	 * copy the bezier basis matrix into the basis matrix stack and
	 * set the curve basis accordingly.
	 */
	defbasis((short)1, bezier);
	curvebasis((short)1);

	color(RED);

	/*
	 * draw a curve using the current basis matrix (bezier in this case)
	 * and the control points in geom1
	 */
	crv(geom1);

	cmov2(70.0, 60.0);
	charstr("Bezier Curve Segment");

	cmov2(-190.0, 450.0);
	charstr("Three overlapping Bezier Curves");

	/*
	 * crvn draws overlapping curve segments according to geom2, the
	 * number of curve segments drawn is three less than the number of
	 * points passed, assuming there are a least four points in the
	 * geometry matrix (in this case geom2). This call will draw 3
	 * overlapping curve segments in the current basis matrix - still
	 * bezier.
	 */
	crvn(6L, geom2);

	qread(&val);

	/*
	 * load in the cardinal basis matrix
	 */
	defbasis((short)1, cardinal);
	curvebasis((short)1);

	color(MAGENTA);

	cmov2(70.0, 10.0);
	charstr("Cardinal Curve Segment");

	/*
	 * plot out a curve segment using the cardinal basis matrix
	 */
	crv(geom1);

	cmov2(-190.0, 400.0);
	charstr("Three overlapping Cardinal Curves");

	/*
	 * now draw a bunch of them again.
	 */
	crvn(6L, geom2);

	qread(&val);

	/*
	 * change the basis matrix again
	 */
	defbasis((short)1, bspline);
	curvebasis((short)1);

	color(GREEN);

	cmov2(70.0, -40.0);
	charstr("Bspline Curve Segment");

	/*
	 * now draw our curve segment in the new basis...
	 */
	crv(geom1);

	cmov2(-190.0, 350.0);
	charstr("Three overlapping Bspline Curves");

	/*
	 * ...and do some overlapping ones
	 */
	crvn(6L, geom2);

	qread(&val);

	gexit();
}
예제 #6
0
main()
{
        char    *p;
	float	tdir = TRANS;
	float	scal = 1.0 + SCAL;
	int	but, nplanes;
	int	x, y, i, n;
	short	val;
	int	bf = 1;
	int	fill = 1;

	prefsize(500L, 500L);

	vinit("mswin");
	winopen("lcube");

	unqdevice(INPUTCHANGE);
	qdevice(SKEY);
	qdevice(XKEY);
	qdevice(YKEY);
	qdevice(ZKEY);
	qdevice(EQUALKEY);
	qdevice(MINUSKEY);
	qdevice(ESCKEY);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;
	

	window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
	lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);

	if ((nplanes = getplanes()) == 1)
		makecubes(0);

	makecubes(1);

	backface(1);
		
	doublebuffer();
	gconfig();

	/*
	 * Doublebuffer does a backbuffer(TRUE)....
	 */

	while(1) {
		x = 500 - (int)getvaluator(MOUSEX);
		y = 500 - (int)getvaluator(MOUSEY);
		x *= 3;
		y *= 3;
		pushmatrix();
			rotate(x, 'y');
			rotate(y, 'x');
			color(BLACK);
			clear();
			callobj((Object)3);
			if (nplanes == 1)
				callobj((Object)2);
		popmatrix();
		swapbuffers();

		if (qtest()) {
			but = qread(&val);
			but = qread(&val);	/* swallow up event */

			switch (but) {

			case SKEY:
				scale(scal, scal, scal);
				break;
			case XKEY:
				translate(tdir, 0.0, 0.0);
				break;
			case YKEY:
				translate(0.0, tdir, 0.0);
				break;
			case ZKEY:
				translate(0.0, 0.0, tdir);
				break;
			case MINUSKEY:
				tdir = -tdir;

				if (scal < 1.0)
					scal = 1.0 + SCAL;
				else
					scal = 1.0 - SCAL;

				break;
			case EQUALKEY:
				tdir = TRANS;
				break;
			case BKEY:
				bf = !bf;
				backface(bf);
				break;
			case FKEY:
				fill = !fill;
				if (fill)
					polymode(PYM_FILL);
				else
					polymode(PYM_LINE);
				break;
			case ESCKEY:
			case QKEY:
				gexit();
				exit(0);
			default:
				;
			}
		}
	}
}
예제 #7
0
main()
{
	int	i, itest,  dobackface, dofill, dodouble;
	char	buf[100];
	float	H;
	short	idata;
	int	xr, yr;

	vinit("mswin");
	winopen("piston");
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&idata) != REDRAW)
		;

	doublebuffer();

	gconfig();

	unqdevice(INPUTCHANGE);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	qdevice(ESCKEY);
        qdevice(REDRAW);

	makecyl();

	polymode(PYM_FILL);

	backface(1);
/*
 * set up a perspective projection with a field of view of
 * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
 * and the far clipping plane at 1000.0.
 */
	perspective(400, 1.5, 0.1, 600.0);
	lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0);

/*
 * here we loop back here adnaseum until someone hits a key
 */
	xr = yr = 0;

 	while(1) {
		for (i = 0; i < 360; i += 5) {
			color(BLACK);
			clear();
			color(RED);
			H = 1.0 + cos(2.0 * 3.14159265*i / 180.0);

			yr = 500 - (int)getvaluator(MOUSEY);
			xr = 500 - (int)getvaluator(MOUSEX);
			yr = 500 - (int)getvaluator(MOUSEY);
			xr *= 3;
			yr *= 3;

			pushmatrix();
				rotate(xr, 'x');
				rotate(yr, 'y');
				piston(H);
			popmatrix();

			if (dodouble)
				swapbuffers();

			if (qtest()) {
				itest = qread(&idata);
				itest = qread(&idata); /* Zap Up event */
				if (itest == BKEY) {
					dobackface = !dobackface;
					backface(dobackface);
				} else if (itest == FKEY) {
					dofill = !dofill;
					if (dofill)
						polymode(PYM_FILL);
					else
						polymode(PYM_LINE);
				} else if(itest == QKEY || itest == ESCKEY) {
					 gexit();
					 exit(0);
				}

			}
		}
	}
}
예제 #8
0
파일: matplot.c 프로젝트: B-Rich/tcoffee
/* init_matplot: initialises distmat plotting. The matrix size should
 * be Row x Col (which is the min. size in pixels). Title is put on the top
 * of the window by the window manager. Xorig and Yorig specify
 * the lower left corner position of the window: if either of them
 * is negative, then the window will be positioned interactively.
 * Return value: the 'gid' window ID number.
 */
long init_matplot(unsigned int Row, unsigned int Col, char *Title, 
	long Xorig, long Yorig)
{
    const unsigned int MINSIZE=500;
    
    long Gid, Xsize, Ysize, Xmax, Ymax;
    float Xmagnif, Ymagnif;
    unsigned int Rs, Cs;
    
    if (!Row) Row=MINSIZE;
    if (!Col) Col=MINSIZE;
    
    Xmagnif=(float)Col/MINSIZE;
    Ymagnif=(float)Row/MINSIZE;
    Rs=Row; Cs=Col;
    if (Col<=Row)
    {
	if (Xmagnif<1.0)
	{
	    Cs=MINSIZE;
	    Rs=round_id(Row/Xmagnif);
	}
    }
    else
    {
	if (Ymagnif<1.0)
	{
	    Rs=MINSIZE;
	    Cs=round_id(Col/Ymagnif);
	}
    }
    
    foreground();	/* enable signal catch etc. */
    Xmax=getgdesc(GD_XPMAX); Ymax=getgdesc(GD_YPMAX);
    keepaspect(Col, Row);

    /* Xmax,Ymax: the maximal screen coordinates */
    Xmax=getgdesc(GD_XPMAX); Ymax=getgdesc(GD_YPMAX);
    if (Xorig+Cs>Xmax) Xorig=Xmax-Cs;
    if (Yorig+Rs>Ymax) Yorig=Ymax-Rs;
    if (Xorig>=0 && Yorig>=0)
	prefposition(Xorig, Xorig+Cs, Yorig, Yorig+Rs);
    iconsize(84, 67);
    Gid=winopen(Title);	/* create window */
    
    RGBmode();
    /* check if double buffering is available */
    if (Dblbuffer=getgdesc(GD_BITS_NORM_DBL_BLUE))
    { doublebuffer(); gconfig(); }
    else fputs("init_matplot: single-buffer mode\n", stderr);

    /* enable resize */
    winconstraints();
    keepaspect(Col, Row);
    winconstraints();
    
    getsize(&Xsize, &Ysize);    /* scale drawing into window */
    Xmagnif=(float)Xsize/Col;
    Ymagnif=(float)Ysize/Row;
    pushmatrix();
    scale(Xmagnif, Ymagnif, 1.0);
    cpack(RGB_BLACK); clear();          /* clears window to black */
    if (Dblbuffer) { swapbuffers(); cpack(RGB_BLACK); clear(); }
    
    /* queue input events */
    qdevice(ESCKEY); qdevice(WINFREEZE); qdevice(WINTHAW);
    qdevice(REDRAWICONIC); qdevice(WINQUIT);
    
    return(Gid);
}
예제 #9
0
파일: loc.c 프로젝트: Milkyway-at-home/nemo
/*
 * a routine to demonstrate using locator.
 */
main()
{
	int		i, bt, act, nchars;
	short		data;
	Scoord		x, y, sx, sy;
	Screencoord	minx, maxx, miny, maxy;

	ginit();

	color(BLACK);
	clear();

	color(BLUE);

	getviewport(&minx, &maxx, &miny, &maxy);

	ortho2((Coord)minx, (Coord)maxx, (Coord)miny, (Coord)maxy);

	/*
	 * draw some axes
	 */
	move2s((Scoord)minx, (Scoord)((maxy - miny) / 2));
	draw2s((Scoord)maxx, (Scoord)((maxy - miny) / 2));

	move2s((Scoord)((maxx - minx) / 2), (Scoord)miny);
	draw2s((Scoord)((maxx - minx) / 2), (Scoord)maxy);

	color(GREEN);

	/*
	 * enable the left and middle mouse buttons
	 */
	unqdevice(INPUTCHANGE);
	qdevice(LEFTMOUSE);
	qdevice(MIDDLEMOUSE);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&data) != REDRAW)
		;

	act = 0;

	/*
	 * getvaluator tells us the valuator's value. In
	 * this case it's the X and Y positions of the mouse.
	 * Note: these come back to us in screen coordinates.
	 */
	while((bt = qread(&data)) != MIDDLEMOUSE) {
		sx = getvaluator(MOUSEX);
		sy = getvaluator(MOUSEY);
		if (bt == -1) {
			gexit();
			printf("No locator device found\n");
			exit(0);
		} else {
			if (act) {
				act = 0;
				move2s(sx, sy);
				draw2s(x, y);
			} else {
				act = 1;
				x = sx;
				y = sy;
			}
		}
		(void)qread(&data);	/* swallow the up event */
	}

	gexit();

}
예제 #10
0
main()
{
    float ship[XY];
    long org[XY];
    long size[XY];
    Device dev;
    short val;
    Device mdev[XY];
    short mval[XY];
    long nhits;
    short buffer[BUFSIZE];
    Boolean run;

    prefsize(400, 400);
    winopen("select1");
    getorigin(&org[X], &org[Y]);
    getsize(&size[X], &size[Y]);
    mmode(MVIEWING);
    ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);
    qdevice(LEFTMOUSE);
    qdevice(ESCKEY);
    color(BLACK);
    clear();
    mdev[X] = MOUSEX;
    mdev[Y] = MOUSEY;

    drawplanet();
    run = TRUE;
    while (run) {
	dev = qread(&val);
	if (val == 0) {				/* on upstroke */
	    switch (dev) {
	    case LEFTMOUSE:
		getdev(XY, mdev, mval);
		ship[X] = mval[X] - org[X];
		ship[Y] = mval[Y] - org[Y];
		color(BLUE);
		sbox(ship[X], ship[Y], 
		     ship[X] + SHIPWIDTH, ship[Y] + SHIPHEIGHT);

		/*
		 * specify the selecting region to be a box surrounding the
		 * rocket ship 
		 */
		ortho2(ship[X], ship[X] + SHIPWIDTH, 
		       ship[Y], ship[Y] + SHIPHEIGHT);

		initnames();
		gselect(buffer, BUFSIZE);
		    loadname(PLANET);
		    /* no actual drawing takes place */
		    drawplanet();
		nhits = endselect(buffer);

		/*
		 * restore the Projection matrix; NB. can't use push/popmatrix 
		 * since they only work for the ModelView matrix stack 
		 * when in MVIEWING mode
		 */
		ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);

		/* 
		 * check to see if PLANET was selected; NB. nhits is NOT the
		 * number of buffer elements written
		 */
		if (nhits < 0) {
		    fprintf(stderr, "gselect buffer overflow\n");
		    run = FALSE;
		} 
		else if (nhits >= 1 && buffer[0] == 1 && buffer[1] == PLANET)
		    ringbell();
		break;
	    case ESCKEY:
		run = FALSE;
		break;
	    }
	}
    }
    gexit();
    return 0;
}
예제 #11
0
/*
 * Using polygons, hatching, and filling.
 */
main()
{
	short	val;

	winopen("poly");

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);		/* enable keyboard */
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);		/* clear to black */
	clear();

	/*
	 * world coordinates are now in the range -10 to 10
	 * in x, y, and z. Note that positive z is towards us.
	 */
	ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);

	color(YELLOW);

	/*
	 * write out the string "Polygon from poly()" in the
	 * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
	 * 0.5 units high.
	 */
	hfont("futura.m");
	hboxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()/ polf()");

	color(GREEN);

	/*
	 * write out a scaled string starting at (0.0, 6.0)
	 */
	hboxtext(0.0, 6.0, 4.5, 0.5, "Polygon from bgnpoly()/ endpoly()");
	hboxtext(0.0, 5.0, 4.5, 0.5, "             pmv()/ pdr()/ pclos()");

	color(MAGENTA);

	/*
	 * write out a scaled string starting at (0.0, 6.0)
	 */
	hboxtext(3.5, -3.5, 1.9, 0.5, "Arc/ Arcf");

	/*
	 * draw some wire frame polygons
	 */
	drawpoly();

	/*
	 *  rotate so the next polygons will appear in a different place.
	 */
	rot(20.0, 'x');
	rot(30.0, 'y');

	/*
	 * draw some filled polygons.
	 */
	drawpolyf();

	gexit();
}