|
|
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: editThing(m,p,t)
9: Point m; /* Mouse location */
10: Point p; /* Offset */
11: register struct thing *t; /* Thing to be edited */
12: {
13: register int d,dx,dy,u;
14: Point o, np;
15: if (t != TNULL) {
16: o = t->origin;
17: switch(t->type) {
18: case CIRCLE: {
19: d = norm(o.x-m.x,o.y-m.y,0);
20: if (d< (t->otherValues.radius>>1)) {
21: track(m,p,MOVE,t);
22: }
23: else {
24: track(m,p,GROWCIRCLE,t);
25: }
26: d = t->otherValues.radius;
27: break;
28: }
29: case BOX: {
30: np = t->otherValues.corner;
31: dx = (np.x - o.x)>>2;
32: dy = (np.y - o.y)>>2;
33: if (ptinrect(m,Rect(o.x+dx,o.y+dy,np.x-dx,np.y-dy))) {
34: if (t->boorder != SOLID) {
35: draw(t,p);
36: xbox(raddp(t->bb,p));
37: }
38: t->bb = moveBox(m,t->bb,t,p);
39: t->otherValues.corner = t->bb.corner;
40: t->origin = t->bb.origin;
41: xbox(raddp(t->bb,p));
42: }
43: else {
44: draw(t,p);
45: t->origin.x = 0;
46: t->origin.y = 0;
47: t->bb.origin = t->origin;
48: t->bb.corner = t->origin;
49: t->otherValues.corner = t->origin;
50: if (!ptinrect(m,Rect(o.x-dx,o.y-dy,o.x+dx,o.y-dy))) {
51: if (ptinrect(m,Rect(o.x-dx,np.y-dy,o.x+dx,np.y+dy))) {
52: np.y = o.y;
53: }
54: else {
55: if (ptinrect(m,Rect(np.x-dx,np.y-dy,np.x+dx,np.y+dy))) {
56: np = o;
57: }
58: else {
59: if (ptinrect(m,Rect(np.x-dx,o.y-dy,np.x+dx,o.y+dy))) {
60: np.x = o.x;
61: }
62: }
63: }
64: }
65: o = track(np,p,BOX,t);
66: t->origin.x = min(o.x,np.x);
67: t->origin.y = min(o.y,np.y);
68: t->otherValues.corner.x = max(o.x,np.x);
69: t->otherValues.corner.y = max(o.y,np.y);
70: }
71: break;
72: }
73: case ELLIPSE: {
74: dx = abs(m.x - o.x);
75: dy = abs(m.y - o.y);
76: d = norm(dx,dy,0);
77: if ((dx > dy) && (d > (t->otherValues.ellipse.wid>>2))) {
78: track(m,p,GROWEWID,t);
79: }
80: else {
81: if ((dx < dy) && (d > (t->otherValues.ellipse.ht>>2))) {
82: track(m,p,GROWEHT,t);
83: }
84: else {
85: track(m,p,MOVE,t);
86: }
87: }
88: break;
89: }
90: case LINE: {
91: np=t->otherValues.end;
92: draw(t,p);
93: if (distance(m,o)<distance(m,np)) {
94: t->origin = track(np,p,LINE,t);
95: }
96: else {
97: t->otherValues.end = track(o,p,LINE,t);
98: }
99: break;
100: }
101: case ARC: {
102: d = (distance(o,t->otherValues.arc.start))>>1;
103: if (distance(o,m)<d) {
104: arcOrigin(t,p);
105: }
106: else {
107: if (distance(m,t->otherValues.arc.start)<
108: distance(m,t->otherValues.arc.end)) {
109: arcStart(t,p);
110: }
111: else {
112: arcEnd(t,p);
113: }
114: }
115: break;
116: }
117: case MACRO: {
118: draw(t,p);
119: xbox(raddp(t->bb,p));
120: t->bb = moveBox(m,t->bb,t,p);
121: t->origin = t->bb.origin;
122: xbox(raddp(t->bb,p));
123: break;
124: }
125: case TEXT: {
126: track(m,p,MOVE,t);
127: break;
128: }
129: case SPLINE: {
130: u = t->otherValues.spline.used;
131: d=findNearestPoint(m,t->otherValues.spline.plist,u);
132: if ((t->arrow==startARROW)||(t->arrow==doubleARROW)) {
133: arrow(add(p,t->otherValues.spline.plist[2]),
134: add(p,t->otherValues.spline.plist[1]));
135: }
136: if ((t->arrow==endARROW)||(t->arrow==doubleARROW)) {
137: arrow(add(p,t->otherValues.spline.plist[u-2]),
138: add(p,t->otherValues.spline.plist[u-1]));
139: }
140: if ((d == u-1) || (d==1)) {
141: xsegment
142: (add(p,t->otherValues.spline.plist[(d==1)?1:(d-1)]),
143: add(p,t->otherValues.spline.plist[(d==1)?2:d]));
144: np=track(t->otherValues.spline.plist[(d==1)?2:(d-1)],
145: p,(d==1)?REVLINE:LINE,t); /* See note 1 in track.c */
146: }
147: else {
148: np=track2(p,t->otherValues.spline.plist[d-1],
149: t->otherValues.spline.plist[d+1],
150: t->otherValues.spline.plist[d]);
151: }
152: xspline(p,t->otherValues.spline.plist,u);
153: t->otherValues.spline.plist[d]=np;
154: t->origin=t->otherValues.spline.plist[1];
155: break;
156: }
157: } /* end switch */
158: BoundingBox(t);
159: switch (t->type) {
160: case TEXT:
161: case CIRCLE:
162: case ARC:
163: case ELLIPSE: {
164: break;
165: }
166: default: {
167: draw(t,p);
168: break;
169: }
170: }
171: }
172: }
173:
174: struct thing *
175: copyThing(t,p,offset)
176: register struct thing *t;
177: Point p, offset;
178: {
179: register struct thing *c;
180: Point *pl;
181: int i, n;
182:
183: if (t != TNULL) {
184: switch(t->type) {
185: case CIRCLE: {
186: if ((c = newCircle(p)) != TNULL) {
187: c->otherValues.radius = t->otherValues.radius;
188: }
189: break;
190: }
191: case BOX: {
192: if ((c=newBox(Rpt(p,add(p,sub(t->bb.corner,t->origin)))))
193: != TNULL) {
194: c->boorder = t->boorder;
195: }
196: break;
197: }
198: case ELLIPSE: {
199: if ((c = newEllipse(p)) != TNULL) {
200: c->otherValues = t->otherValues;
201: }
202: break;
203: }
204: case LINE: {
205: if ((c = newLine(p,add(p,sub(t->otherValues.end,t->origin))))
206: != TNULL) {
207: c->boorder = t->boorder;
208: c->arrow = t->arrow;
209: }
210: break;
211: }
212: case ARC: {
213: c = newArc(p,add(p, sub(t->otherValues.arc.end,
214: t->otherValues.arc.start)));
215: break;
216: }
217: case SPLINE: {
218: n = t->otherValues.spline.used;
219: c = TNULL;
220: if ((pl = (Point *) getSpace ((n+2)*sizeof(Point)))
221: != (Point *)NULL){
222: p = sub(p, t->origin);
223: for (i=1; i<=n; i++) {
224: pl[i]=add(p,t->otherValues.spline.plist[i]);
225: }
226: c = newSpline(n,n,pl);
227: }
228: break;
229: }
230: case TEXT: {
231: if ((c = newText(p,t->otherValues.text.s)) != TNULL) {
232: c->otherValues.text.f = t->otherValues.text.f;
233: c->otherValues.text.just = t->otherValues.text.just;
234: }
235: break;
236: }
237: case MACRO: {
238: c = newMacro(p,t->otherValues.list);
239: break;
240: }
241: }
242: if (c == TNULL) {
243: return (c);
244: }
245: BoundingBox(c);
246: draw(c,offset);
247: return(c);
248: }
249: else {
250: return(t);
251: }
252: }
253:
254: /* Returns the index of the point, in plist p, closest to point */
255: /* given by o. */
256:
257: int
258: findNearestPoint(o,p,n)
259: register Point *p; /* Plist of spline points */
260: int n; /* Number of points in Plist */
261: Point o; /* Mouse location */
262: {
263: register int i;
264: int f; /* Plist index to point closest to o */
265: int d; /* Distance between point and o */
266: int mind = -1; /* Minimum distance */
267:
268: if (p != (Point *) NULL) {
269: for (i=1; i<=n; i++) {
270: d = norm(o.x-p[i].x, o.y-p[i].y, 0);
271: if ((mind<0) || (mind>d)) {
272: mind = d;
273: f = i;
274: }
275: }
276: return(f);
277: }
278: else {
279: return(-1);
280: }
281: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.