Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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