|
|
1.1 ! root 1: /* ! 2: %Z% %M% version %I% %Q%of %H% %T% ! 3: Last Delta: %G% %U% to %P% ! 4: */ ! 5: ! 6: #include "cip.h" ! 7: #define DOT 2 ! 8: #define DASH 10 ! 9: #define ARROWwid 10 ! 10: #define ARROWht 5 ! 11: ! 12: Rectangle saveScreenmap; ! 13: Word *saveBase; ! 14: extern Point jString (); ! 15: extern void jMoveTo (); ! 16: extern Rectangle brushes[]; ! 17: struct thing addOffset(); ! 18: ! 19: /* This routine clips an arc within rectangle brushes[PIC] */ ! 20: ! 21: xarc(p0, p1, p2) ! 22: Point p0, p1, p2; ! 23: { ! 24: arc(&display , p0, p1, p2, F_XOR); ! 25: } ! 26: ! 27: ! 28: /* This routine clips a spline within rectangle brushes[PIC] */ ! 29: ! 30: xspline(offset,p, n) ! 31: Point offset; ! 32: register Point *p; ! 33: int n; ! 34: { ! 35: spline(offset,p, n); ! 36: } ! 37: ! 38: /* This routine clips a line within rectangle brushes[PIC] */ ! 39: ! 40: xsegment (p, q) ! 41: Point p, q; ! 42: { ! 43: segment(&display , p, q, F_XOR); ! 44: PtCurrent = q; ! 45: } ! 46: ! 47: draw(t,offset) ! 48: register struct thing *t; ! 49: Point offset; ! 50: { ! 51: register struct thing *s; ! 52: Rectangle rc; ! 53: Point p1,p2; ! 54: register int u; ! 55: register Font *ft; ! 56: ! 57: if (t != (struct thing *) NULL) { ! 58: cursinhibit(); ! 59: switch(t->type) { ! 60: case CIRCLE: { ! 61: circle(&display,add(offset,t->origin), ! 62: t->otherValues.radius,F_XOR); ! 63: break; ! 64: } ! 65: case BOX: { ! 66: rc = raddp(t->bb,offset); ! 67: if (t->boorder == DOTTED) { ! 68: dashedBox(rc,DOT); ! 69: } ! 70: else { ! 71: if (t->boorder == DASHED) { ! 72: dashedBox(rc,DASH); ! 73: } ! 74: else { ! 75: box(rc); ! 76: } ! 77: } ! 78: break; ! 79: } ! 80: case ELLIPSE: { ! 81: Ellipse(add(offset,t->origin),t->otherValues.ellipse.ht, ! 82: t->otherValues.ellipse.wid); ! 83: break; ! 84: } ! 85: case LINE: { ! 86: p1 = add(t->origin,offset); ! 87: p2 = add(t->otherValues.end,offset); ! 88: if (t->boorder == DOTTED) { ! 89: dashedLine(p1,p2,DOT); ! 90: } ! 91: else { ! 92: if (t->boorder == DASHED) { ! 93: dashedLine(p1,p2,DASH); ! 94: } ! 95: else { ! 96: segment(&display,p1,p2,F_XOR); ! 97: PtCurrent = p2; ! 98: } ! 99: } ! 100: if ((t->arrow==startARROW)||(t->arrow==doubleARROW)) { ! 101: arrow(p2,p1); ! 102: } ! 103: if ((t->arrow==endARROW)||(t->arrow==doubleARROW)) { ! 104: arrow(p1,p2); ! 105: } ! 106: break; ! 107: } ! 108: case ARC: { ! 109: arc (&display, add(offset,t->origin), ! 110: add(offset,t->otherValues.arc.start), ! 111: add(offset,t->otherValues.arc.end),F_XOR); ! 112: break; ! 113: } ! 114: case TEXT: { ! 115: ft = t->otherValues.text.f->f; ! 116: u = strwidth(ft,t->otherValues.text.s); ! 117: switch (t->otherValues.text.just) { ! 118: case CENTER: { ! 119: p1 = add(offset,sub(t->origin,Pt(u>>1,0))); ! 120: break; ! 121: } ! 122: case LEFTJUST: { ! 123: p1 = add(offset,t->origin); ! 124: break; ! 125: } ! 126: case RIGHTJUST: { ! 127: p1 = add(offset,sub(t->origin,Pt(u,0))); ! 128: break; ! 129: } ! 130: } ! 131: string(ft,t->otherValues.text.s,&display,p1,F_XOR); ! 132: break; ! 133: } ! 134: case SPLINE: { ! 135: u = t->otherValues.spline.used; ! 136: spline(offset,t->otherValues.spline.plist,u); ! 137: if ((t->arrow==startARROW)||(t->arrow==doubleARROW)) { ! 138: arrow(add(offset,t->otherValues.spline.plist[2]), ! 139: add(offset,t->otherValues.spline.plist[1])); ! 140: } ! 141: if ((t->arrow==endARROW)||(t->arrow==doubleARROW)) { ! 142: arrow(add(offset,t->otherValues.spline.plist[u-2]), ! 143: add(offset,t->otherValues.spline.plist[u-1])); ! 144: } ! 145: break; ! 146: } ! 147: case MACRO: { ! 148: if ((s=t->otherValues.list->parts) != (struct thing *)NULL) { ! 149: do { ! 150: draw(s,add(offset,t->origin)); ! 151: s = s->next; ! 152: } while (s != t->otherValues.list->parts); ! 153: } ! 154: break; ! 155: } ! 156: } ! 157: cursallow(); ! 158: } ! 159: } ! 160: ! 161: xbox(r) ! 162: Rectangle r; ! 163: { ! 164: xsegment(r.origin,Pt(r.corner.x,r.origin.y)); ! 165: xsegment(Pt(r.corner.x,r.origin.y),r.corner); ! 166: xsegment(r.corner,Pt(r.origin.x,r.corner.y)); ! 167: xsegment(Pt(r.origin.x,r.corner.y),r.origin); ! 168: } ! 169: ! 170: box(r) ! 171: Rectangle r; ! 172: { ! 173: segment(&display , r.origin,Pt(r.corner.x,r.origin.y),F_XOR); ! 174: segment(&display , Pt(r.corner.x,r.origin.y),r.corner,F_XOR); ! 175: segment(&display , r.corner,Pt(r.origin.x,r.corner.y),F_XOR); ! 176: segment(&display , Pt(r.origin.x,r.corner.y),r.origin,F_XOR); ! 177: PtCurrent = r.origin; ! 178: } ! 179: ! 180: dashedBox(r,dashsize) ! 181: Rectangle r; ! 182: register int dashsize; ! 183: { ! 184: dashedLine(r.origin,Pt(r.corner.x,r.origin.y),dashsize); ! 185: dashedLine(Pt(r.corner.x,r.origin.y),r.corner,dashsize); ! 186: dashedLine(r.corner,Pt(r.origin.x,r.corner.y),dashsize); ! 187: dashedLine(Pt(r.origin.x,r.corner.y),r.origin,dashsize); ! 188: } ! 189: ! 190: dashedLine(s,end,dashsize) ! 191: Point s, end; ! 192: int dashsize; ! 193: { ! 194: register int e, dx, dy, i, toDraw, yinc, xinc, swit; ! 195: ! 196: initpoints(&display, F_XOR); ! 197: dx = abs(end.x - s.x); ! 198: dy = abs(end.y - s.y); ! 199: xinc = ((end.x-s.x)>0)? 1 : -1; ! 200: yinc = ((end.y-s.y)>0)? 1 : -1; ! 201: swit = (dy>dx); ! 202: toDraw = 1; ! 203: e = (swit)? (2*dx - dy) : (2*dy - dx); ! 204: for (i=0; i < ((swit) ? dy : dx); i++) { ! 205: if (i>0 && i%dashsize==0) { ! 206: toDraw = (toDraw==1)?0:1; ! 207: } ! 208: if (toDraw) { ! 209: points(s, F_XOR); ! 210: } ! 211: if (e>0) { ! 212: if (swit) { ! 213: s.x += xinc; ! 214: } ! 215: else { ! 216: s.y += yinc; ! 217: } ! 218: e += (swit)? (2*dx - 2*dy) : (2*dy - 2*dx); ! 219: } ! 220: else { ! 221: e += (swit)? 2*dx : 2*dy; ! 222: } ! 223: if (swit) { ! 224: s.y += yinc; ! 225: } ! 226: else { ! 227: s.x += xinc; ! 228: } ! 229: } ! 230: endpoints(); ! 231: } ! 232: ! 233: int ! 234: degrees(d) ! 235: register int d; ! 236: { ! 237: while (d>360) { ! 238: d -= 360; ! 239: } ! 240: while (d<0) { ! 241: d += 360; ! 242: } ! 243: return(d); ! 244: } ! 245: ! 246: arrow(a, b) /* draw arrow (without line) */ ! 247: Point a,b; ! 248: { ! 249: register int alpha, rot, hyp; ! 250: register int dx, dy; ! 251: ! 252: rot = atan2( ARROWwid / 2, ARROWht); ! 253: hyp = norm(ARROWwid,ARROWht,0); ! 254: alpha = atan2(b.y-a.y, b.x-a.x); ! 255: dx = muldiv(hyp,cos(degrees(alpha + 180 + rot)),1024); ! 256: dy = muldiv(hyp,sin(degrees(alpha + 180 + rot)),1024); ! 257: cursinhibit(); ! 258: segment(&display,add(b,Pt(-dx,dy)),b,F_XOR); ! 259: cursallow(); ! 260: dx = muldiv(hyp,cos(degrees(alpha + 180 - rot)),1024); ! 261: dy = muldiv(hyp,sin(degrees(alpha + 180 - rot)),1024); ! 262: cursinhibit(); ! 263: segment(&display,add(b,Pt(dx,-dy)),b,F_XOR); ! 264: cursallow(); ! 265: } ! 266: ! 267: centeredText(p,s) ! 268: Point p; ! 269: register char *s; ! 270: { ! 271: jMoveTo(Pt(p.x-(strwidth(&defont,s)>>1),p.y)); ! 272: jString(s); ! 273: } ! 274: ! 275: flash(b,offset) ! 276: register Rectangle *b; ! 277: Point offset; ! 278: { ! 279: if (b != (Rectangle *) NULL) { ! 280: cursinhibit(); ! 281: rectf(&display,inset(raddp(*b,offset),1),F_XOR); ! 282: cursallow(); ! 283: } ! 284: } ! 285: ! 286: flashThing(t,offset) ! 287: register struct thing *t; ! 288: Point offset; ! 289: { ! 290: if (t != (struct thing *) NULL) { ! 291: cursinhibit(); ! 292: switch (t->type) { ! 293: case CIRCLE: ! 294: case BOX: ! 295: case ELLIPSE: ! 296: case LINE: ! 297: case ARC: ! 298: case SPLINE: { ! 299: draw(t,offset); ! 300: break; ! 301: } ! 302: case MACRO: ! 303: case TEXT: { ! 304: flash(&t->bb,offset); ! 305: break; ! 306: } ! 307: } ! 308: cursallow(); ! 309: } ! 310: } ! 311: ! 312: Ellipse(p,h,w) ! 313: Point p; ! 314: register int h, w; ! 315: { ! 316: ! 317: ellipse(&display , p, w>>1, h>>1, F_XOR); ! 318: } ! 319: ! 320: drawZigZag(offset,p,n) ! 321: Point offset; ! 322: register Point *p; ! 323: int n; ! 324: { ! 325: register int i; ! 326: register Point j, k; ! 327: ! 328: if (p != (Point *) NULL) { ! 329: cursinhibit(); ! 330: if (n>0) { ! 331: j = add(offset, p[1]); ! 332: for (i=2; i<=n; i++) { ! 333: k = add (offset, p[i]); ! 334: xsegment(j, k); ! 335: j = k; ! 336: } ! 337: } ! 338: cursallow(); ! 339: } ! 340: } ! 341: ! 342: #define SCALE (long) 1000 ! 343: #define STEPS 10 ! 344: ! 345: spline(offset,p, n) ! 346: Point offset; ! 347: register Point *p; ! 348: int n; ! 349: { ! 350: register long w, t1, t2, t3; ! 351: register int i, j; ! 352: Point q; ! 353: Point pcurrent; /* Current point */ ! 354: ! 355: if (p != (Point *) NULL) { ! 356: p[0] = p[1]; ! 357: p[n] = p[n-1]; ! 358: cursinhibit(); ! 359: pcurrent = add(offset,p[0]); ! 360: for (i = 0; i < n-1; i++) { ! 361: for (j = 0; j < STEPS; j++) { ! 362: w = SCALE * j / STEPS; ! 363: t1 = w * w / (2 * SCALE); ! 364: w = w - SCALE/2; ! 365: t2 = 3*SCALE/4 - w * w / SCALE; ! 366: w = w - SCALE/2; ! 367: t3 = w * w / (2*SCALE); ! 368: q.x = (t1*p[i+2].x + t2*p[i+1].x + t3*p[i].x + SCALE/2) / SCALE; ! 369: q.y = (t1*p[i+2].y + t2*p[i+1].y + t3*p[i].y + SCALE/2) / SCALE; ! 370: segment(&display, pcurrent, add(offset,q), F_XOR); ! 371: pcurrent = add(offset, q ); ! 372: } ! 373: } ! 374: cursallow(); ! 375: } ! 376: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.