Commit | Line | Data |
---|---|---|
0e630f4c | 1 | #ifndef lint |
e1edd7cd | 2 | static char sccsid[] = "@(#)boxgen.c 3.1 (CWI) 85/07/30"; |
0e630f4c | 3 | #endif lint |
e1edd7cd | 4 | |
0e630f4c JA |
5 | #include <stdio.h> |
6 | #include "pic.h" | |
7 | #include "y.tab.h" | |
8 | ||
ff32afa0 | 9 | obj *boxgen(type) |
0e630f4c JA |
10 | { |
11 | static float prevh = HT; | |
12 | static float prevw = WID; /* golden mean, sort of */ | |
ff32afa0 | 13 | int i, invis, at, ddtype, with; |
0e630f4c | 14 | float ddval, xwith, ywith; |
ff32afa0 JA |
15 | float h, w, x0, y0, x1, y1; |
16 | obj *p, *ppos; | |
17 | Attr *ap; | |
0e630f4c JA |
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++) { | |
ff32afa0 JA |
25 | ap = &attr[i]; |
26 | switch (ap->a_type) { | |
0e630f4c | 27 | case HEIGHT: |
ff32afa0 | 28 | h = ap->a_val.f; |
0e630f4c JA |
29 | break; |
30 | case WIDTH: | |
ff32afa0 | 31 | w = ap->a_val.f; |
0e630f4c JA |
32 | break; |
33 | case SAME: | |
34 | h = prevh; | |
35 | w = prevw; | |
36 | break; | |
37 | case WITH: | |
ff32afa0 | 38 | with = ap->a_val.i; /* corner */ |
0e630f4c JA |
39 | break; |
40 | case AT: | |
ff32afa0 | 41 | ppos = ap->a_val.o; |
0e630f4c JA |
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: | |
ff32afa0 JA |
51 | ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT; |
52 | if (ap->a_sub == DEFAULT) | |
0e630f4c | 53 | ddval = getfval("dashwid"); |
ff32afa0 JA |
54 | else |
55 | ddval = ap->a_val.f; | |
0e630f4c | 56 | break; |
ff32afa0 JA |
57 | case TEXTATTR: |
58 | savetext(ap->a_sub, ap->a_val.p); | |
0e630f4c JA |
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; | |
0e630f4c | 95 | p->o_ddval = ddval; |
ff32afa0 | 96 | p->o_attr = invis | ddtype; |
0e630f4c JA |
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 | } |