boxgen.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include <stdio.h>
  2. #include "pic.h"
  3. #include "y.tab.h"
  4. obj *boxgen(void)
  5. {
  6. static double prevh = HT;
  7. static double prevw = WID; /* golden mean, sort of */
  8. int i, at, battr, with;
  9. double ddval, fillval, xwith, ywith;
  10. double h, w, x0, y0, x1, y1;
  11. obj *p, *ppos;
  12. Attr *ap;
  13. h = getfval("boxht");
  14. w = getfval("boxwid");
  15. at = battr = with = 0;
  16. ddval = fillval = xwith = ywith = 0;
  17. for (i = 0; i < nattr; i++) {
  18. ap = &attr[i];
  19. switch (ap->a_type) {
  20. case HEIGHT:
  21. h = ap->a_val.f;
  22. break;
  23. case WIDTH:
  24. w = ap->a_val.f;
  25. break;
  26. case SAME:
  27. h = prevh;
  28. w = prevw;
  29. break;
  30. case WITH:
  31. with = ap->a_val.i; /* corner */
  32. break;
  33. case AT:
  34. ppos = ap->a_val.o;
  35. curx = ppos->o_x;
  36. cury = ppos->o_y;
  37. at++;
  38. break;
  39. case INVIS:
  40. battr |= INVIS;
  41. break;
  42. case NOEDGE:
  43. battr |= NOEDGEBIT;
  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. }