- /* Local Variables */
-
- XGCValues gcv;
- XWindowAttributes xwa;
- sonar_info *si;
- XColor start, end;
- int h1, h2;
- double s1, s2, v1, v2;
-
- /* Create the Sonar information structure */
-
- if ((si = (sonar_info *) calloc(1, sizeof(sonar_info))) == NULL) {
- fprintf(stderr, "%s: Out of memory\n", progname);
- return NULL;
- }
-
- /* Initialize the structure for the current environment */
-
- si->dpy = dpy;
- si->win = win;
- si->visable = NULL;
- XGetWindowAttributes(dpy, win, &xwa);
- si->cmap = xwa.colormap;
- si->width = xwa.width;
- si->height = xwa.height;
- si->centrex = si->width / 2;
- si->centrey = si->height / 2;
- si->maxx = si->centrex + MY_MIN(si->centrex, si->centrey) - 10;
- si->minx = si->centrex - MY_MIN(si->centrex, si->centrey) + 10;
- si->maxy = si->centrey + MY_MIN(si->centrex, si->centrey) - 10;
- si->miny = si->centrey - MY_MIN(si->centrex, si->centrey) + 10;
- si->radius = si->maxx - si->centrex;
- si->current = 0;
- si->sweepnum = 0;
-
- /* Get the font */
-
- if (((si->font = XLoadQueryFont(dpy, get_string_resource ("font", "Font")))
- == NULL) &&
- ((si->font = XLoadQueryFont(dpy, "fixed")) == NULL)) {
- fprintf(stderr, "%s: can't load an appropriate font\n", progname);
- return NULL;
- }
-
- /* Get the delay between animation frames */
-
- si->delay = get_integer_resource ("delay", "Integer");
-
- if (si->delay < 0) si->delay = 0;
- si->TTL = get_integer_resource("ttl", "TTL");
-
- /* Create the Graphics Contexts that will be used to draw things */
-
- gcv.foreground =
- get_pixel_resource ("sweepColor", "SweepColor", dpy, si->cmap);
- 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("scopeColor", "ScopeColor",
- dpy, si->cmap);
- si->erase = XCreateGC (dpy, win, GCForeground, &gcv);
- gcv.foreground = get_pixel_resource("gridColor", "GridColor",
- dpy, si->cmap);
- si->grid = XCreateGC (dpy, win, GCForeground, &gcv);
-
- /* Compute pixel values for fading text on the display */
-
- XParseColor(dpy, si->cmap,
- get_string_resource("textColor", "TextColor"), &start);
- XParseColor(dpy, si->cmap,
- get_string_resource("scopeColor", "ScopeColor"), &end);
-
- 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("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 */
-
- XParseColor(dpy, si->cmap,
- get_string_resource("sweepColor", "SweepColor"), &start);
-
- rgb_to_hsv (start.red, start.green, start.blue, &h1, &s1, &v1);
-
- si->sweep_degrees = get_integer_resource("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("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);
-
- /* Done */