1 | /* |
---|
2 | * $Id: xcluster.c,v 1.2 1999-01-22 23:15:36 ghudson Exp $ |
---|
3 | * |
---|
4 | * Copyright 1990, 1991 by the Massachusetts Institute of Technology. |
---|
5 | * |
---|
6 | * For copying and distribution information, please see the file |
---|
7 | * <mit-copyright.h>. |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef lint |
---|
12 | static char rcsid[] = |
---|
13 | "$Id: xcluster.c,v 1.2 1999-01-22 23:15:36 ghudson Exp $"; |
---|
14 | #endif /* lint */ |
---|
15 | |
---|
16 | #include "mit-copyright.h" |
---|
17 | #include <stdio.h> |
---|
18 | #include <ctype.h> |
---|
19 | #include <signal.h> |
---|
20 | #include <sys/types.h> |
---|
21 | #include <sys/wait.h> |
---|
22 | #include <sys/time.h> |
---|
23 | #include <sys/resource.h> |
---|
24 | #include <sys/param.h> |
---|
25 | #include <fcntl.h> |
---|
26 | #include <X11/Xlib.h> |
---|
27 | #include <X11/Xutil.h> |
---|
28 | #include <X11/Xatom.h> |
---|
29 | #include <X11/Xmu/WinUtil.h> |
---|
30 | #include <Jets/Jets.h> |
---|
31 | #include <Jets/Window.h> |
---|
32 | #include <Jets/Button.h> |
---|
33 | #include <Jets/Label.h> |
---|
34 | #include <Jets/Form.h> |
---|
35 | #include <Jets/Tree.h> |
---|
36 | #include <Jets/Drawing.h> |
---|
37 | |
---|
38 | #include "xcluster.h" |
---|
39 | #include "points.h" |
---|
40 | |
---|
41 | |
---|
42 | int check_cluster(); |
---|
43 | struct cluster *find_text(); |
---|
44 | |
---|
45 | extern int DEBUG; |
---|
46 | |
---|
47 | Jet root, text, map; |
---|
48 | GC map_gc = NULL; |
---|
49 | int lx = 32767, ly = 32767, hx = 0, hy = 0; |
---|
50 | XPoint *points2 = NULL; |
---|
51 | char *progname; |
---|
52 | char form[BUFSIZ]; |
---|
53 | struct cluster *Current; |
---|
54 | |
---|
55 | int set_auto(); |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | /* |
---|
60 | * These definitions are needed by the tree jet |
---|
61 | */ |
---|
62 | JetClass *jetClasses[] = |
---|
63 | { &treeJetClass, &windowJetClass, &buttonJetClass, &labelJetClass, |
---|
64 | &formJetClass, &drawingJetClass}; |
---|
65 | |
---|
66 | int numJetClasses = XjNumber(jetClasses); |
---|
67 | |
---|
68 | static XrmOptionDescRec opTable[] = { |
---|
69 | {"+rv", "*reverseVideo", XrmoptionNoArg, (caddr_t) "off"}, |
---|
70 | {"-background", "*background", XrmoptionSepArg, (caddr_t) NULL}, |
---|
71 | {"-bd", "*borderColor", XrmoptionSepArg, (caddr_t) NULL}, |
---|
72 | {"-bg", "*background", XrmoptionSepArg, (caddr_t) NULL}, |
---|
73 | {"-bordercolor","*borderColor", XrmoptionSepArg, (caddr_t) NULL}, |
---|
74 | {"-borderwidth","*xclusterWindow.borderWidth", XrmoptionSepArg, |
---|
75 | (caddr_t) NULL}, |
---|
76 | {"-bw", "*xclusterWindow.borderWidth", XrmoptionSepArg, |
---|
77 | (caddr_t) NULL}, |
---|
78 | {"-display", ".display", XrmoptionSepArg, (caddr_t) NULL}, |
---|
79 | {"-fg", "*foreground", XrmoptionSepArg, (caddr_t) NULL}, |
---|
80 | {"-fn", "*font", XrmoptionSepArg, (caddr_t) NULL}, |
---|
81 | {"-font", "*font", XrmoptionSepArg, (caddr_t) NULL}, |
---|
82 | {"-foreground", "*foreground", XrmoptionSepArg, (caddr_t) NULL}, |
---|
83 | {"-geometry", "*xclusterWindow.geometry",XrmoptionSepArg, (caddr_t) NULL}, |
---|
84 | {"-reverse", "*reverseVideo", XrmoptionNoArg, (caddr_t) "on"}, |
---|
85 | {"-rv", "*reverseVideo", XrmoptionNoArg, (caddr_t) "on"}, |
---|
86 | {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL}, |
---|
87 | {"-name", ".name", XrmoptionSepArg, (caddr_t) NULL}, |
---|
88 | {"-appdefs", ".appDefs", XrmoptionSepArg, (caddr_t) NULL}, |
---|
89 | {"-f", ".appDefs", XrmoptionSepArg, (caddr_t) NULL}, |
---|
90 | {"-userdefs", ".userDefs", XrmoptionSepArg, (caddr_t) NULL}, |
---|
91 | {"-inactive", ".inactive", XrmoptionSepArg, (caddr_t) 60}, |
---|
92 | {"-auto", ".auto", XrmoptionSepArg, (caddr_t) 60}, |
---|
93 | {"-circlecolor",".circlecolor", XrmoptionSepArg, (caddr_t) NULL}, |
---|
94 | {"-zoom", ".zoom", XrmoptionNoArg, (caddr_t) "on"}, |
---|
95 | {"-color0", ".color0", XrmoptionSepArg, (caddr_t) NULL}, |
---|
96 | {"-color1", ".color1", XrmoptionSepArg, (caddr_t) NULL}, |
---|
97 | {"-color2", ".color2", XrmoptionSepArg, (caddr_t) NULL}, |
---|
98 | {"-changetime", ".changetime", XrmoptionSepArg, (caddr_t) NULL}, /* s*/ |
---|
99 | {"-steps", ".steps", XrmoptionSepArg, (caddr_t) NULL}, |
---|
100 | {"-steptime", ".steptime", XrmoptionSepArg, (caddr_t) NULL}, /*ms*/ |
---|
101 | }; |
---|
102 | |
---|
103 | typedef struct _MyResources |
---|
104 | { |
---|
105 | int inactive; |
---|
106 | int automatic; |
---|
107 | int ccolor; |
---|
108 | Boolean zoom; |
---|
109 | char *colors[3]; |
---|
110 | int changetime; |
---|
111 | int steps, steptime; |
---|
112 | } MyResources; |
---|
113 | |
---|
114 | typedef struct _MyResources *MyResourcesPtr; |
---|
115 | |
---|
116 | MyResources parms; |
---|
117 | |
---|
118 | #define offset(field) XjOffset(MyResourcesPtr,field) |
---|
119 | |
---|
120 | static XjResource appResources[] = |
---|
121 | { |
---|
122 | { "inactive", "Inactive", XjRInt, sizeof(int), |
---|
123 | offset(inactive), XjRInt, (caddr_t) 0 }, |
---|
124 | { "auto", "Auto", XjRInt, sizeof(int), |
---|
125 | offset(automatic), XjRInt, (caddr_t) 0 }, |
---|
126 | { "circlecolor", XjCForeground, XjRColor, sizeof(int), |
---|
127 | offset(ccolor), XjRString, XjDefaultForeground }, |
---|
128 | { "zoom", "Zoom", XjRBoolean, sizeof(Boolean), |
---|
129 | offset(zoom), XjRBoolean, (caddr_t) 0 }, |
---|
130 | { "color0", "Color", XjRString, sizeof(char *), |
---|
131 | offset(colors[0]), XjRString, (caddr_t) "red green blue" }, |
---|
132 | { "color1", "Color", XjRString, sizeof(char *), |
---|
133 | offset(colors[1]), XjRString, (caddr_t) "green blue red" }, |
---|
134 | { "color2", "Color", XjRString, sizeof(char *), |
---|
135 | offset(colors[2]), XjRString, (caddr_t) "blue red green" }, |
---|
136 | { "changetime", "Changetime", XjRInt, sizeof(int), |
---|
137 | offset(changetime), XjRInt, (caddr_t) 3600 }, |
---|
138 | { "steps", "Steps", XjRInt, sizeof(int), |
---|
139 | offset(steps), XjRInt, (caddr_t) 256 }, |
---|
140 | { "steptime", "Steptime", XjRInt, sizeof(int), |
---|
141 | offset(steptime), XjRInt, (caddr_t) 50 }, |
---|
142 | }; |
---|
143 | |
---|
144 | #undef offset |
---|
145 | |
---|
146 | int div; |
---|
147 | int xleft = 0, yleft = 0; |
---|
148 | struct cluster *circled = NULL; |
---|
149 | Pixmap pixmap_on = (Pixmap) NULL, pixmap_off = (Pixmap) NULL; |
---|
150 | |
---|
151 | int resize(draw, foo, data) |
---|
152 | DrawingJet draw; |
---|
153 | int foo; |
---|
154 | caddr_t data; |
---|
155 | { |
---|
156 | int div_x, div_y; |
---|
157 | int i; |
---|
158 | int width, height; |
---|
159 | |
---|
160 | if (parms.zoom) |
---|
161 | { |
---|
162 | width = hx - lx + 5000; |
---|
163 | height = hy - ly + 5000; |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | width = max_x; |
---|
168 | height = max_y; |
---|
169 | } |
---|
170 | |
---|
171 | div_x = (width / draw->core.width) + 1; |
---|
172 | div_y = (height / draw->core.height) + 1; |
---|
173 | |
---|
174 | div = (div_x > div_y) ? div_x : div_y; |
---|
175 | |
---|
176 | if (parms.zoom) |
---|
177 | { |
---|
178 | if (div == div_y) |
---|
179 | { |
---|
180 | yleft = (2500-ly)/div; |
---|
181 | xleft = -lx/div + ((draw->core.width - (hx - lx)/div) / 2); |
---|
182 | } |
---|
183 | else |
---|
184 | { |
---|
185 | xleft = (2500-lx)/div; |
---|
186 | yleft = -ly/div + ((draw->core.height - (hy - ly)/div) / 2); |
---|
187 | } |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | yleft = (draw->core.height - (max_y/div)) / 2; |
---|
192 | xleft = (draw->core.width - (max_x/div)) / 2; |
---|
193 | } |
---|
194 | |
---|
195 | if (points2 == NULL) |
---|
196 | points2 = (XPoint *) malloc(num_points * sizeof(XPoint)); |
---|
197 | |
---|
198 | for (i=0; i < num_points; i++) |
---|
199 | { |
---|
200 | points2[i].x = points[i].x / div + xleft; |
---|
201 | points2[i].y = points[i].y / div + yleft; |
---|
202 | } |
---|
203 | XClearWindow(XjDisplay(draw), XjWindow(draw)); |
---|
204 | |
---|
205 | if (pixmap_on != (Pixmap) NULL) |
---|
206 | XFreePixmap(XjDisplay(map), pixmap_on); |
---|
207 | if (pixmap_off != (Pixmap) NULL) |
---|
208 | XFreePixmap(XjDisplay(map), pixmap_off); |
---|
209 | pixmap_on = XCreatePixmap(XjDisplay(map), |
---|
210 | XjWindow(map), |
---|
211 | 800/div+2, 800/div+2, |
---|
212 | DefaultDepth(XjDisplay(map), |
---|
213 | DefaultScreen(XjDisplay(map)))); |
---|
214 | pixmap_off = XCreatePixmap(XjDisplay(map), |
---|
215 | XjWindow(map), |
---|
216 | 800/div+2, 800/div+2, |
---|
217 | DefaultDepth(XjDisplay(map), |
---|
218 | DefaultScreen(XjDisplay(map)))); |
---|
219 | circled = NULL; |
---|
220 | |
---|
221 | return 0; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | /* |
---|
227 | * draw_circle draws a circle around a cluster. |
---|
228 | */ |
---|
229 | void draw_circle(c) |
---|
230 | struct cluster *c; |
---|
231 | { |
---|
232 | if (circled != NULL && circled != c && map_gc != NULL) |
---|
233 | { |
---|
234 | XCopyArea(XjDisplay(map), pixmap_off, XjWindow(map), |
---|
235 | ((DrawingJet) map)->drawing.foreground_gc, |
---|
236 | 0, 0, 800/div+2, 800/div+2, |
---|
237 | (circled->x_coord-400)/div+xleft-1, |
---|
238 | (circled->y_coord-400)/div+yleft-1); |
---|
239 | } |
---|
240 | |
---|
241 | if (c != NULL && circled != c && map_gc != NULL) |
---|
242 | { |
---|
243 | XCopyArea(XjDisplay(map), XjWindow(map), pixmap_off, |
---|
244 | ((DrawingJet) map)->drawing.foreground_gc, |
---|
245 | (c->x_coord-400)/div + xleft - 1, |
---|
246 | (c->y_coord-400)/div + yleft - 1, |
---|
247 | 800/div+2, 800/div+2, |
---|
248 | 0, 0); |
---|
249 | XDrawArc(XjDisplay(map), XjWindow(map), map_gc, |
---|
250 | (c->x_coord-400)/div + xleft, |
---|
251 | (c->y_coord-400)/div + yleft, |
---|
252 | 800/div, 800/div, |
---|
253 | 0, 64 * 365); |
---|
254 | XCopyArea(XjDisplay(map), XjWindow(map), pixmap_on, |
---|
255 | ((DrawingJet) map)->drawing.foreground_gc, |
---|
256 | (c->x_coord-400)/div + xleft - 1, |
---|
257 | (c->y_coord-400)/div + yleft - 1, |
---|
258 | 800/div+2, 800/div+2, |
---|
259 | 0, 0); |
---|
260 | /* There's only 360 degrees in a circle, I know, but for the */ |
---|
261 | /* xterminal, we have to go a bit extra. Sigh. */ |
---|
262 | |
---|
263 | XFlush(XjDisplay(map)); |
---|
264 | } |
---|
265 | |
---|
266 | if (map_gc != NULL) |
---|
267 | circled = c; |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | int expos(draw, foo, data) |
---|
273 | DrawingJet draw; |
---|
274 | int foo; |
---|
275 | caddr_t data; |
---|
276 | { |
---|
277 | int i,k; |
---|
278 | struct cluster *c; |
---|
279 | |
---|
280 | k=0; |
---|
281 | for (i=0; i < num_groups; i++) |
---|
282 | { |
---|
283 | XDrawLines(XjDisplay(draw), XjWindow(draw), |
---|
284 | draw->drawing.foreground_gc, |
---|
285 | points2+k, |
---|
286 | num_segs[i], CoordModeOrigin); |
---|
287 | k += num_segs[i]; |
---|
288 | } |
---|
289 | |
---|
290 | /* |
---|
291 | * Draw the cluster locations on the map pixmap. |
---|
292 | */ |
---|
293 | |
---|
294 | if (map_gc == NULL) |
---|
295 | { |
---|
296 | unsigned long valuemask; |
---|
297 | XGCValues values; |
---|
298 | |
---|
299 | values.line_width = 2; |
---|
300 | values.cap_style = CapProjecting; |
---|
301 | values.foreground = parms.ccolor; |
---|
302 | valuemask = GCForeground | GCLineWidth | GCCapStyle; |
---|
303 | |
---|
304 | map_gc = XCreateGC(XjDisplay(draw), XjWindow(draw), valuemask, &values); |
---|
305 | |
---|
306 | valuemask = GCBackground | GCFunction | GCFont; |
---|
307 | XCopyGC(XjDisplay(draw), draw->drawing.foreground_gc, |
---|
308 | valuemask, map_gc); |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | for (c = cluster_list; c != NULL; c = c->next) |
---|
313 | { |
---|
314 | XDrawLine(XjDisplay(draw), XjWindow(draw), map_gc, |
---|
315 | (c->x_coord-100)/div +xleft, (c->y_coord-100)/div +yleft, |
---|
316 | (c->x_coord+100)/div +xleft, (c->y_coord+100)/div +yleft); |
---|
317 | XDrawLine(XjDisplay(draw), XjWindow(draw), map_gc, |
---|
318 | (c->x_coord-100)/div +xleft, (c->y_coord+100)/div +yleft, |
---|
319 | (c->x_coord+100)/div +xleft, (c->y_coord-100)/div +yleft); |
---|
320 | if (c == Current) |
---|
321 | { |
---|
322 | draw_circle(c); |
---|
323 | } |
---|
324 | } |
---|
325 | return 0; |
---|
326 | } |
---|
327 | |
---|
328 | |
---|
329 | |
---|
330 | |
---|
331 | int createTree(fromJet, what, data) |
---|
332 | Jet fromJet; |
---|
333 | char *what; |
---|
334 | caddr_t data; |
---|
335 | { |
---|
336 | if (NULL == XjFindJet(what, root)) |
---|
337 | XjRealizeJet(XjVaCreateJet(what, treeJetClass, root, NULL, NULL)); |
---|
338 | return 0; |
---|
339 | } |
---|
340 | |
---|
341 | |
---|
342 | int mapTree(fromJet, what, data) |
---|
343 | Jet fromJet; |
---|
344 | char *what; |
---|
345 | caddr_t data; |
---|
346 | { |
---|
347 | Jet w; |
---|
348 | |
---|
349 | w = XjFindJet(what, root); |
---|
350 | |
---|
351 | if (w != NULL) |
---|
352 | { |
---|
353 | w = w->core.child; |
---|
354 | while (w) |
---|
355 | { |
---|
356 | MapWindow(w, True); |
---|
357 | w = w->core.sibling; |
---|
358 | } |
---|
359 | return 0; |
---|
360 | } |
---|
361 | else |
---|
362 | { |
---|
363 | char errtext[100]; |
---|
364 | |
---|
365 | sprintf(errtext, "couldn't find %s to map it", what); |
---|
366 | XjWarning(errtext); |
---|
367 | return 1; |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | |
---|
372 | int unmapTree(fromJet, what, data) |
---|
373 | Jet fromJet; |
---|
374 | char *what; |
---|
375 | caddr_t data; |
---|
376 | { |
---|
377 | Jet w; |
---|
378 | |
---|
379 | w = XjFindJet(what, root); |
---|
380 | |
---|
381 | if (w != NULL) |
---|
382 | { |
---|
383 | w = w->core.child; |
---|
384 | while (w) |
---|
385 | { |
---|
386 | UnmapWindow(w); |
---|
387 | w = w->core.sibling; |
---|
388 | } |
---|
389 | return 0; |
---|
390 | } |
---|
391 | else |
---|
392 | { |
---|
393 | char errtext[100]; |
---|
394 | |
---|
395 | sprintf(errtext, "couldn't find %s to unmap it", what); |
---|
396 | XjWarning(errtext); |
---|
397 | return 1; |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | |
---|
402 | int quit(fromJet, what, data) |
---|
403 | caddr_t fromJet; |
---|
404 | int what; |
---|
405 | caddr_t data; |
---|
406 | { |
---|
407 | exit(what); |
---|
408 | return 0; /* For linting... */ |
---|
409 | } |
---|
410 | |
---|
411 | |
---|
412 | fatal(display) |
---|
413 | Display *display; |
---|
414 | { |
---|
415 | exit(-1); |
---|
416 | } |
---|
417 | |
---|
418 | |
---|
419 | int timeout(data, id) |
---|
420 | int data, id; |
---|
421 | { |
---|
422 | exit(0); |
---|
423 | } |
---|
424 | |
---|
425 | void reset_timer() |
---|
426 | { |
---|
427 | static int timerid = -1; |
---|
428 | |
---|
429 | if (parms.inactive != 0) |
---|
430 | { |
---|
431 | if (timerid != -1) |
---|
432 | (void) XjRemoveWakeup(timerid); |
---|
433 | timerid = XjAddWakeup(timeout, 0, 1000 * parms.inactive); |
---|
434 | } |
---|
435 | } |
---|
436 | |
---|
437 | |
---|
438 | void set_curr(c, id) |
---|
439 | struct cluster *c; |
---|
440 | int id; |
---|
441 | { |
---|
442 | static int timerid = -1; |
---|
443 | Current = c; |
---|
444 | |
---|
445 | for(c=cluster_list; c != NULL; c=c->next) |
---|
446 | if (c != Current) |
---|
447 | SetToggleState(c->btn, False, False); |
---|
448 | else |
---|
449 | SetToggleState(c->btn, True, False); |
---|
450 | |
---|
451 | XjCallCallbacks(text, ((DrawingJet) text)->drawing.exposeProc, NULL); |
---|
452 | draw_circle(Current); |
---|
453 | reset_timer(); |
---|
454 | if (parms.automatic != 0) |
---|
455 | { |
---|
456 | if (timerid != -1 && timerid != id) |
---|
457 | (void) XjRemoveWakeup(timerid); |
---|
458 | timerid = XjAddWakeup(set_auto, 0, 1000 * parms.automatic); |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | |
---|
463 | int set_auto(data, id) |
---|
464 | int data, id; |
---|
465 | { |
---|
466 | static struct cluster *automatic = NULL; |
---|
467 | |
---|
468 | if (automatic == NULL) |
---|
469 | automatic = cluster_list; |
---|
470 | |
---|
471 | set_curr(automatic, id); |
---|
472 | automatic = Current->next; |
---|
473 | return 0; |
---|
474 | } |
---|
475 | |
---|
476 | |
---|
477 | int btn(me, curr, data) |
---|
478 | DrawingJet me; |
---|
479 | int curr; |
---|
480 | caddr_t data; |
---|
481 | { |
---|
482 | int n; |
---|
483 | struct cluster *c; |
---|
484 | |
---|
485 | for(c=cluster_list, n=0; c != NULL && n < curr; c=c->next, n++); |
---|
486 | set_curr(c, -1); |
---|
487 | return 0; |
---|
488 | } |
---|
489 | |
---|
490 | int unset(me, curr, data) |
---|
491 | DrawingJet me; |
---|
492 | int curr; |
---|
493 | caddr_t data; |
---|
494 | { |
---|
495 | SetToggleState(me, True, True); |
---|
496 | return(0); |
---|
497 | } |
---|
498 | |
---|
499 | |
---|
500 | |
---|
501 | |
---|
502 | #define SQUARE(a) (a) * (a) /* obvious... */ |
---|
503 | |
---|
504 | |
---|
505 | /* |
---|
506 | * find_cluster finds the closest cluster to point (a,b) and returns it. |
---|
507 | */ |
---|
508 | struct cluster *find_cluster(a, b) |
---|
509 | int a, b; |
---|
510 | { |
---|
511 | double closest_distance, distance; |
---|
512 | struct cluster *closest_cluster, *curr; |
---|
513 | |
---|
514 | closest_cluster = curr = cluster_list; |
---|
515 | closest_distance = SQUARE(curr->x_coord/div + xleft - a) |
---|
516 | + SQUARE(curr->y_coord/div + yleft - b); |
---|
517 | |
---|
518 | for(; curr != NULL; curr=curr->next) |
---|
519 | { |
---|
520 | distance = SQUARE(curr->x_coord/div + xleft - a) |
---|
521 | + SQUARE(curr->y_coord/div + yleft - b); |
---|
522 | if (distance < closest_distance) |
---|
523 | { |
---|
524 | closest_distance = distance; |
---|
525 | closest_cluster = curr; |
---|
526 | } |
---|
527 | } |
---|
528 | return(closest_cluster); |
---|
529 | } |
---|
530 | |
---|
531 | |
---|
532 | int map_hit(me, curr, event) |
---|
533 | DrawingJet me; |
---|
534 | int curr; |
---|
535 | XEvent *event; |
---|
536 | { |
---|
537 | struct cluster *c; |
---|
538 | |
---|
539 | if (event->type == ButtonPress) |
---|
540 | { |
---|
541 | c = find_cluster(event->xbutton.x, event->xbutton.y); |
---|
542 | set_curr(c, -1); |
---|
543 | } |
---|
544 | return 0; |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | int text_resize(draw, foo, data) |
---|
549 | DrawingJet draw; |
---|
550 | int foo; |
---|
551 | caddr_t data; |
---|
552 | { |
---|
553 | XClearWindow(XjDisplay(draw), XjWindow(draw)); |
---|
554 | } |
---|
555 | |
---|
556 | |
---|
557 | int text_hit(me, curr, event) |
---|
558 | DrawingJet me; |
---|
559 | int curr; |
---|
560 | XEvent *event; |
---|
561 | { |
---|
562 | struct cluster *c; |
---|
563 | extern struct cluster *find_text(); |
---|
564 | |
---|
565 | if (event->type == ButtonPress) |
---|
566 | { |
---|
567 | c = find_text(event->xbutton.x, event->xbutton.y); |
---|
568 | set_curr(c, -1); |
---|
569 | } |
---|
570 | return 0; |
---|
571 | } |
---|
572 | |
---|
573 | |
---|
574 | int state = 0; |
---|
575 | |
---|
576 | int flash(data, id) |
---|
577 | int data, id; |
---|
578 | { |
---|
579 | if (circled != NULL) |
---|
580 | { |
---|
581 | if (state) |
---|
582 | XCopyArea(XjDisplay(map), pixmap_on, XjWindow(map), |
---|
583 | ((DrawingJet) map)->drawing.foreground_gc, |
---|
584 | 0, 0, 800/div+2, 800/div+2, |
---|
585 | (circled->x_coord-400)/div+xleft-1, |
---|
586 | (circled->y_coord-400)/div+yleft-1); |
---|
587 | else |
---|
588 | XCopyArea(XjDisplay(map), pixmap_off, XjWindow(map), |
---|
589 | ((DrawingJet) map)->drawing.foreground_gc, |
---|
590 | 0, 0, 800/div+2, 800/div+2, |
---|
591 | (circled->x_coord-400)/div+xleft-1, |
---|
592 | (circled->y_coord-400)/div+yleft-1); |
---|
593 | } |
---|
594 | state = !state; |
---|
595 | (void) XjAddWakeup(flash, 0, 1000); |
---|
596 | return 0; |
---|
597 | } |
---|
598 | |
---|
599 | |
---|
600 | |
---|
601 | XjCallbackRec callbacks[] = |
---|
602 | { |
---|
603 | { "createTree", createTree }, |
---|
604 | { "mapTree", mapTree }, |
---|
605 | { "unmapTree", unmapTree }, |
---|
606 | { "quit", quit }, |
---|
607 | { "resize", resize }, |
---|
608 | { "expose", expos }, |
---|
609 | { "check_cluster", check_cluster }, |
---|
610 | { "button", btn }, |
---|
611 | { "unset", unset }, |
---|
612 | { "map_hit", map_hit }, |
---|
613 | { "text_hit", text_hit }, |
---|
614 | { "text_resize", text_resize }, |
---|
615 | }; |
---|
616 | |
---|
617 | |
---|
618 | void make_btns(Form) |
---|
619 | Jet Form; |
---|
620 | { |
---|
621 | struct cluster *c; |
---|
622 | int n; |
---|
623 | Jet w, l; |
---|
624 | int first = 1; |
---|
625 | char prev[10]; |
---|
626 | char buf[BUFSIZ]; |
---|
627 | char buf1[10]; |
---|
628 | |
---|
629 | for(c=cluster_list, n=0; c != NULL; c=c->next, n++) |
---|
630 | { |
---|
631 | sprintf(buf1, "button%d", n); |
---|
632 | w = XjVaCreateJet(buf1, windowJetClass, Form, NULL, NULL); |
---|
633 | c->btn = (ButtonJet) XjVaCreateJet("foo", buttonJetClass, w, NULL, NULL); |
---|
634 | l = XjVaCreateJet("bar", labelJetClass, c->btn, |
---|
635 | XjNlabel, c->button_name, NULL, NULL); |
---|
636 | |
---|
637 | if (first) |
---|
638 | { |
---|
639 | first = 0; |
---|
640 | sprintf(buf, " %s: 1 - - twin ", buf1); |
---|
641 | } |
---|
642 | else |
---|
643 | sprintf(buf, " %s: %s - - twin ", buf1, prev); |
---|
644 | |
---|
645 | strcpy(prev, buf1); |
---|
646 | strcat(form, buf); |
---|
647 | } |
---|
648 | } |
---|
649 | |
---|
650 | compute_zoom() |
---|
651 | { |
---|
652 | struct cluster *c; |
---|
653 | |
---|
654 | for(c=cluster_list; c != NULL; c=c->next) |
---|
655 | { |
---|
656 | lx = MIN(c->x_coord, lx); |
---|
657 | ly = MIN(c->y_coord, ly); |
---|
658 | hx = MAX(c->x_coord, hx); |
---|
659 | hy = MAX(c->y_coord, hy); |
---|
660 | } |
---|
661 | } |
---|
662 | |
---|
663 | #define MAXCOLORS 3 |
---|
664 | #define MAXCYCLES 15 |
---|
665 | XColor cycles[MAXCOLORS][MAXCYCLES]; |
---|
666 | int cycle, subcycle, numCycles; |
---|
667 | |
---|
668 | void nextcycle() |
---|
669 | { |
---|
670 | int i; |
---|
671 | XColor col; |
---|
672 | |
---|
673 | subcycle++; |
---|
674 | if (subcycle >= parms.steps) |
---|
675 | { |
---|
676 | subcycle = 0; |
---|
677 | cycle++; |
---|
678 | if (cycle == numCycles) |
---|
679 | cycle = 0; |
---|
680 | } |
---|
681 | |
---|
682 | if (parms.changetime != 0 && subcycle == 0) |
---|
683 | (void)XjAddWakeup(nextcycle, 0, parms.changetime * 1000); |
---|
684 | else |
---|
685 | (void)XjAddWakeup(nextcycle, 0, parms.steptime); |
---|
686 | |
---|
687 | for (i = 0; i < MAXCOLORS; i++) |
---|
688 | if (cycles[i][0].pixel != XjNoColor) |
---|
689 | { |
---|
690 | col.pixel = cycles[i][0].pixel; |
---|
691 | col.red = cycles[i][cycle].red + |
---|
692 | (subcycle * (int)( cycles[i][(cycle + 1)%numCycles].red - |
---|
693 | cycles[i][cycle].red ) / parms.steps); |
---|
694 | col.green = cycles[i][cycle].green + |
---|
695 | (subcycle * (int)( cycles[i][(cycle + 1)%numCycles].green - |
---|
696 | cycles[i][cycle].green ) / parms.steps); |
---|
697 | col.blue = cycles[i][cycle].blue + |
---|
698 | (subcycle * (int)( cycles[i][(cycle + 1)%numCycles].blue - |
---|
699 | cycles[i][cycle].blue ) / parms.steps); |
---|
700 | col.flags = DoRed | DoGreen | DoBlue; |
---|
701 | |
---|
702 | XStoreColors(XjDisplay(root), XjColormap(root), &col, 1); |
---|
703 | } |
---|
704 | } |
---|
705 | |
---|
706 | void init_color_cycle() |
---|
707 | { |
---|
708 | int i, j, docycles; |
---|
709 | char name[50], *dest, *src; |
---|
710 | char errtext[100]; |
---|
711 | |
---|
712 | docycles = 0; |
---|
713 | numCycles = 0; |
---|
714 | |
---|
715 | for (i = 0; i < MAXCOLORS; i++) |
---|
716 | for (j = 0; j < MAXCYCLES; j++) |
---|
717 | cycles[i][j].pixel = XjNoColor; |
---|
718 | |
---|
719 | for (i = 0; i < MAXCOLORS; i++) |
---|
720 | if (XjGetColor(i) != XjNoColor) /* a used color */ |
---|
721 | { |
---|
722 | docycles = 1; |
---|
723 | src = parms.colors[i]; |
---|
724 | |
---|
725 | for (j = 0; j < MAXCYCLES; j++) |
---|
726 | { |
---|
727 | while (isspace(*src)) |
---|
728 | src++; |
---|
729 | |
---|
730 | if (*src == '\0') |
---|
731 | { |
---|
732 | if (j == 0) |
---|
733 | { |
---|
734 | sprintf(errtext, "bad specification for color%d", i); |
---|
735 | XjWarning(errtext); |
---|
736 | src = "red"; |
---|
737 | } |
---|
738 | else |
---|
739 | break; |
---|
740 | } |
---|
741 | |
---|
742 | dest = name; |
---|
743 | while (!isspace(*src) && *src != '\0') |
---|
744 | *dest++ = *src++; /* XXX no error checking for > 50 */ |
---|
745 | *dest = '\0'; |
---|
746 | |
---|
747 | if (!XParseColor(XjDisplay(root), XjColormap(root), |
---|
748 | name, &cycles[i][j])) |
---|
749 | { |
---|
750 | sprintf(errtext, "could not look up color \"%s\"", name); |
---|
751 | XjWarning(errtext); |
---|
752 | cycles[i][j].red = 256*255; |
---|
753 | cycles[i][j].green = 0; |
---|
754 | cycles[i][j].blue = 0; |
---|
755 | cycles[i][j].flags = DoRed | DoGreen | DoBlue; |
---|
756 | } |
---|
757 | cycles[i][j].pixel = XjGetColor(i); |
---|
758 | } |
---|
759 | |
---|
760 | numCycles = MAX(numCycles, j); |
---|
761 | } |
---|
762 | |
---|
763 | if (docycles == 0) /* we're not using this feature */ |
---|
764 | return; |
---|
765 | |
---|
766 | for (i = 0; i < MAXCOLORS; i++) |
---|
767 | for (j = 1; j < numCycles; j++) |
---|
768 | if (cycles[i][j].pixel == XjNoColor) |
---|
769 | cycles[i][j] = cycles[i][j-1]; |
---|
770 | |
---|
771 | cycle = 0; |
---|
772 | subcycle = 0; |
---|
773 | |
---|
774 | for (i = 0; i < MAXCOLORS; i++) |
---|
775 | if (cycles[i][0].pixel != XjNoColor) |
---|
776 | XStoreColors(XjDisplay(root), XjColormap(root), &cycles[i][cycle], 1); |
---|
777 | |
---|
778 | if (parms.changetime != 0) |
---|
779 | (void)XjAddWakeup(nextcycle, 0, parms.changetime * 1000); |
---|
780 | else |
---|
781 | (void)XjAddWakeup(nextcycle, 0, parms.steptime); |
---|
782 | } |
---|
783 | |
---|
784 | main(argc, argv) |
---|
785 | int argc; |
---|
786 | char **argv; |
---|
787 | { |
---|
788 | Jet xclusterWindow, xclusterForm, label1, mapwin; |
---|
789 | Jet qw, qb, ql, hw, hb, hl; |
---|
790 | Jet twin; |
---|
791 | |
---|
792 | |
---|
793 | Current = cluster_list; |
---|
794 | |
---|
795 | (void)XSetIOErrorHandler(fatal); |
---|
796 | |
---|
797 | root = XjCreateRoot(&argc, argv, "Xcluster", NULL, |
---|
798 | opTable, XjNumber(opTable)); |
---|
799 | |
---|
800 | XjLoadFromResources(XjDisplay(root), |
---|
801 | XjWindow(root), |
---|
802 | programName, |
---|
803 | programClass, |
---|
804 | appResources, |
---|
805 | XjNumber(appResources), |
---|
806 | (caddr_t) &parms); |
---|
807 | |
---|
808 | progname = programName; |
---|
809 | |
---|
810 | XjRegisterCallbacks(callbacks, XjNumber(callbacks)); |
---|
811 | |
---|
812 | xclusterWindow = XjVaCreateJet("xclusterWindow", |
---|
813 | windowJetClass, root, NULL, NULL); |
---|
814 | xclusterForm = XjVaCreateJet("xclusterForm", |
---|
815 | formJetClass, xclusterWindow, NULL, NULL); |
---|
816 | label1 = XjVaCreateJet("label1", labelJetClass, xclusterForm, NULL, NULL); |
---|
817 | mapwin = XjVaCreateJet("mapwin", windowJetClass, xclusterForm, NULL, NULL); |
---|
818 | map = XjVaCreateJet("map", drawingJetClass, mapwin, NULL, NULL); |
---|
819 | |
---|
820 | qw = XjVaCreateJet("quit", windowJetClass, xclusterForm, NULL, NULL); |
---|
821 | qb = XjVaCreateJet("buttonQuit", buttonJetClass, qw, NULL, NULL); |
---|
822 | ql = XjVaCreateJet("quitLabel", labelJetClass, qb, NULL, NULL); |
---|
823 | |
---|
824 | hw = XjVaCreateJet("help", windowJetClass, xclusterForm, NULL, NULL); |
---|
825 | hb = XjVaCreateJet("buttonHelp", buttonJetClass, hw, NULL, NULL); |
---|
826 | hl = XjVaCreateJet("helpLabel", labelJetClass, hb, NULL, NULL); |
---|
827 | |
---|
828 | twin = XjVaCreateJet("twin", windowJetClass, xclusterForm, NULL, NULL); |
---|
829 | text = XjVaCreateJet("text", drawingJetClass, twin, NULL, NULL); |
---|
830 | |
---|
831 | strcpy(form, |
---|
832 | "label1: 0 1 100 - twin: 0 - 100 100 quit: - - 99 twin \ |
---|
833 | help: - - quit twin mapwin: 1 label1 99 quit"); |
---|
834 | |
---|
835 | read_clusters(); |
---|
836 | |
---|
837 | if (parms.zoom == 1) |
---|
838 | compute_zoom(); |
---|
839 | |
---|
840 | make_btns(xclusterForm); |
---|
841 | |
---|
842 | setForm(xclusterForm, form); |
---|
843 | |
---|
844 | XjRealizeJet(root); |
---|
845 | flash(NULL, NULL); |
---|
846 | reset_timer(); |
---|
847 | |
---|
848 | if (parms.automatic != 0) |
---|
849 | set_auto(0, -1); |
---|
850 | |
---|
851 | init_color_cycle(); |
---|
852 | |
---|
853 | XjEventLoop(root); |
---|
854 | } |
---|