|
|
1.1 root 1: /*
2: %Z% %M% version %I% %Q%of %H% %T%
3: Last Delta: %G% %U% to %P%
4: */
5:
6: #ifndef JPIC
7: #define JPIC "Jpic "
8: #endif JPIC
9:
10: #include "cip.h"
11:
12: char jpicCmd[sizeof (JPIC) + MAXNAMESIZE] = JPIC;
13: #define filename (jpicCmd + sizeof (JPIC) - 1)
14:
15: int Yoffset = YPIC, Xoffset = Xmin;
16: struct macro *macroList;
17: int nextMacroName;
18: Rectangle macroBB();
19:
20: extern int currentBrush, copyFlag, gridState, buttonState;
21: extern int videoState;
22: extern char c;
23: extern Rectangle brushes[];
24: extern Rectangle BBpic;
25: extern struct thing *readPic();
26: extern void initMessage ();
27: extern void putMessage ();
28: extern Point jString ();
29: extern void jMoveTo ();
30:
31:
32: doPut(h)
33: struct thing *h;
34: {
35: register struct thing *t;
36: register FILE *fp;
37: register struct macro *m;
38: register int saveB;
39:
40: saveB = buttonState;
41: getFileName();
42: if (filename[0]!='\0') {
43: if ((fp = fopen(filename,"w")) != (FILE *) NULL) {
44: fprintf(fp,".PS\nscale=81\n");
45: cursswitch(&hourglass);
46: findBBpic(h);
47: nextMacroName = 0;
48: for (m=macroList; m!=(struct macro *)NULL; m=m->next) {
49: if (m->useCount>0) {
50: m->outName = nextMacroName++;
51: fprintf(fp,"define m%d |\n",m->outName);
52: fprintf(fp,"[ box invis ht %d wid %d with .sw at 0,0\n",
53: m->bb.corner.y, m->bb.corner.x);
54: if ((t=m->parts) !=TNULL) {
55: do {
56: writePIC(t,fp,Rpt(Pt(0,0),m->bb.corner));
57: t=t->next;
58: } while (t!=m->parts);
59: }
60: fprintf(fp,"] |\n\n");
61: }
62: }
63: fprintf(fp,"box invis ht %d wid %d with .sw at 0,0\n",
64: BBpic.corner.y - BBpic.origin.y,
65: BBpic.corner.x - BBpic.origin.x);
66: if ((t = h) != TNULL) {
67: do {
68: writePIC(t,fp,BBpic);
69: t = t->next;
70: } while (t!=h);
71: }
72: fprintf(fp,".PE\n");
73: fclose(fp);
74: cursSwitch();
75: }
76: else {
77: fileError("open",filename);
78: }
79: }
80: changeButtons(saveB);
81: }
82:
83: fileError(s,fn)
84: register char *s, *fn;
85: {
86: beep();
87: initMessage ();
88: putMessage("cannot ");
89: putMessage(s);
90: putMessage(" file ");
91: putMessage(fn);
92: sleep( 5 );
93: beep();
94: }
95:
96: struct thing *
97: doGet(h)
98: register struct thing *h;
99: {
100: register FILE *fp;
101:
102: getFileName();
103: if (filename[0]!='\0') {
104: if (access(filename,4)!=0) {
105: fileError("access",filename);
106: }
107: else {
108: if ((fp = popen(jpicCmd,"r")) == (FILE *) NULL) {
109: fileError("open pipe for",filename);
110: }
111: else {
112: cursswitch(&hourglass);
113: getChar(fp);
114: h = readPic(fp,h);
115: pclose(fp);
116: cursSwitch();
117: }
118: }
119: }
120: changeBrush(-1);
121: changeButtons(INITbuttons);
122: return(h);
123: }
124:
125: getFileName()
126: {
127: register int i;
128: Point p;
129:
130: p = MOUSE_XY;
131: p.y += 20;
132: changeButtons(BLANKbuttons);
133: centeredText(p,filename);
134: for (i=0; filename[i]!='\0'; i++) {
135: }
136: getKbdText (filename, p, i, &prompt, MAXNAMESIZE);
137: }
138:
139: struct thing *
140: doClear(h)
141: struct thing *h;
142: {
143: deleteAllThings(h);
144: cursinhibit();
145: xtipple(&display,brushes[PIC]);
146: cursallow();
147: copyFlag = 0;
148: changeBrush(-1);
149: changeButtons(INITbuttons);
150: if (gridState==GRIDon) {
151: drawGrid();
152: }
153: return(TNULL);
154: }
155:
156: struct thing *
157: defineMacro(h)
158: register struct thing *h;
159: {
160: Point p, q;
161: register struct thing *s, *t, *l = { TNULL };
162: Rectangle r;
163: struct thing dummy;
164: char *z; /* Temporary alloc space */
165:
166: changeBrush(-1);
167: /* Test to see if there is enough memory to create this macro */
168: if ((z=getSpace(sizeof(struct macro)+sizeof(struct thing))) == NULL) {
169: return (h);
170: }
171: free (z);
172: changeButtons(MACRObuttons);
173: for (; !button2(); jnap(2)) ;
174: p = sub(MOUSE_XY,Pt(Xmin,YPIC));
175: q = track(p,Pt(Xmin,YPIC),BOX,h);
176: r = canon (p, q);
177: h = insert(&dummy,h);
178: if ((t = h->next) != TNULL) {
179: do {
180: if (inside(r,t->bb)) {
181: s = remove(t);
182: l = insert(t,l);
183: t = s;
184: }
185: else {
186: t = t->next;
187: }
188: } while (t != &dummy);
189: }
190: h = remove(&dummy);
191: if ((t = l) != TNULL) {
192: r = macroBB(l);
193: do {
194: makeRelative(t,r.origin);
195: t = t->next;
196: } while (t != l);
197: p = r.origin;
198: r = rsubp (r, r.origin);
199: changeButtons(INITbuttons);
200: return insert(newMacro(p,recordMacro(l,r,NULL,NULL,NULL)),h);
201: }
202: else {
203: changeButtons(INITbuttons);
204: return(h);
205: }
206: }
207:
208: Rectangle
209: macroBB(l)
210: struct thing *l;
211: {
212: Point p, q, p1, p2;
213: register struct thing *t;
214: Rectangle r;
215:
216: p.x = Xmax; p.y=YBOT; q.x=0; q.y=0;
217: if ((t=l) != TNULL) {
218: do {
219: if (t->type != LINE) {
220: p1 = t->bb.origin;
221: p2 = t->bb.corner;
222: }
223: else {
224: p1.x = min(t->origin.x,t->otherValues.end.x);
225: p1.y = min(t->origin.y,t->otherValues.end.y);
226: p2.x = max(t->origin.x,t->otherValues.end.x);
227: p2.y = max(t->origin.y,t->otherValues.end.y);
228: }
229: p.x = min(p.x,p1.x);
230: p.y = min(p.y,p1.y);
231: q.x = max(q.x,p2.x);
232: q.y = max(q.y,p2.y);
233: t=t->next;
234: } while (t != l);
235: }
236: r.origin = p; r.corner = q;
237: return(r);
238: }
239:
240: /* This routine places a new macro athe the end of the macro list. */
241: /* The head of the list is pointed to by macroList. */
242:
243: struct macro *
244: recordMacro(list,r,xro,yro,s)
245: struct thing *list; /* List of things making up macro */
246: Rectangle r; /* BB of macro with origin at (0,0) */
247: struct macro *xro; /* X-reflection of macro */
248: struct macro *yro; /* Y-reflection of macro */
249: char *s;
250: {
251: register struct macro *m, *l, *n;
252:
253: if ((m = (struct macro *) getSpace(sizeof(struct macro)))
254: !=(struct macro *)NULL) {
255: m->name = s;
256: m->bb = r;
257: m->useCount = 0;
258: m->parts = list;
259: m->xReflectionOf = xro;
260: m->yReflectionOf = yro;
261: m->next = (struct macro *)NULL;
262: l = (struct macro *)NULL;
263: for (n=macroList; n!=(struct macro *)NULL; n=n->next) {
264: l=n;
265: }
266: if (l == (struct macro *)NULL) {
267: macroList = m;
268: }
269: else {
270: l->next = m;
271: }
272: }
273: return(m);
274: }
275:
276: int
277: inside(r,s)
278: Rectangle r,s;
279: {
280: return((r.origin.x <= s.origin.x) && (r.origin.y <= s.origin.y)
281: && (r.corner.x >= s.corner.x) && (r.corner.y >= s.corner.y));
282: }
283:
284: struct thing *
285: makeRelative(t,p)
286: register struct thing *t;
287: Point p;
288: {
289: register int i;
290:
291: t->origin = sub(t->origin,p);
292: switch(t->type) {
293: case CIRCLE:
294: case ELLIPSE:
295: case TEXT: {
296: break;
297: }
298: case LINE: {
299: t->otherValues.end = sub(t->otherValues.end,p);
300: break;
301: }
302: case BOX: {
303: t->otherValues.corner = sub(t->otherValues.corner,p);
304: break;
305: }
306: case ARC: {
307: t->otherValues.arc.start = sub(t->otherValues.arc.start,p);
308: t->otherValues.arc.end = sub(t->otherValues.arc.end,p);
309: break;
310: }
311: case SPLINE: {
312: for (i=0; i<=t->otherValues.spline.used; i++) {
313: t->otherValues.spline.plist[i] =
314: sub(t->otherValues.spline.plist[i],p);
315: }
316: break;
317: }
318: }
319: BoundingBox(t);
320: return(t);
321: }
322:
323: int
324: backspaceOneWord(s,i)
325: register char *s;
326: register int i;
327: {
328: s[(i>0)? --i : 0] = '\0';
329: for ( ; i>0 && (isdigit(s[i-1]) || isletter(s[i-1])); ) {
330: s[--i]='\0';
331: }
332: return(i);
333: }
334:
335: /* This routine places a stippled texture into the rectangle */
336: /* specified by r in the layer specified by P->layer. No stippling */
337: /* is used if the user owns the mouse. Instead a blank */
338: /* stipple pattern is used. Note, that when STORE mode is used, */
339: /* anything that was in the rectangle is wiped out. */
340: /* Reverse textures are used if reverse video is set. */
341:
342: xtipple (b, r)
343: Bitmap *b;
344: Rectangle r;
345: {
346: Texture *tp;
347:
348: if (videoState == BLACKfield) {
349: tp = &rvplain;
350: }
351: else {
352: tp = &plain;
353: }
354: texture (&display, r, tp, F_STORE);
355: }
356:
357: cursSwitch ()
358: {
359: cursswitch(ptinrect(MOUSE_XY,brushes[PIC])
360: ? &crossHairs : (Cursor *)0);
361: }
362:
363: getKbdText (s, p, size, cursorTexture, maximum)
364: char *s;
365: Point p;
366: int size; /* Size of text in s */
367: Texture *cursorTexture;
368: int maximum; /* Maximumimum size of s */
369: {
370: int i;
371:
372: cursswitch (cursorTexture);
373: clearKeyboard();
374: wait(KBD);
375: for(i=size; (c=kbdchar())!='\r'; wait(KBD)) {
376: if (i!=0) {
377: centeredText(p,s);
378: }
379: switch (c) {
380: case '@':
381: case 'U'-'@': {
382: i=0;
383: s[0] = '\0';
384: break;
385: }
386: case 'W'-'@': {
387: i = backspaceOneWord(s,i);
388: break;
389: }
390: case '\b': {
391: s[(i>0)? --i : 0] = '\0';
392: break;
393: }
394: default: {
395: if (i >= maximum) {
396: ringbell ();
397: }
398: else {
399: s[i++] = c;
400: s[i] = '\0';
401: }
402: break;
403: }
404: }
405: centeredText(p,s);
406: }
407: if (i != 0) {
408: centeredText(p,s);
409: }
410: cursSwitch ();
411: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.