|
|
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:
8:
9: extern int currentBrush, copyFlag, thingSelected, editDepth;
10: extern Rectangle brushes[];
11: extern int gridState, videoState, buttonState;
12: extern short noSpace;
13: extern Point jString ();
14: extern void getKbdChar ();
15: extern void jMoveTo ();
16: extern struct macro *macroList;
17:
18: char *lineText[] = {"delete","copy",
19: "solid","dotted","dashed","arrow",
20: "reflect x","reflect y",NULL};
21: Menu lineMenu = { lineText };
22:
23: char *boxText[] = {"delete","copy","solid","dotted","dashed",NULL};
24: Menu boxMenu = { boxText };
25:
26: char *circleText[] = {"delete","copy",NULL};
27: Menu circleMenu = { circleText };
28:
29: char *splineText[] = {"delete", "copy", "arrow",
30: "reflect x", "reflect y", NULL};
31: Menu splineMenu = { splineText };
32:
33: char *arcText[] = {"delete","copy","reflect x","reflect y",NULL};
34: Menu arcMenu = { arcText };
35:
36: char *macroText[] = {"delete","copy","reflect x","reflect y",
37: "edit","separate",NULL};
38: Menu macroMenu = { macroText };
39:
40: char *textText[] = {"delete","copy","point size","roman",
41: "italic","bold", "center","left justify",
42: "right justify","attributes",
43: NULL};
44: Menu textMenu = { textText };
45:
46: #define GET 0
47: #define PUT 1
48: #define CLEAR 2
49: #define REDRAW 3
50: #define DEFINEMACRO 4
51: #define GRID 5
52: #define FLIPVIDEO 6
53: #define QUIT 7
54: #define DUMPIT 8
55:
56: char *commandText[] = {"get file","put file","clear screen",
57: "redraw screen","define macro","grid",
58: "reverse video","quit",
59: #ifdef DUMP
60: "dump",
61: #endif
62: NULL};
63: Menu commandMenu = { commandText };
64:
65: int
66: menuHit (menu, but)
67: Menu *menu;
68: int but;
69: {
70: int item;
71:
72: cursswitch ((Word *)NULL);
73: item = menuhit(menu, but);
74: cursSwitch ();
75: return (item);
76: }
77:
78: struct thing *
79: insertReflect (t, p, item, which)
80: struct thing *t;
81: Point p; /* Offset */
82: int item;
83: int which; /* Which item to be tested */
84: {
85: register struct thing d; /* Dummy structure */
86: register struct thing *h; /* New head of thing list */
87:
88: drawSelectionLines(t,p);
89: draw(t,p);
90: h = remove(t);
91: d = *t;
92: free(t);
93: h = (item==which) ?
94: insert(reflect(&d,Pt(0,d.bb.corner.y+d.bb.origin.y)),h)
95: : insert(reflect(&d,Pt(d.bb.corner.x+d.bb.origin.x,0)),h);
96: draw(h,p);
97: drawSelectionLines(h,p);
98: return (h);
99: }
100:
101: /* This routine deletes the given macro from the macro list. */
102: /* It has to scan the macro list looking for that macros entry since */
103: /* there are no back links within the list. */
104:
105: void
106: removeMacro (m)
107: struct macro *m;
108: {
109: register struct macro *ml; /* Pointer for macro list */
110:
111: if (m == macroList) {
112: macroList = (struct macro *)NULL;
113: }
114: else {
115: for (ml = macroList; ml != (struct macro *)NULL; ml = ml->next) {
116: if (ml->next == m) { /* Macro found delete it. */
117: ml->next = m->next;
118: }
119: }
120: }
121: free (m);
122: return;
123: }
124:
125: struct thing *
126: displayThingMenu(m,t,p)
127: Point m; /* Mouse location */
128: Point p; /* Offset */
129: register struct thing *t; /* Thing to be displayed */
130: {
131: register int item;
132: register int i, b, oldED;
133: register struct thing *pts;
134: register struct thing *h, *g, *f;
135: Rectangle r; register char c, s[10];
136:
137: switch(t->type) {
138: case LINE: {
139: item = menuHit (&lineMenu, 3);
140: b = -1;
141: switch (item) {
142: case 2: {
143: /* make line solid */
144: b = SOLID;
145: break;
146: }
147: case 3: {
148: /* make line dotted */
149: b = DOTTED;
150: break;
151: }
152: case 4: {
153: /* make line dashed */
154: b = DASHED;
155: break;
156: }
157: case 5: {
158: /* add or remove arrowheads */
159: draw(t,p);
160: if (distance(m,t->origin) < distance(m,t->otherValues.end)) {
161: if ((t->arrow==startARROW)||(t->arrow==doubleARROW)) {
162: t->arrow -= startARROW;
163: }
164: else {
165: t->arrow += startARROW;
166: }
167: }
168: else {
169: if ((t->arrow==endARROW)||(t->arrow==doubleARROW)) {
170: t->arrow -= endARROW;
171: }
172: else {
173: t->arrow += endARROW;
174: }
175: }
176: draw(t,p);
177: break;
178: }
179: case 6:
180: case 7: {
181: t = insertReflect (t, p, item, 6);
182: break;
183: }
184: }
185: if (b >= 0 && b!=t->boorder) {
186: draw(t,p);
187: t->boorder = b;
188: draw(t,p);
189: }
190: break;
191: }
192: case BOX: {
193: item = menuHit(&boxMenu,3);
194: b = -1;
195: switch(item) {
196: case 2: { /* make box outline solid */
197: b = SOLID;
198: break;
199: }
200: case 3: { /* make box outline dotted */
201: b = DOTTED;
202: break;
203: }
204: case 4: { /* make box outline dashed */
205: b = DASHED;
206: break;
207: }
208: }
209: if (b>=0 && b!=t->boorder) {
210: draw(t,p);
211: t->boorder = b;
212: draw(t,p);
213: }
214: break;
215: }
216: case MACRO: {
217: item = menuHit(¯oMenu,3);
218: switch (item) {
219: case 2:
220: case 3: {
221: r = t->otherValues.list->bb;
222: h = TNULL;
223: draw(t,p);
224: if (item==2 && t->otherValues.list->xReflectionOf
225: != (struct macro *)NULL) {
226: t->otherValues.list->useCount--;
227: t->otherValues.list = t->otherValues.list->xReflectionOf;
228: }
229: else {
230: if (item==3 && t->otherValues.list->yReflectionOf
231: != (struct macro *)NULL) {
232: t->otherValues.list->useCount--;
233: t->otherValues.list = t->otherValues.list->yReflectionOf;
234: }
235: else {
236: /* Go thru parts list, reflect all things, and */
237: /* make copies of them. The copies go into the list h. */
238: if ((g=t->otherValues.list->parts)
239: !=TNULL) {
240: do {
241: h = (item==2) ?
242: insert(reflect(
243: g,Pt(0,r.origin.y+r.corner.y)),h)
244: : insert(reflect(
245: g,Pt(r.corner.x+r.origin.x,0)),h);
246: g = g->next;
247: } while (g != t->otherValues.list->parts);
248: }
249: t->otherValues.list = recordMacro(h,r,
250: (item==2)?t->otherValues.list :(struct macro *)NULL,
251: (item==2)?(struct macro *)NULL :t->otherValues.list,
252: NULL);
253: }
254: }
255: t->otherValues.list->useCount++;
256: draw(t,p);
257: break;
258: }
259: case 4: {
260: /* edit macro */
261: oldED = editDepth;
262: removeReflectionReferences(t->otherValues.list);
263: pts = t->otherValues.list->parts;
264: /* Draw edit button when editDepth==1, other times */
265: /* undraw button. */
266: if ((editDepth)!=0) {
267: drawEDbutton(editDepth);
268: }
269: drawEDbutton(++editDepth);
270: changeButtons (INITbuttons);
271: thingSelected = 0;
272: while (editDepth>oldED) {
273: pts = doMouseButtons(pts,add(p,t->origin));
274: jnap(2);
275: }
276: t->otherValues.list->parts = pts;
277: t->otherValues.list->bb = macroBB(pts);
278: if (thingSelected) {
279: drawSelectionLines (t, p);
280: thingSelected = 0;
281: }
282: if (editDepth==0) {
283: doRedraw(t, p);
284: }
285: break;
286: }
287: case 5: { /* separate */
288: h = remove(t); /* Cut macro from thing list */
289: t->otherValues.list->useCount--;
290: m = sub(Pt(0,0),t->origin);
291: /* Go thru macro's thing list and make everything relative */
292: if ((g=t->otherValues.list->parts)!=TNULL) {
293: if (t->otherValues.list->useCount > 0) {
294: do { /* Copy list */
295: if ((f=(struct thing *)getSpace(sizeof(struct thing)))
296: == TNULL) {
297: break;
298: }
299: g = g->next;
300: *f = *g;
301: f = makeRelative (f, m);
302: h = insert (f, h);
303: } while (g != t->otherValues.list->parts);
304: }
305: else {
306: do{ /* Move list */
307: g = g->next;
308: g = makeRelative(g,m);
309: f = g;
310: g = remove (f);
311: h = insert (f, h);
312: } while (g != TNULL);
313: removeMacro (t->otherValues.list);
314: }
315: }
316:
317: thingSelected = 0;
318: copyFlag = 0;
319: changeButtons(INITbuttons);
320: free(t); /* Remove macro thing */
321: t = h;
322: break;
323: }
324: }
325: break;
326: }
327: case TEXT: {
328: item = menuHit(&textMenu,3);
329: switch (item) {
330: case 2: { /* point size */
331: m = MOUSE_XY;
332: m.x += 20;
333: getKbdText (s, m, 0, &pointsize, sizeof (s)-1);
334: b = atoi (s);
335: draw(t,p);
336: t->otherValues.text.f->useCount--;
337: t->otherValues.text.f =
338: findFont(b,t->otherValues.text.f->num);
339: draw(t,p);
340: BoundingBox(t);
341: break;
342: }
343: case 3: /* roman face */
344: case 4: /* italic face */
345: case 5: { /* bold face */
346: draw(t,p);
347: t->otherValues.text.f->useCount--;
348: t->otherValues.text.f =
349: findFont(t->otherValues.text.f->ps,item-2);
350: BoundingBox(t);
351: draw(t,p);
352: break;
353: }
354: case 6: /* center */
355: case 7: /* left justify */
356: case 8: { /* right justify */
357: draw(t,p);
358: t->otherValues.text.just = item - 6;
359: BoundingBox(t);
360: draw(t,p);
361: break;
362: }
363: case 9: { /* show attributes */
364: char buf[25];
365: cursswitch(&candle);
366: sprintf(buf,"%s f:%c ps:%d",
367: (t->otherValues.text.just==CENTER)?"center":
368: ((t->otherValues.text.just==LEFTJUST)?"ljust":"rjust"),
369: (t->otherValues.text.f->num==ROMAN)?'R':
370: ((t->otherValues.text.f->num==ITALIC)?'I':'B'),
371: t->otherValues.text.f->ps);
372: m = MOUSE_XY;
373: jMoveTo(Pt(m.x+20,m.y));
374: jString(buf);
375: wait(MOUSE);
376: while (!button123()) {
377: jnap(2);
378: }
379: jMoveTo(Pt(m.x+20,m.y));
380: jString(buf);
381: cursSwitch();
382: break;
383: }
384: }
385: break;
386: }
387: case CIRCLE:
388: case ELLIPSE: {
389: item = menuHit(&circleMenu,3);
390: break;
391: }
392: case ARC: {
393: item = menuHit(&arcMenu,3);
394: switch (item) {
395: case 2:
396: case 3: {
397: t = insertReflect (t, p, item, 2);
398: break;
399: }
400: }
401: break;
402: }
403: case SPLINE: {
404: item = menuHit(&splineMenu,3);
405: switch (item) {
406: case 2: { /* arrow */
407: b = t->otherValues.spline.used;
408: if (distance(m,t->origin)<
409: distance(m,t->otherValues.spline.plist[b])) {
410: if ((t->arrow==startARROW)||(t->arrow==doubleARROW)) {
411: t->arrow -= startARROW;
412: }
413: else {
414: t->arrow += startARROW;
415: }
416: arrow(add(p,t->otherValues.spline.plist[2]),
417: add(p,t->otherValues.spline.plist[1]));
418: }
419: else {
420: if ((t->arrow==endARROW)||(t->arrow==doubleARROW)) {
421: t->arrow -= endARROW;
422: }
423: else {
424: t->arrow += endARROW;
425: }
426: arrow(add(p,t->otherValues.spline.plist[b-2]),
427: add(p,t->otherValues.spline.plist[b-1]));
428: }
429: break;
430: }
431: case 3:
432: case 4: {
433: t = insertReflect(t, p, item, 3);
434: break;
435: }
436: }
437: break;
438: }
439: }
440: if (item == 1) /* copy */ {
441: if (!noSpace) {
442: copyFlag=1;
443: changeButtons(COPYbuttons);
444: }
445: }
446: else {
447: if (item == 0) {
448: /* delete */
449: drawSelectionLines(t,p);
450: t = deleteThing(t,p);
451: thingSelected = 0;
452: copyFlag = 0;
453: changeButtons(INITbuttons);
454: }
455: }
456: return(t);
457: }
458:
459: RUsure ()
460: {
461: int savebuttonstate;
462: int ret;
463:
464: ret = 0;
465: cursswitch (&rusure);
466: savebuttonstate = buttonState;
467: changeButtons (QUITbuttons);
468: while (!button123())
469: jnap(2);
470: if (button3()) {
471: ret = 1;
472: }
473: changeButtons (savebuttonstate);
474: while (button12())
475: jnap(2);
476: cursSwitch();
477: return (ret);
478: }
479:
480: struct thing *
481: displayCommandMenu(h, offset)
482: register struct thing *h;
483: Point offset;
484: {
485: int item;
486: item = menuHit(&commandMenu,3);
487: switch (item) {
488: case GET: {
489: h = doGet(h);
490: break;
491: }
492: case PUT: {
493: doPut(h);
494: break;
495: }
496: case CLEAR: {
497: if (RUsure()) {
498: h = doClear(h);
499: }
500: break;
501: }
502: case DEFINEMACRO: {
503: if (!noSpace) {
504: h = defineMacro(h);
505: }
506: break;
507: }
508: case REDRAW: {
509: doRedraw(h, offset);
510: break;
511: }
512: case QUIT: {
513: if (RUsure()) {
514: exit (0);
515: }
516: break;
517: }
518: case GRID: {
519: gridState = (gridState==GRIDon)?GRIDoff:GRIDon;
520: drawGrid();
521: break;
522: }
523: case FLIPVIDEO: {
524: if (videoState==WHITEfield) {
525: videoState=BLACKfield;
526: rectf (&display, Drect, F_XOR);
527: }
528: else {
529: videoState=WHITEfield;
530: rectf (&display, Drect, F_XOR);
531: }
532: break;
533: }
534: #ifdef DUMP
535: case DUMPIT: {
536: dump (h);
537: break;
538: }
539: #endif
540: }
541: return(h);
542: }
543:
544: doRedraw(h, offset)
545: struct thing *h;
546: Point offset;
547: {
548: register struct thing *t;
549:
550: cursinhibit();
551: xtipple(&display,brushes[PIC]);
552: cursallow();
553: if (gridState==GRIDon) {
554: drawGrid();
555: }
556: if ((t = h) != TNULL) {
557: do {
558: if (t->type==MACRO) BoundingBox(t);
559: draw(t,offset);
560: t = t->next;
561: } while (t != h);
562: }
563: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.