+ XColor start, end;
+ int h1, h2;
+ double s1, s2, v1, v2;
+
+ debug_p = get_boolean_resource (dpy, "debug", "Debug");
+ resolve_p = get_boolean_resource (dpy, "resolve", "Resolve");
+ times_p = get_boolean_resource (dpy, "showTimes", "ShowTimes");
+
+ /* Create the Sonar information structure */
+
+ if ((si = (sonar_info *) calloc(1, sizeof(sonar_info))) == NULL) {
+ fprintf(stderr, "%s: Out of memory\n", progname);
+ exit (1);
+ }
+
+ /* Initialize the structure for the current environment */
+
+ si->dpy = dpy;
+ si->win = win;
+ si->visible = NULL;
+
+ XGetWindowAttributes(dpy, win, &xwa);
+ si->cmap = xwa.colormap;
+
+ si->current = 0;
+ si->sweepnum = 0;
+
+ /* Get the font */
+
+ {
+ char *fn = get_string_resource (dpy, "font", "Font");
+ if (((si->font = XLoadQueryFont(dpy, fn)) == NULL) &&
+ ((si->font = XLoadQueryFont(dpy, "fixed")) == NULL)) {
+ fprintf(stderr, "%s: can't load an appropriate font\n", progname);
+ exit (1);
+ }
+ if (fn) free (fn);
+ }
+
+ /* Get the delay between animation frames */
+
+ si->delay = get_integer_resource (dpy, "delay", "Integer");
+
+ if (si->delay < 0) si->delay = 0;
+ si->TTL = get_integer_resource(dpy, "ttl", "TTL");
+
+ /* Create the Graphics Contexts that will be used to draw things */
+
+ gcv.foreground =
+ get_pixel_resource (dpy, si->cmap, "sweepColor", "SweepColor");
+ si->hi = XCreateGC(dpy, win, GCForeground, &gcv);
+ gcv.font = si->font->fid;
+ si->text = XCreateGC(dpy, win, GCForeground|GCFont, &gcv);
+ gcv.foreground = get_pixel_resource(dpy, si->cmap,
+ "scopeColor", "ScopeColor");
+ si->erase = XCreateGC (dpy, win, GCForeground, &gcv);
+ gcv.foreground = get_pixel_resource(dpy, si->cmap,
+ "gridColor", "GridColor");
+ si->grid = XCreateGC (dpy, win, GCForeground, &gcv);
+
+ reshape (si);
+
+ /* Compute pixel values for fading text on the display */
+ {
+ char *s = get_string_resource(dpy, "textColor", "TextColor");
+ XParseColor(dpy, si->cmap, s, &start);
+ if (s) free (s);
+ s = get_string_resource(dpy, "scopeColor", "ScopeColor");
+ XParseColor(dpy, si->cmap, s, &end);
+ if (s) free (s);
+ }
+
+ rgb_to_hsv (start.red, start.green, start.blue, &h1, &s1, &v1);
+ rgb_to_hsv (end.red, end.green, end.blue, &h2, &s2, &v2);
+
+ si->text_steps = get_integer_resource(dpy, "textSteps", "TextSteps");
+ if (si->text_steps < 0 || si->text_steps > 255)
+ si->text_steps = 10;
+
+ si->text_colors = (XColor *) calloc(si->text_steps, sizeof(XColor));
+ make_color_ramp (dpy, si->cmap,
+ h1, s1, v1,
+ h2, s2, v2,
+ si->text_colors, &si->text_steps,
+ False, True, False);
+
+ /* Compute the pixel values for the fading sweep */
+
+ {
+ char *s = get_string_resource(dpy, "sweepColor", "SweepColor");
+ XParseColor(dpy, si->cmap, s, &start);
+ if (s) free (s);
+ }
+
+ rgb_to_hsv (start.red, start.green, start.blue, &h1, &s1, &v1);
+
+ si->sweep_degrees = get_integer_resource(dpy, "sweepDegrees", "Degrees");
+ if (si->sweep_degrees <= 0) si->sweep_degrees = 20;
+ if (si->sweep_degrees > 350) si->sweep_degrees = 350;
+
+ si->sweep_segs = get_integer_resource(dpy, "sweepSegments", "SweepSegments");
+ if (si->sweep_segs < 1 || si->sweep_segs > 255)
+ si->sweep_segs = 255;
+
+ si->sweep_colors = (XColor *) calloc(si->sweep_segs, sizeof(XColor));
+ make_color_ramp (dpy, si->cmap,
+ h1, s1, v1,
+ h2, s2, v2,
+ si->sweep_colors, &si->sweep_segs,
+ False, True, False);
+
+ if (si->sweep_segs <= 0)
+ si->sweep_segs = 1;