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