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