home *** CD-ROM | disk | FTP | other *** search
- /*
- * Sunplot - plotter backend for Sun workstation
- *
- * Copyright (c) 1987 by Sjoerd Mullender, Vrije Universiteit, Amsterdam.
- *
- * This program may be redistributed without fee as long as this copyright
- * notice is in tact.
- * Any commercial use is strictly prohibited.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /tmp_mnt/tuintje/ufs1/cl/sjoerd/src/sunplot/RCS/sunplot.c,v 1.5 89/12/08 10:53:15 sjoerd Exp $";
- #endif
-
- #include <stdio.h>
- #include <suntool/sunview.h>
- #include <suntool/scrollbar.h>
- #include <suntool/panel.h>
- #include <suntool/canvas.h>
-
- /*
- * Configurable definitions
- */
- #define INIT_CANVAS_SIZE 512
- #define DEFAULT_SPACE 4096
- #define MAX_NAME_LENGTH 128
-
- /*
- * Unconfigurable definitions
- */
- #define BIG 0x7FFFFFFF
-
- #define FORMAT_RASTER 0
- #define FORMAT_ICON 1
- #define FORMAT_PLOT 2
-
- #define LABEL 0
- #define SQUARE 1
- #define REVERSE 2
-
- int client_object; /* used for notifier */
- int *me = &client_object; /* idem */
-
- int curx, cury; /* current position on plot */
- int lox, loy, hix = DEFAULT_SPACE, hiy = DEFAULT_SPACE; /* current space */
- int slox, shix, sloy, shiy; /* saved space settings for zooming */
- int minx, maxx, miny, maxy; /* minimum and maximum values encountered */
- int hor_size, ver_size; /* canvas size */
- int turned, xmirror, ymirror; /* orientation of plot */
- int zooming;
- int make_label = TRUE; /* print labels */
- int square = TRUE; /* canvas is square */
- int reverse = FALSE; /* reverse video */
- int dirty;
- Frame frame, dump_frame, options_frame;
- Panel panel, dump_panel, options_panel;
- Panel_item next_page_item;
- Panel_item hor_size_item, ver_size_item, toggle_item, font_item;
- Panel_item dump_format, dump_file_item;
- Canvas canvas;
- Pixwin *pw;
- Pixfont *font;
- char font_name[MAX_NAME_LENGTH];
- char font_dir[] = "/usr/lib/fonts/fixedwidthfonts/";
- Pr_texture texture;
- Pr_brush brush = {1};
-
- short sunplot_icon_image[] = {
- #include "sunplot.icon"
- };
- mpr_static(sunplot_icon, 64, 64, 1, sunplot_icon_image);
-
- char *malloc(), *realloc();
-
- /*
- * input module
- */
-
- static char *plotcommands, *plptr;
- static int plotlength;
- static int maxplotlength;
- static int eof_seen;
-
- getchr()
- {
- register c;
-
- if (plptr < plotcommands + plotlength)
- return *plptr++ & 0xFF;
- if (eof_seen || (c = getchar()) == EOF) {
- eof_seen = 1;
- return EOF;
- }
- if (plotlength >= maxplotlength) {
- plotcommands = realloc(plotcommands, maxplotlength *= 2);
- plptr = plotcommands + plotlength;
- }
- *plptr++ = c;
- plotlength++;
- return c;
- }
-
- getint()
- {
- register n;
-
- n = getchr();
- n = n | getchr() << 8;
- if (n & 0x8000) /* sign extend */
- n |= ~0x7FFF;
- return n;
- }
-
- char *getstr()
- {
- register i = plptr - plotcommands;
- register c;
-
- while ((c = getchr()) != EOF && c != '\0' && c != '\n')
- ;
- plptr[-1] = 0;
- return plotcommands + i;
- }
-
- /*
- * plot module
- */
-
- #define point(x,y) pw_put(pw, plotx(x, y), ploty(x, y), !reverse)
-
- #if 0
- #define line(x0,y0,x1,y1) pw_vector(pw,plotx(x0,y0),ploty(x0,y0),plotx(x1,y1),ploty(x1,y1),PIX_SRC,!reverse)
- #else
- #define line(x0,y0,x1,y1) pw_line(pw,plotx(x0,y0),ploty(x0,y0),plotx(x1,y1),ploty(x1,y1),&brush,&texture,reverse?PIX_CLR:PIX_SET)
- #endif
-
- #define convx(x,s) (((x) - lox) * (s) / (hix - lox))
- #define convy(y,s) (((y) - loy) * (s) / (hiy - loy))
-
- initplot()
- {
- plptr = plotcommands = malloc(maxplotlength = 1024);
- plotlength = 0;
- }
-
- plotx(x, y)
- {
- register a;
-
- switch (turned) {
- case 0: a = convx(x, hor_size); break;
- case 1: a = hor_size - 1 - convy(y, hor_size); break;
- case 2: a = hor_size - 1 - convx(x, hor_size); break;
- case 3: a = convy(y, hor_size); break;
- }
- return xmirror ? hor_size - 1 - a : a;
- }
-
- ploty(x, y)
- {
- register a;
-
- switch (turned) {
- case 0: a = ver_size - 1 - convy(y, ver_size); break;
- case 1: a = ver_size - 1 - convx(x, ver_size); break;
- case 2: a = convy(y, ver_size); break;
- case 3: a = convx(x, ver_size); break;
- }
- a = ymirror ? ver_size - 1 - a : a;
- return zooming ? a+1 : a;
- }
-
- label(s)
- char *s;
- {
- struct pr_size pr_size;
-
- if (!make_label)
- return 0;
- pw_text(pw, plotx(curx, cury), ploty(curx, cury), reverse ? PIX_NOT(PIX_SRC)&PIX_DST : PIX_SRC|PIX_DST, font, s);
- pr_size = pf_textwidth(strlen(s), font, s);
- return pr_size.x * (hix - lox) / hor_size;
- }
-
- linemod(s)
- char *s;
- {
- static short dotted[] = {1,5,0};
- static short solid[] = {1,0};
- static short longdashed[] = {10,6,0};
- static short shortdashed[] = {5,3,0};
- static short dotdashed[] = {7,3,1,3,0};
-
- if (strcmp(s, "dotted") == 0) {
- texture.pattern = dotted;
- } else if (strcmp(s, "solid") == 0) {
- texture.pattern = solid;
- } else if (strcmp(s, "longdashed") == 0) {
- texture.pattern = longdashed;
- } else if (strcmp(s, "shortdashed") == 0) {
- texture.pattern = shortdashed;
- } else if (strcmp(s, "dotdashed") == 0) {
- texture.pattern = dotdashed;
- }
- }
-
- isqrt(n)
- {
- int a, b, c;
-
- a = n;
- b = n;
- if (n > 1) {
- while (a > 0) {
- a = a >> 2;
- b = b >> 1;
- }
- do {
- a = b;
- c = n / b;
- b = (c + a) >> 1;
- } while ((a - c) < -1 || (a - c) > 1);
- }
- return b;
- }
-
- static setcir(x, y, a1, b1, c1, a2, b2, c2)
- {
- if (a1 * y - b1 * x >= c1 && a2 * y - b2 * x <= c2)
- point(x, y);
- }
-
- arc(x, y, x1, y1, x2, y2)
- {
- register a1 = x1 - x, b1 = y1 - y, a2 = x2 - x, b2 = y2 - y;
- register c1 = a1 * y - b1 * x, c2 = a2 * y - b2 * x;
- register r2 = a1 * a1 + b1 * b1;
- register i, di, sqrt, dx, dy;
-
- dx = (hix - lox) / hor_size;
- dy = (hiy - loy) / ver_size;
- di = dx < dy ? dx : dy;
- if (di <= 0)
- di = 1;
- for (i = isqrt(r2 >> 1); i >= 0; i -= di) {
- sqrt = isqrt(r2 - i * i);
- setcir(x + i, y + sqrt, a1, b1, c1, a2, b2, c2);
- setcir(x + i, y - sqrt, a1, b1, c1, a2, b2, c2);
- setcir(x - i, y + sqrt, a1, b1, c1, a2, b2, c2);
- setcir(x - i, y - sqrt, a1, b1, c1, a2, b2, c2);
- setcir(x + sqrt, y + i, a1, b1, c1, a2, b2, c2);
- setcir(x + sqrt, y - i, a1, b1, c1, a2, b2, c2);
- setcir(x - sqrt, y + i, a1, b1, c1, a2, b2, c2);
- setcir(x - sqrt, y - i, a1, b1, c1, a2, b2, c2);
- }
- }
-
- circle(x, y, r)
- {
- arc(x, y, x + r, y, x - r, y);
- arc(x, y, x - r, y, x + r, y);
- }
-
- Notify_value input_reader(me, fd)
- int *me;
- int fd;
- {
- int newx, newy, x, y, r;
- register char *p;
-
- do {
- switch (getchr()) {
- case 'm': /* move */
- dirty = 1;
- curx = getint();
- cury = getint();
- if (curx < minx) minx = curx;
- if (curx > maxx) maxx = curx;
- if (cury < miny) miny = cury;
- if (cury > maxy) maxy = cury;
- break;
- case 'n': /* cont */
- dirty = 1;
- newx = getint();
- newy = getint();
- line(curx, cury, newx, newy);
- curx = newx;
- cury = newy;
- if (curx < minx) minx = curx;
- if (curx > maxx) maxx = curx;
- if (cury < miny) miny = cury;
- if (cury > maxy) maxy = cury;
- break;
- case 'p': /* point */
- dirty = 1;
- curx = getint();
- cury = getint();
- point(curx, cury);
- if (curx < minx) minx = curx;
- if (curx > maxx) maxx = curx;
- if (cury < miny) miny = cury;
- if (cury > maxy) maxy = cury;
- break;
- case 'l': /* line */
- dirty = 1;
- newx = getint();
- newy = getint();
- curx = getint();
- cury = getint();
- line(newx, newy, curx, cury);
- if (newx < minx) minx = newx;
- if (newx > maxx) maxx = newx;
- if (newy < miny) miny = newy;
- if (newy > maxy) maxy = newy;
- if (curx < minx) minx = curx;
- if (curx > maxx) maxx = curx;
- if (cury < miny) miny = cury;
- if (cury > maxy) maxy = cury;
- break;
- case 't': /* label */
- dirty = 1;
- p = getstr();
- curx += label(p);
- plptr[-1] = '\n';
- if (curx < minx) minx = curx;
- if (curx > maxx) maxx = curx;
- break;
- case 'a': /* arc */
- dirty = 1;
- x = getint();
- y = getint();
- newx = getint();
- newy = getint();
- curx = getint();
- cury = getint();
- arc(x, y, newx, newy, curx, cury);
- if (x < minx) minx = x;
- if (x > maxx) maxx = x;
- if (y < miny) miny = y;
- if (y > maxy) maxy = y;
- if (newx < minx) minx = newx;
- if (newx > maxx) maxx = newx;
- if (newy < miny) miny = newy;
- if (newy > maxy) maxy = newy;
- if (curx < minx) minx = curx;
- if (curx > maxx) maxx = curx;
- if (cury < miny) miny = cury;
- if (cury > maxy) maxy = cury;
- break;
- case 'c': /* circle */
- dirty = 1;
- curx = getint();
- cury = getint();
- r = getint();
- circle(curx, cury, r);
- if (curx - r < minx) minx = curx - r;
- if (curx + r > maxx) maxx = curx + r;
- if (cury - r < miny) miny = cury - r;
- if (cury + r > maxy) maxy = cury + r;
- break;
- case 'e': /* erase */
- if (!dirty)
- break;
- panel_set(next_page_item, PANEL_SHOW_ITEM, TRUE, 0);
- /* fall through */
- case EOF:
- notify_set_input_func(me, NOTIFY_FUNC_NULL, fd);
- if (zooming) {
- lox = slox;
- hix = shix;
- loy = sloy;
- hiy = shiy;
- zooming = 0;
- }
- return NOTIFY_DONE;
- case 'f': /* linemod */
- dirty = 1;
- p = getstr();
- linemod(p);
- plptr[-1] = '\n';
- break;
- case 's': /* space */
- if (zooming) {
- slox = getint();
- sloy = getint();
- shix = getint();
- shiy = getint();
- } else {
- lox = getint();
- loy = getint();
- hix = getint();
- hiy = getint();
- }
- break;
- }
- } while (plptr < plotcommands + plotlength || stdin->_cnt > 0);
- return NOTIFY_DONE;
- }
-
- /*
- * button routines
- */
-
- restartplot()
- {
- dirty = 0;
- minx = BIG;
- maxx = -BIG;
- miny = BIG;
- maxy = -BIG;
- plptr = plotcommands;
-
- /* clear the canvas */
- pw_writebackground(pw, 0, 0, (int) window_get(canvas, CANVAS_WIDTH),
- (int) window_get(canvas, CANVAS_HEIGHT),
- reverse ? PIX_SET : PIX_CLR);
- }
-
- resetplot()
- {
- restartplot();
- plotlength = 0;
- }
-
- void redraw()
- {
- if (zooming) {
- lox = slox;
- hix = shix;
- loy = sloy;
- hiy = shiy;
- zooming = 0;
- }
- restartplot();
- input_reader(me, fileno(stdin));
- }
-
- void nextpage()
- {
- resetplot();
- panel_set(next_page_item, PANEL_SHOW_ITEM, FALSE, 0);
- notify_set_input_func(me, input_reader, fileno(stdin));
- if (stdin->_cnt > 0)
- input_reader(me, fileno(stdin));
- }
-
- void zoom()
- {
- int a;
-
- if (!zooming) {
- slox = lox;
- shix = hix;
- sloy = loy;
- shiy = hiy;
- zooming = 1;
- }
- if (maxx == minx) {
- maxx++;
- minx--;
- }
- if (maxy == miny) {
- maxy++;
- miny--;
- }
- if ((a = (maxx-minx) * (shiy-sloy) / (shix-slox)) >= maxy-miny) {
- loy = miny - (a - maxy + miny) / 2;
- hiy = loy + a;
- lox = minx;
- hix = maxx;
- } else {
- a = (maxy - miny) * (shix - slox) / (shiy - sloy);
- lox = minx - (a - maxx + minx) / 2;
- hix = lox + a;
- loy = miny;
- hiy = maxy;
- }
- hix++;
- hiy++;
- restartplot();
- input_reader(me, fileno(stdin));
- }
-
- void quit()
- {
- /* don't ask for confirmation */
- if (font)
- pf_close(font);
- window_set(frame, FRAME_NO_CONFIRM, TRUE, 0);
- window_destroy(frame);
- }
-
- void turn()
- {
- int tmp;
-
- turned = (turned + 1) & 3;
- tmp = xmirror;
- xmirror = ymirror;
- ymirror = tmp;
- }
-
- void mirrorx()
- {
- xmirror ^= 1;
- }
-
- void mirrory()
- {
- ymirror ^= 1;
- }
-
- void canvas_fit()
- {
- register int w, h;
-
- w = (int) window_get(canvas, WIN_WIDTH) - (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_VERTICAL_SCROLLBAR), SCROLL_THICKNESS);
- h = (int) window_get(canvas, WIN_HEIGHT) - (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_HORIZONTAL_SCROLLBAR), SCROLL_THICKNESS);
- if ((int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE)) {
- if (w < h)
- h = w;
- else
- w = h;
- }
- panel_set(hor_size_item, PANEL_VALUE, w, 0);
- panel_set(ver_size_item, PANEL_VALUE, h, 0);
- }
-
- /*
- * initialization
- */
-
- void toggle_proc()
- {
- if ((int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE)) {
- panel_set(ver_size_item,
- PANEL_SHOW_ITEM, FALSE,
- 0);
- panel_set(hor_size_item,
- PANEL_LABEL_STRING, "Canvas size: ",
- 0);
- } else {
- panel_set(ver_size_item,
- PANEL_SHOW_ITEM, TRUE,
- 0);
- panel_set(hor_size_item,
- PANEL_LABEL_STRING, "Horizontal size: ",
- 0);
- }
- }
-
- void options()
- {
- window_set(options_frame, WIN_SHOW, TRUE, 0);
- }
-
- void apply_options()
- {
- register int r;
- char *f;
- Cursor cursor;
-
- square = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, SQUARE);
- r = (int) panel_get(hor_size_item, PANEL_VALUE);
- if (r != hor_size) {
- window_set(canvas, CANVAS_WIDTH, r, 0);
- hor_size = r;
- }
- if (square)
- r = hor_size;
- else
- r = (int) panel_get(ver_size_item, PANEL_VALUE);
- if (r != ver_size) {
- window_set(canvas, CANVAS_HEIGHT, r, 0);
- ver_size = r;
- }
- f = (char *) panel_get_value(font_item);
- if (f == 0 || *f == 0) {
- if (font_name[0] != 0) {
- font_name[0] = 0;
- if (font)
- pf_close(font);
- font = pf_default();
- }
- } else {
- if (font_name[0] == 0 || strcmp(f, font_name) != 0) {
- strcpy(font_name, f);
- f = font_name;
- if (*f != '/') {
- f = malloc(strlen(font_dir)+strlen(font_name)+1);
- strcpy(f, font_dir);
- strcat(f, font_name);
- }
- if (font)
- pf_close(font);
- font = pf_open(f);
- if (f != font_name)
- free(f);
- }
- }
- if (font == 0) {
- font_name[0] = 0;
- font = pf_default();
- }
- make_label = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, LABEL);
- reverse = (int) panel_get(toggle_item, PANEL_TOGGLE_VALUE, REVERSE);
- cursor = (Cursor) window_get(canvas, WIN_CURSOR);
- cursor_set(cursor,
- CURSOR_OP, reverse ? PIX_SRC^PIX_DST : PIX_SRC|PIX_DST,
- 0);
- window_set(canvas, WIN_CURSOR, cursor, 0);
- redraw();
- }
-
- void options_done()
- {
- window_set(options_frame, WIN_SHOW, FALSE, 0);
- apply_options();
- }
-
- void dump()
- {
- window_set(dump_frame, WIN_SHOW, TRUE, 0);
- }
-
- void do_dump()
- {
- char *file;
- int width, height;
- register int x, y;
- register char *s;
- register short *p;
- FILE *f;
-
- /* we use the fact that the canvas is retained */
- file = (char *) panel_get_value(dump_file_item);
- if (file != 0 && *file != 0 && (f = fopen(file, "w")) != 0) {
- width = (int) window_get(canvas, CANVAS_WIDTH);
- height = (int) window_get(canvas, CANVAS_HEIGHT);
- switch ((int) panel_get_value(dump_format)) {
- case FORMAT_RASTER:
- pr_dump(pw->pw_prretained, f, (colormap_t *) 0,
- RT_STANDARD, 0);
- break;
- case FORMAT_ICON:
- p = mpr_d(pw->pw_prretained)->md_image;
- fprintf(f, "\
- /* Format_version=1, Width=%d, Height=%d, Depth=1, Valid_bits_per_item=16\n\
- */\n", (width+15) & ~15, height);
- for (y = 0; y < height; y++) {
- s = "\t";
- for (x = 0; x < width; x += 16) {
- fprintf(f, "%s0x%04x,", s, *p & 0xFFFF);
- p++;
- s = "";
- }
- fprintf(f, "\n");
- }
- break;
- case FORMAT_PLOT:
- fwrite(plotcommands, 1, plotlength, f);
- break;
- }
- fclose(f);
- }
- }
-
- void dump_done()
- {
- window_set(dump_frame, WIN_SHOW, FALSE, 0);
- }
-
- void fit_screen()
- {
- register int w, h;
-
- w = hor_size + (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_VERTICAL_SCROLLBAR), SCROLL_THICKNESS);
- h = ver_size + (int) scrollbar_get((Scrollbar) window_get(canvas, WIN_HORIZONTAL_SCROLLBAR), SCROLL_THICKNESS);
- window_set(canvas, WIN_WIDTH, w, WIN_HEIGHT, h, 0);
- window_set(canvas, CANVAS_WIDTH, hor_size, CANVAS_HEIGHT, ver_size, 0);
- window_set(panel, WIN_WIDTH, w, 0);
- window_fit(frame);
- }
-
- /*
- * initialization
- */
-
- void dump_init()
- {
- register Pixrect *pr;
-
- dump_frame = window_create(frame, FRAME,
- FRAME_DONE_PROC, dump_done,
- 0);
- dump_panel = window_create(dump_frame, PANEL, 0);
- pr = panel_button_image(dump_panel, "Done", 0, (Pixfont *) 0);
- (void) panel_create_item(dump_panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, pr,
- PANEL_NOTIFY_PROC, dump_done,
- 0);
- pr = panel_button_image(dump_panel, "Dump", 0, (Pixfont *) 0);
- (void) panel_create_item(dump_panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, pr,
- PANEL_NOTIFY_PROC, do_dump,
- 0);
- /* order of strings is important (see definitions of FORMAT_*) */
- dump_format = panel_create_item(dump_panel, PANEL_CYCLE,
- PANEL_LABEL_STRING, "Dump format:",
- PANEL_CHOICE_STRINGS, "Rasterfile format",
- "Icon format",
- "Plot format",
- (char *) 0,
- 0);
- dump_file_item = panel_create_item(dump_panel, PANEL_TEXT,
- PANEL_LABEL_X, ATTR_COL(0),
- PANEL_LABEL_Y, ATTR_ROW(1),
- PANEL_VALUE_DISPLAY_LENGTH, 30,
- PANEL_LABEL_STRING, "Dump to file:",
- 0);
- window_fit(dump_panel);
- window_fit(dump_frame);
- }
-
- void options_init()
- {
- register Pixrect *pr;
-
- options_frame = window_create(frame, FRAME,
- FRAME_DONE_PROC, options_done,
- 0);
- options_panel = window_create(options_frame, PANEL, 0);
-
- pr = panel_button_image(options_panel, "Done", 0, (Pixfont *) 0);
- (void) panel_create_item(options_panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, pr,
- PANEL_NOTIFY_PROC, options_done,
- 0);
- pr = panel_button_image(options_panel, "Apply", 0, (Pixfont *) 0);
- (void) panel_create_item(options_panel, PANEL_BUTTON,
- PANEL_LABEL_IMAGE, pr,
- PANEL_NOTIFY_PROC, apply_options,
- 0);
- pr = panel_button_image(options_panel, "Rotate", 0, (Pixfont*) 0);
- (void) panel_create_item(options_panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, turn,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(options_panel, "X Mirror", 0, (Pixfont*) 0);
- (void) panel_create_item(options_panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, mirrorx,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(options_panel, "Y Mirror", 0, (Pixfont*) 0);
- (void) panel_create_item(options_panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, mirrory,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(options_panel, "Fit Canvas", 0, (Pixfont*) 0);
- (void) panel_create_item(options_panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, canvas_fit,
- PANEL_LABEL_IMAGE, pr,
- 0);
- toggle_item = panel_create_item(options_panel, PANEL_TOGGLE,
- PANEL_LAYOUT, PANEL_HORIZONTAL,
- PANEL_CHOICE_STRINGS, "Label",
- "Square",
- "Reverse",
- (char *) 0,
- PANEL_TOGGLE_VALUE, LABEL, make_label,
- PANEL_TOGGLE_VALUE, SQUARE, square,
- PANEL_TOGGLE_VALUE, REVERSE, reverse,
- PANEL_NOTIFY_PROC, toggle_proc,
- 0);
- font_item = panel_create_item(options_panel, PANEL_TEXT,
- PANEL_VALUE_DISPLAY_LENGTH, 51,
- PANEL_VALUE_STORED_LENGTH, MAX_NAME_LENGTH,
- PANEL_LABEL_STRING, "Font name:",
- PANEL_VALUE, font_name,
- 0);
- hor_size_item = panel_create_item(options_panel, PANEL_SLIDER,
- PANEL_LABEL_STRING, "Horizontal size: ",
- PANEL_VALUE, hor_size,
- PANEL_MIN_VALUE, 64,
- PANEL_MAX_VALUE, 2048,
- PANEL_SLIDER_WIDTH, 225,
- 0);
- ver_size_item = panel_create_item(options_panel, PANEL_SLIDER,
- PANEL_LABEL_STRING, "Vertical size: ",
- PANEL_VALUE, ver_size,
- PANEL_MIN_VALUE, 64,
- PANEL_MAX_VALUE, 2048,
- PANEL_SLIDER_WIDTH, 225,
- 0);
- window_fit(options_panel);
- window_fit(options_frame);
- if (square) {
- panel_set(ver_size_item,
- PANEL_SHOW_ITEM, FALSE,
- 0);
- panel_set(hor_size_item,
- PANEL_LABEL_STRING, "Canvas size: ",
- 0);
- }
- }
-
- void panel_init()
- {
- register Pixrect *pr;
-
- panel = window_create(frame, PANEL, 0);
- pr = panel_button_image(panel, "Next Page", 0, (Pixfont *) 0);
- next_page_item = panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, nextpage,
- PANEL_LABEL_IMAGE, pr,
- PANEL_SHOW_ITEM, FALSE,
- 0);
- pr = panel_button_image(panel, "Redraw", 0, (Pixfont *) 0);
- (void) panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, redraw,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(panel, "Zoom", 0, (Pixfont *) 0);
- (void) panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, zoom,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(panel, "Options", 0, (Pixfont *) 0);
- (void) panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, options,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(panel, "Dump", 0, (Pixfont *) 0);
- (void) panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, dump,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(panel, "Fit Screen", 0, (Pixfont *) 0);
- (void) panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, fit_screen,
- PANEL_LABEL_IMAGE, pr,
- 0);
- pr = panel_button_image(panel, "Quit", 0, (Pixfont *) 0);
- (void) panel_create_item(panel, PANEL_BUTTON,
- PANEL_NOTIFY_PROC, quit,
- PANEL_LABEL_IMAGE, pr,
- 0);
- window_fit_height(panel);
- }
-
- canvas_init()
- {
- canvas = window_create(frame, CANVAS,
- CANVAS_AUTO_SHRINK, FALSE,
- CANVAS_WIDTH, hor_size,
- CANVAS_HEIGHT, ver_size,
- CANVAS_RETAINED, TRUE,
- WIN_VERTICAL_SCROLLBAR, scrollbar_create(0),
- WIN_HORIZONTAL_SCROLLBAR, scrollbar_create(0),
- 0);
- pw = canvas_pixwin(canvas);
- }
-
- usage(cmd)
- char *cmd;
- {
- fprintf(stderr, "\
- %s recognizes the following options:\n\
- \t-c canvas-size\t\t(set size of canvas)\n\
- \t-h horizontal-size\t(set horizontal size of canvas)\n\
- \t-v vertical-size\t(set vertical size of canvas)\n\
- \t-f font-name\t\t(use specified font for labels)\n\
- \t-r\t\t\t(rotate 90 degrees)\n\
- \t-x\t\t\t(mirror in x axis)\n\
- \t-y\t\t\t(mirror in y axis)\n\
- \t-l\t\t\t(don't print labels)\n\
- \t-s\t\t\t(don't force canvas to be square)\n\
- \t-R\t\t\t(display in reverse video)\n\
- ", cmd);
- exit(1);
- }
-
- main(argc, argv)
- char **argv;
- {
- Cursor cursor;
- register c;
- extern char *optarg;
-
- initplot();
-
- hor_size = ver_size = INIT_CANVAS_SIZE;
- frame = window_create(NULL, FRAME,
- FRAME_LABEL, "Sunplot",
- FRAME_SUBWINDOWS_ADJUSTABLE, FALSE,
- FRAME_ICON, icon_create(ICON_IMAGE, &sunplot_icon, 0),
- FRAME_ARGC_PTR_ARGV, &argc, argv,
- 0);
- while ((c = getopt(argc, argv, "c:h:v:lsRrxyf:")) != EOF) {
- switch (c) {
- case 'c':
- hor_size = atoi(optarg);
- if (hor_size < 64)
- hor_size = 64;
- ver_size = hor_size;
- square = TRUE;
- break;
- case 'h':
- hor_size = atoi(optarg);
- if (hor_size < 64)
- hor_size = 64;
- square = FALSE;
- break;
- case 'v':
- ver_size = atoi(optarg);
- if (ver_size < 64)
- ver_size = 64;
- square = FALSE;
- break;
- case 'l':
- make_label = !make_label;
- break;
- case 's':
- square = !square;
- break;
- case 'R':
- reverse = !reverse;
- break;
- case 'r':
- turn();
- break;
- case 'x':
- mirrorx();
- break;
- case 'y':
- mirrory();
- break;
- case 'f':
- strcpy(font_name, optarg);
- break;
- default:
- usage(argv[0]);
- /*NOTREACHED*/
- }
- }
- dump_init();
- options_init();
- panel_init();
- canvas_init();
- if (font_name[0]) {
- register char *f = font_name;
-
- if (*f != '/') {
- f = malloc(strlen(font_dir)+strlen(font_name)+1);
- strcpy(f, font_dir);
- strcat(f, font_name);
- }
- font = pf_open(f);
- if (f != font_name)
- free(f);
- }
- if (font == 0) {
- font = pf_default();
- font_name[0] = 0;
- }
-
- fit_screen();
-
- notify_set_input_func(me, input_reader, fileno(stdin));
-
- linemod("solid");
- restartplot();
- cursor = (Cursor) window_get(canvas, WIN_CURSOR);
- cursor_set(cursor,
- CURSOR_OP, reverse ? PIX_SRC^PIX_DST : PIX_SRC|PIX_DST,
- 0);
- window_set(canvas, WIN_CURSOR, cursor, 0);
-
- window_main_loop(frame);
-
- exit(0);
- }
-