1 #ifndef lint
2 static char sccsid[] = "@(#)boxgen.c	3.1 (CWI) 85/07/30";
3 #endif lint
4 
5 #include	<stdio.h>
6 #include	"pic.h"
7 #include	"y.tab.h"
8 
9 obj *boxgen(type)
10 {
11 	static float prevh = HT;
12 	static float prevw = WID;	/* golden mean, sort of */
13 	int i, invis, at, ddtype, with;
14 	float ddval, xwith, ywith;
15 	float h, w, x0, y0, x1, y1;
16 	obj *p, *ppos;
17 	Attr *ap;
18 
19 	h = getfval("boxht");
20 	w = getfval("boxwid");
21 	invis = at = 0;
22 	with = xwith = ywith = 0;
23 	ddtype = ddval = 0;
24 	for (i = 0; i < nattr; i++) {
25 		ap = &attr[i];
26 		switch (ap->a_type) {
27 		case HEIGHT:
28 			h = ap->a_val.f;
29 			break;
30 		case WIDTH:
31 			w = ap->a_val.f;
32 			break;
33 		case SAME:
34 			h = prevh;
35 			w = prevw;
36 			break;
37 		case WITH:
38 			with = ap->a_val.i;	/* corner */
39 			break;
40 		case AT:
41 			ppos = ap->a_val.o;
42 			curx = ppos->o_x;
43 			cury = ppos->o_y;
44 			at++;
45 			break;
46 		case INVIS:
47 			invis = INVIS;
48 			break;
49 		case DOT:
50 		case DASH:
51 			ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT;
52 			if (ap->a_sub == DEFAULT)
53 				ddval = getfval("dashwid");
54 			else
55 				ddval = ap->a_val.f;
56 			break;
57 		case TEXTATTR:
58 			savetext(ap->a_sub, ap->a_val.p);
59 			break;
60 		}
61 	}
62 	if (with) {
63 		switch (with) {
64 		case NORTH:	ywith = -h / 2; break;
65 		case SOUTH:	ywith = h / 2; break;
66 		case EAST:	xwith = -w / 2; break;
67 		case WEST:	xwith = w / 2; break;
68 		case NE:	xwith = -w / 2; ywith = -h / 2; break;
69 		case SE:	xwith = -w / 2; ywith = h / 2; break;
70 		case NW:	xwith = w / 2; ywith = -h / 2; break;
71 		case SW:	xwith = w / 2; ywith = h / 2; break;
72 		}
73 		curx += xwith;
74 		cury += ywith;
75 	}
76 	if (!at) {
77 		if (isright(hvmode))
78 			curx += w / 2;
79 		else if (isleft(hvmode))
80 			curx -= w / 2;
81 		else if (isup(hvmode))
82 			cury += h / 2;
83 		else
84 			cury -= h / 2;
85 	}
86 	x0 = curx - w / 2;
87 	y0 = cury - h / 2;
88 	x1 = curx + w / 2;
89 	y1 = cury + h / 2;
90 	extreme(x0, y0);
91 	extreme(x1, y1);
92 	p = makenode(BOX, 2);
93 	p->o_val[0] = w;
94 	p->o_val[1] = h;
95 	p->o_ddval = ddval;
96 	p->o_attr = invis | ddtype;
97 	dprintf("B %g %g %g %g at %g %g, h=%g, w=%g\n", x0, y0, x1, y1, curx, cury, h, w);
98 	if (isright(hvmode))
99 		curx = x1;
100 	else if (isleft(hvmode))
101 		curx = x0;
102 	else if (isup(hvmode))
103 		cury = y1;
104 	else
105 		cury = y0;
106 	prevh = h;
107 	prevw = w;
108 	return(p);
109 }
110