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