argv%turnpike@Sun.COM (Dan Heller) (03/06/90)
Submitted-by: Brian Smith <bvsmith@lbl.gov> Posting-number: Volume 6, Issue 20 Archive-name: xfig2/part12 #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # If this archive is complete, you will see the following message at the end: # "End of archive 12 (of 15)." # Contents: xfig/arc.c xfig/cursor.c xfig/deletept.c xfig/geom.c # xfig/msgsw.c xfig/popup.c xfig/printfonts.c xfig/save.c # xfig/spline.c # Wrapped by argv@turnpike on Wed Feb 28 10:53:24 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'xfig/arc.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/arc.c'\" else echo shar: Extracting \"'xfig/arc.c'\" \(5265 characters\) sed "s/^X//" >'xfig/arc.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "alloc.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X X#define PI 3.14159 X Xextern int foreground_color, background_color; Xextern int fix_x, fix_y, cur_x, cur_y; X Xextern int autoforwardarrow_mode, autobackwardarrow_mode; Xextern int cur_line_style, line_thickness; Xextern float cur_styleval; Xextern int cur_color; Xextern int cur_areafill; Xextern int fill_mode; Xextern float cur_dashlength; Xextern int num_point; Xextern int DEBUG; Xextern F_compound objects; X Xextern freehand_elasticline(); Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); Xextern null_proc(); Xextern set_popupmenu(); X XF_pos point[3]; X X create_arcobject(); X get_arcpoint(); X init_arc_drawing(); X Xarc_drawing_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_arc_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_arc_drawing(x, y) Xint x, y; X{ X num_point = 0; X point[num_point].x = fix_x = cur_x = x; X point[num_point++].y = fix_y = cur_y = y; X canvas_locmove_proc = freehand_elasticline; /* in line.c */ X canvas_leftbut_proc = get_arcpoint; X canvas_middlebut_proc = create_arcobject; X draw_elasticline(); /* in line.c */ X set_temp_cursor(&null_cursor); X set_action_on(); X } X Xget_arcpoint(x, y) Xint x, y; X{ X if (x == fix_x && y == fix_y) return; X X if (num_point == 2) X { X create_arcobject(x, y); X return; X } X draw_elasticline(); /* in line.c */ X cur_x = x; cur_y = y; X draw_elasticline(); /* in line.c */ X point[num_point].x = fix_x = x; X point[num_point++].y = fix_y = y; X draw_elasticline(); /* in line.c */ X } X Xcreate_arcobject(lx, ly) Xint lx, ly; X{ X extern F_arrow *forward_arrow(), *backward_arrow(); X F_arc *arc; X int x, y, i; X float xx, yy; X X draw_elasticline(); X cur_x = lx; cur_y = ly; X draw_elasticline(); /* in line.c */ X if (num_point == 1) { X arc_drawing_selected(); X return; X } X else if (num_point == 2) { X point[num_point].x = lx; X point[num_point++].y = ly; X } X X x = point[0].x; y = point[0].y; X for (i = 1; i < num_point; i++) { X pw_vector(canvas_pixwin, x, y, point[i].x, point[i].y, INV_PAINT, X 1); X x = point[i].x; y = point[i].y; X } X if (num_point < 3) { X arc_drawing_selected(); X return; X } X if (! compute_arccenter(point[0], point[1], point[2], &xx, &yy)) { X arc_drawing_selected(); X return; X } X Arc_malloc(arc); X if (arc == NULL) { X blink_msg(); X put_msg(Err_mem); X arc_drawing_selected(); X return; X } X arc->type = T_3_POINTS_ARC; X arc->style = cur_line_style; X arc->thickness = line_thickness; X arc->style_val = cur_styleval; X arc->pen = NULL; X /* added 3/1/89 B.V.Smith */ X arc->area_fill = fill_mode? cur_areafill : 0; X arc->color = cur_color; X arc->depth = 0; X arc->direction = compute_direction(point[0], point[1], point[2]); X if (autoforwardarrow_mode) X arc->for_arrow = forward_arrow(); X else X arc->for_arrow = NULL; X if (autobackwardarrow_mode) X arc->back_arrow = backward_arrow(); X else X arc->back_arrow = NULL; X arc->center.x = xx; X arc->center.y = yy; X arc->point[0].x = point[0].x; X arc->point[0].y = point[0].y; X arc->point[1].x = point[1].x; X arc->point[1].y = point[1].y; X arc->point[2].x = point[2].x; X arc->point[2].y = point[2].y; X arc->next = NULL; X pw_batch_on(canvas_pixwin); X draw_arc(arc, foreground_color); X if (DEBUG) { X int xmin, ymin, xmax, ymax; X arc_bound(arc, &xmin, &ymin, &xmax, &ymax); X draw_rectbox(xmin, ymin, xmax, ymax, PAINT, 1); X } X pw_batch_off(canvas_pixwin); X clean_up(); X set_action_object(F_CREATE, O_ARC); X insert_arc(&objects.arcs, arc); X set_latestarc(arc); X set_modifiedflag(); X arc_drawing_selected(); X } X X#define round(x) ((int)((x) + .5)) X Xdraw_arc(a, op) XF_arc *a; Xint op; X{ X extern int foreground_color, background_color; X X curve(canvas_pixwin, round(a->point[0].x - a->center.x), X round(a->center.y - a->point[0].y), X round(a->point[2].x - a->center.x), X round(a->center.y - a->point[2].y), X a->direction, 1, 1, X round(a->center.x), round(a->center.y), op, X a->thickness, a->area_fill); X draw_arcarrow(a, op); X } X Xdraw_arcarrow(a, op) XF_arc *a; Xint op; X{ X int x, y; X X if (a->for_arrow) { X compute_normal(a->center.x, a->center.y, a->point[2].x, X a->point[2].y, a->direction, &x, &y); X if (op == foreground_color) X draw_arrow(x, y, a->point[2].x, a->point[2].y, X a->for_arrow, PAINT); X else X draw_arrow(x, y, a->point[2].x, a->point[2].y, X a->for_arrow, ERASE); X } X if (a->back_arrow) { X compute_normal(a->center.x, a->center.y, a->point[0].x, X a->point[0].y, a->direction ^ 1, &x, &y); X if (op == foreground_color) X draw_arrow(x, y, a->point[0].x, a->point[0].y, X a->back_arrow, PAINT); X else X draw_arrow(x, y, a->point[0].x, a->point[0].y, X a->back_arrow, ERASE); X } X } END_OF_FILE if test 5265 -ne `wc -c <'xfig/arc.c'`; then echo shar: \"'xfig/arc.c'\" unpacked with wrong size! fi # end of 'xfig/arc.c' fi if test -f 'xfig/cursor.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/cursor.c'\" else echo shar: Extracting \"'xfig/cursor.c'\" \(5400 characters\) sed "s/^X//" >'xfig/cursor.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "paintop.h" X Xstatic u_int arrow_cursor_array[8] = { X 0xC000E000, 0xF000F800, 0xFC00F000, 0x90001800, X 0x18000C00, 0x0C000600, 0x06000300, 0x03000100 }; Xmpr_static(arrow_cursor_pr, 16, 16, 1, arrow_cursor_array); XCURSORREC arrow_cursor = { 0, 0, MERGE, &arrow_cursor_pr }; X Xstatic short bull_cursor_array[16] = { X 0x0F00,0x30C0,0x4020,0x4020,0x8010,0x8610,0x8610,0x8010, X 0x4020,0x4020,0x30C0,0x0F00,0x0000,0x0000,0x0000,0x0000 X }; Xmpr_static(bull_cursor_pr, 16, 16, 1, bull_cursor_array); XCURSORREC bull_cursor = { 5, 5, INV_PAINT, &bull_cursor_pr }; X Xstatic u_int buster_cursor_array[8] = { X 0x0FE01010, 0x20085004, 0x88028402, 0x82028102, X 0x80828042, 0x80224014, 0x20081010, 0x0FE00000, }; Xmpr_static(buster_cursor_pr, 16, 16, 1, buster_cursor_array); XCURSORREC buster_cursor = { 7, 7, MERGE, &buster_cursor_pr }; X Xstatic short char_cursor_data[16] = { X 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, X 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, 0xFF00, X }; Xmpr_static(char_cursor_pr, 16, 16, 1, char_cursor_data); XCURSORREC char_cursor = { 0, 13, INV_PAINT, &char_cursor_pr }; X Xstatic short crosshair_cursor_data[16] = { X 0x1000, 0x1000, 0x1000, 0xFE00, 0x1000, 0x1000, 0x1000, 0x0000, X 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, X }; Xmpr_static(crosshair_cursor_pr, 16, 16, 1, crosshair_cursor_data); XCURSORREC crosshair_cursor = { 3, 3, INV_PAINT, &crosshair_cursor_pr }; X XCURSORREC null_cursor = { 0, 0, MERGE, 0 }; X Xstatic short magnifier_cursor_array[16] = { X 0x0F80, 0x3060, 0x4010, 0x4010, 0x8008, 0x8008, 0x8008, 0x8008, X 0x8008, 0x4010, 0x4010, 0x3078, 0x0F9C, 0x000E, 0x0007, 0x0003, X }; Xmpr_static(magnifier_cursor_pr, 16, 16, 1, magnifier_cursor_array); XCURSORREC magnifier_cursor = { 6, 6, MERGE, &magnifier_cursor_pr }; X Xstatic short pencil_cursor_array[16] = { X 0x0000, 0x0018, 0x0024, 0x0075, 0x009B, 0x0117, 0x022E, 0x045C, X 0x08B8, 0x1170, 0x22E0, 0x25C0, 0x7B80, 0x6700, 0x8600, 0x0800, X }; Xmpr_static(pencil_cursor_pr, 16, 16, 1, pencil_cursor_array); XCURSORREC pencil_cursor = { 0, 14, MERGE, &pencil_cursor_pr }; X Xstatic u_int pick15_cursor_array[8] = { X 0x0FE01010, 0x20084004, 0x80028002, 0x80028002, X 0x80028002, 0x80024004, 0x20081010, 0x0FE00000, }; Xmpr_static(pick15_cursor_pr, 16, 16, 1, pick15_cursor_array); XCURSORREC pick15_cursor = { 7, 7, MERGE, &pick15_cursor_pr }; X Xstatic short pick9_cursor_array[16] = { X 0x3E00, 0x4100, 0x8080, 0x8080, 0x8080, 0x8080, 0x8080, 0x4100, X 0x3E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, X }; Xmpr_static(pick9_cursor_pr, 16, 16, 1, pick9_cursor_array); XCURSORREC pick9_cursor = { 4, 4, MERGE, &pick9_cursor_pr }; X Xstatic short vbar_cursor_array[16] = { X 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, X 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, X }; Xmpr_static(vbar_cursor_pr, 16, 16, 1, vbar_cursor_array); XCURSORREC vbar_cursor = { 0, 13, INV_PAINT, &vbar_cursor_pr }; X Xstatic u_int wait_cursor_array[8] = { X 0xFFE04040, 0x40403F80, 0x3F801F00, 0x0E000400, X 0x0A001100, 0x20802080, 0x40404040, 0xFFE00000, }; Xmpr_static(wait_cursor_pr, 16, 16, 1, wait_cursor_array); XCURSORREC wait_cursor = { 7, 5, MERGE, &wait_cursor_pr }; X XCURSOR cur_cursor = &arrow_cursor; /* current cursor */ X Xinit_cursor() X{ X register Display *d = tool_d; X X arrow_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_left_ptr); X bull_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_circle); X buster_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_pirate); X char_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_question_arrow); X crosshair_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_crosshair); X null_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_tcross); X magnifier_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_question_arrow); X pencil_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_pencil); X pick15_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_dotbox); X pick9_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_hand1); X vbar_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_xterm); X wait_cursor.bitmap = (XImage *)XCreateFontCursor(d, XC_watch); X} Xrecolor_cursors() X{ X register Display *d = tool_d; X X XRecolorCursor(d, (Cursor)arrow_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)bull_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)buster_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)char_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)crosshair_cursor.bitmap, &x_fg_color, X &x_bg_color); X XRecolorCursor(d, (Cursor)null_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)magnifier_cursor.bitmap, &x_fg_color, X &x_bg_color); X XRecolorCursor(d, (Cursor)pencil_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)pick15_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)pick9_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)vbar_cursor.bitmap, &x_fg_color, &x_bg_color); X XRecolorCursor(d, (Cursor)wait_cursor.bitmap, &x_fg_color, &x_bg_color); X} END_OF_FILE if test 5400 -ne `wc -c <'xfig/cursor.c'`; then echo shar: \"'xfig/cursor.c'\" unpacked with wrong size! fi # end of 'xfig/cursor.c' fi if test -f 'xfig/deletept.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/deletept.c'\" else echo shar: Extracting \"'xfig/deletept.c'\" \(5987 characters\) sed "s/^X//" >'xfig/deletept.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X X#define TOLERANCE 3 X Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); Xextern null_proc(); Xextern set_popupmenu(); X Xextern F_line *line_point_search(); Xextern F_spline *spline_point_search(); Xextern int last_object; Xextern int fix_x, fix_y, cur_x, cur_y; Xextern int pointmarker_shown; X Xextern F_point *left_point, *right_point; Xextern F_point *deleted_point; Xextern F_line *line; Xextern F_spline *spline; X X init_delete_point(); X Xdelete_point_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_delete_point; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&pick9_cursor); X reset_action_on(); X } X Xinit_delete_point(x, y) Xint x, y; X{ X F_spline *spline; X F_line *line; X F_point *p, *q; X int n; X X /* X If the attemp to delete point fails, we wouldn't want any important X variables (left_point, right_point and delted_point) to change. X So we used p and q in the search. X */ X X if ((line = line_point_search(x, y, TOLERANCE, &p, &q)) != NULL) { X if (line->type == T_BOX || line->type == T_ARC_BOX) { X put_msg("Deleting box corners is not allowed"); X return; X } X n = num_points(line->points); X if (line->type == T_POLYGON) { X if (n <= 4) { X put_msg("A polygon cannot have less than 3 points"); X return; X } X } X else if (n <= 1) { X put_msg("A line cannot have less than 2 points"); X return; X } X clean_up(); X left_point = p; X deleted_point = q; X right_point = q->next; X linepoint_deleting(line); X set_action_object(F_DELETE_POINT, O_POLYLINE); X set_latestline(line); X } X else if ((spline=spline_point_search(x, y, TOLERANCE, &p, &q)) != NULL){ X n = num_points(spline->points); X if (closed_spline(spline)) { X if (n <= 4) { X put_msg("A closed spline cannot have less than 3 points"); X return; X } X } X else if (normal_spline(spline)) { X if (n <= 1) { X put_msg("A spline cannot have less than 2 points"); X return; X } X } X else if (n <= 2) { /* it must be an interpolated spline */ X put_msg("An interpolated spline may have less than 3 points"); X return; X } X clean_up(); X left_point = p; X deleted_point = q; X right_point = q->next; X splinepoint_deleting(spline); X set_action_object(F_DELETE_POINT, O_SPLINE); X set_latestspline(spline); X } X } X X/************************** spline *******************************/ X Xsplinepoint_deleting(spline) XF_spline *spline; X{ X F_point *p; X X set_temp_cursor(&wait_cursor); X if (closed_spline(spline)) { X pw_batch_on(canvas_pixwin); X if (pointmarker_shown) toggle_splinepointmarker(spline); X draw_spline(spline, ERASE); /*erase the spline */ X if (left_point == NULL) { X /* The deleted point is the first point */ X spline->points = right_point; X for (left_point = right_point, p = left_point->next; X p->next != NULL; X left_point = p, p = p->next); X /* X left_point now points at next to last point X (the last point is a copy of the first). X */ X p->x = spline->points->x; X p->y = spline->points->y; X right_point = p; X /* X Right_point becomes the last point. If this operation X (point deletion) is reversed (undo), the deleted_point X will not be inserted into it original place, but will X be between left_point and right_point. X */ X } X else X left_point->next = right_point; X } X else { /* open spline */ X pw_batch_on(canvas_pixwin); X if (pointmarker_shown) toggle_splinepointmarker(spline); X draw_spline(spline, ERASE); /*erase the spline */ X if (left_point == NULL) X spline->points = right_point; X else X left_point->next = right_point; X } X if (int_spline(spline)) { X F_control *c; X X c = spline->controls; X spline->controls = c->next; X c->next = NULL; X free((char*)c); X remake_control_points(spline); X } X draw_spline(spline, PAINT); X if (pointmarker_shown) toggle_splinepointmarker(spline); X pw_batch_off(canvas_pixwin); X set_modifiedflag(); X reset_cursor(); X } X X/*************************** line ********************************/ X X/* XIn deleting a point p, linepoint_deleting uses left_point and Xright_point of point p. The relationship of the three points Xare : left_point->p->right_point except when p is the first Xpoint in the list, in which case left_point will be NULL. X*/ Xlinepoint_deleting(line) XF_line *line; X{ X F_point *p; X X if (line->type == T_POLYGON) { X if (pointmarker_shown) toggle_linepointmarker(line); X draw_line(line, ERASE); /*erase the line */ X if (left_point == NULL) { X /* The deleted point is the first point */ X line->points = right_point; X for (left_point = right_point, p = left_point->next; X p->next != NULL; X left_point = p, p = p->next); X /* X left_point now points at next to last point X (the last point is a copy of the first). X */ X p->x = right_point->x; X p->y = right_point->y; X right_point = p; X /* X Right_point becomes the last point. If this operation X (point deletion) is reversed (undo), the deleted_point X will not be inserted into it original place, but will X be between left_point and right_point. X */ X } X else X left_point->next = right_point; X } X else { /* polyline */ X if (pointmarker_shown) toggle_linepointmarker(line); X draw_line(line, ERASE); /*erase the line */ X if (left_point == NULL) X line->points = right_point; X else X left_point->next = right_point; X } X draw_line(line, PAINT); X if (pointmarker_shown) toggle_linepointmarker(line); X set_modifiedflag(); X } END_OF_FILE if test 5987 -ne `wc -c <'xfig/deletept.c'`; then echo shar: \"'xfig/deletept.c'\" unpacked with wrong size! fi # end of 'xfig/deletept.c' fi if test -f 'xfig/geom.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/geom.c'\" else echo shar: Extracting \"'xfig/geom.c'\" \(4668 characters\) sed "s/^X//" >'xfig/geom.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * March 1988. X * X * %W% %G% X*/ X#include "fig.h" X#include "object.h" X X#define PI 3.14159 X#define round(x) ((int)((x) + .5)) X X/* XInput arguments : X (x1,y1)(x2,y2) : the vector X direction : direction of the normal vector to (x1,y1)(x2,y2) XOutput arguments : X (*x,*y)(x2,y2) : a normal vector. XReturn value : none X*/ X Xcompute_normal(x1, y1, x2, y2, direction, x, y) Xfloat x1, y1; Xint x2, y2, direction, *x, *y; X{ X if (direction) { /* counter clockwise */ X *x = round(x2 - (y2 - y1)); X *y = round(y2 - (x1 - x2)); X } X else { X *x = round(x2 + (y2 - y1)); X *y = round(y2 + (x1 - x2)); X } X } X X/* XInput arguments: X (x1,y1)(x2,y2) : the vector X (xp,yp) : the point X d : tolerance (max. allowable distance from the point to the vector) X dd : d * d XOutput arguments: X (*px,*py) : a point on the vector which is not far from (xp,yp) X by more than d. Normally the vector (*px,*py)(xp,yp) X is normal to vector (x1,y1)(x2,y2) except when (xp,yp) X is within d from (x1,y1) or (x2,y2), in which cases, X (*px,*py) = (x1,y1) or (x2,y2) respectively. XReturn value : X 0 : No point on the vector is within d from (xp, yp) X 1 : (*px, *py) is such a point. X*/ X Xclose_to_vector(x1, y1, x2, y2, xp, yp, d, dd, px, py) Xint x1, y1, x2, y2, xp, yp, d; Xfloat dd; Xint *px, *py; X{ X int xmin, ymin, xmax, ymax; X float x, y, slope, D2, dx, dy; X X if (abs(xp - x1) <= d && abs(yp - y1) <= d) { X *px = x1; *py = y1; X return(1); X } X if (abs(xp - x2) <= d && abs(yp - y2) <= d) { X *px = x2; *py = y2; X return(1); X } X X if (x1 < x2) { X xmin = x1 - d; xmax = x2 + d; X } X else { X xmin = x2 - d; xmax = x1 + d; X } X if (xp < xmin || xmax < xp) return(0); X X if (y1 < y2) { X ymin = y1 - d; ymax = y2 + d; X } X else { X ymin = y2 - d; ymax = y1 + d; X } X if (yp < ymin || ymax < yp) return(0); X X if (x2 == x1) { X x = x1; y = yp; X } X else if (y1 == y2) { X x = xp; X y = y1; X } X else { X slope = ((float) (x2 - x1)) / ((float) (y2 - y1)); X y = (slope * (xp - x1 + slope * y1) + yp) / (1 + slope * slope); X x = ((float) x1) + slope * (y - y1); X } X dx = ((float) xp) - x; X dy = ((float) yp) - y; X D2 = dx * dx + dy * dy; X if (D2 < dd) { X *px = (int)(x + .5); *py = (int)(y +.5); X return(1); X } X return(0); X } X X/* XInput arguments : X p1, p2, p3 : 3 points on the arc XOutput arguments : X (*x,*y) : Center of the arc XReturn value : X 0 : if p1, p2, p3 are co-linear. X 1 : if they are not. X*/ X Xint Xcompute_arccenter(p1, p2, p3, x, y) XF_pos p1, p2, p3; Xfloat *x, *y; X{ X float s12, s13, len1, len2, len3, dx12, dy12, dx13, dy13; X X dx12 = p1.x - p2.x; dy12 = p1.y - p2.y; X dx13 = p1.x - p3.x; dy13 = p1.y - p3.y; X s12 = asin((double)(dy12 / sqrt((double)(dx12*dx12 + dy12*dy12)))); X s13 = asin((double)(dy13 / sqrt((double)(dx13*dx13 + dy13*dy13)))); X if (fabs(s12 - s13) < .01) return(0); X X len1 = p1.x * p1.x + p1.y * p1.y; X len2 = p2.x * p2.x + p2.y * p2.y; X len3 = p3.x * p3.x + p3.y * p3.y; X *y = (dx12 * (len3 - len1) - dx13 * (len2 - len1)) / X (2 * (dx13 * dy12 - dx12 * dy13)); X if (dx13 != 0) X *x = (len3 + 2 * (*y) * dy13 - len1) / (2 * (-dx13)); X else X *x = (len2 + 2 * (*y) * dy12 - len1) / (2 * (-dx12)); X return(1); X } X X/* XCompute_angle XInput arguments : X (dx,dy) : the vector (0,0)(dx,dy) XOutput arguments : none XReturn value : the angle of the vector in the range [0, 2PI) X*/ X Xfloat Xcompute_angle(dx, dy) /* compute the angle between 0 to 2PI */ Xfloat dx, dy; X{ X float alpha; X X if (dx == 0) { X if (dy > 0) X alpha = PI / 2; X else X alpha = 3 * PI / 2; X } X else if (dy == 0) { X if (dx > 0) X alpha = 0; X else X alpha = PI; X } X else { X alpha = atan((double)(dy / dx)); /* range = -PI/2 to PI/2 */ X if (dx < 0) alpha += PI; X else if (dy < 0) alpha += 2 * PI; X } X return(alpha); X } X X/* XInput arguments : X p1, p2, p3 : 3 points of an arc with p1 the first and p3 the last. XOutput arguments : none XReturn value : X 0 : if the arc passes p1, p2 and p3 (in that order) in X clockwise direction X 1 : if direction is counterclockwise X*/ X Xint Xcompute_direction(p1, p2, p3) XF_pos p1, p2, p3; X{ X float diff, dx, dy, alpha, theta; X X dx = p2.x - p1.x; X dy = p1.y - p2.y; /* because origin of the screen is on X the upper left corner */ X X alpha = compute_angle(dx, dy); X X dx = p3.x - p2.x; X dy = p2.y - p3.y; X theta = compute_angle(dx, dy); X X diff = theta - alpha; X if ((0 < diff && diff < PI) || diff < -PI) { X return(1); /* counterclockwise */ X } X return(0); /* clockwise */ X } END_OF_FILE if test 4668 -ne `wc -c <'xfig/geom.c'`; then echo shar: \"'xfig/geom.c'\" unpacked with wrong size! fi # end of 'xfig/geom.c' fi if test -f 'xfig/msgsw.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/msgsw.c'\" else echo shar: Extracting \"'xfig/msgsw.c'\" \(3980 characters\) sed "s/^X//" >'xfig/msgsw.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * 2nd revision : Feb 1988. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "const.h" X#include "font.h" X#include "paintop.h" X#include "psfonts.h" X Xextern int errno; Xextern int receiving_msg; Xextern int action_on; Xextern null_proc(); X Xextern int CANVAS_WIDTH; Xextern int PANEL_WID; Xextern int SIDERULER_WIDTH; Xextern char prefix[], suffix[]; Xextern int leng_prefix, leng_suffix; Xextern int cur_x, cur_y; X Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); X X/***************** exported variables and procedures *****************/ X X put_msg(); X init_msgreceiving(); X X/************************ local variables and routines ******************/ X X#define BUF_SIZE 80 X Xstatic (*msgsw_kbd_proc)(); Xstatic (*msgsw_leftbut_proc)(); Xstatic (*msgsw_rightbut_proc)(); Xstatic (*recipient)(); X Xstatic char msg_received[BUF_SIZE]; Xstatic char prompt[BUF_SIZE]; Xstatic int len_prompt; Xstatic int input_base_x; X Xstatic msg_selected(); Xstatic msg_sighandler(); X Xstatic (*saved_canvas_kbd_proc)(); Xstatic (*saved_canvas_locmove_proc)(); Xstatic (*saved_canvas_leftbut_proc)(); Xstatic (*saved_canvas_middlebut_proc)(); Xstatic (*saved_canvas_rightbut_proc)(); X Xstatic Arg msg_args[] = X{ X /* 0 */ { XtNx, (XtArgVal)0 }, X /* 1 */ { XtNy, (XtArgVal)0 }, X /* 2 */ { XtNwidth, (XtArgVal)0 }, X /* 3 */ { XtNheight, (XtArgVal)MSG_HEIGHT }, X /* 4 */ { XtNlabel, (XtArgVal)"" }, X /* 5 */ { XtNfromHoriz, (XtArgVal)NULL }, X /* 6 */ { XtNhorizDistance, (XtArgVal) 2 }, X /* 7 */ { XtNfromVert, (XtArgVal)NULL }, X /* 8 */ { XtNvertDistance, (XtArgVal) 1 }, X /* 9 */ { XtNleft, (XtArgVal) XtChainLeft }, X /*10 */ { XtNinput, (XtArgVal) TRUE }, /* doesn't seem to work for DECwindows */ X}; X Xint init_msg(tool) X TOOL tool; X{ X msg_args[2].value = PANEL_WID+CANVAS_WIDTH+SIDERULER_WIDTH-FONT_PANE_WIDTH; X msg_args[5].value = (XtArgVal)psfont; /* right edge of font ind. */ X msg_args[7].value = (XtArgVal)canvas_sw; /* just below the canvas */ X msg_sw = XtCreateManagedWidget("message", commandWidgetClass, tool, X msg_args, XtNumber(msg_args)); X return (1); X} X X/* X** We have to do this after realizing the widget otherwise X** the width is computed wrong and you get a tiny text box. X*/ Xsetup_msg() X{ X static Arg addn_args[] = X { X { XtNfont, (XtArgVal)NULL }, X }; X X if (bold_font != NULL) X { X addn_args[0].value = (XtArgVal)bold_font; X XtSetValues(msg_sw, addn_args, XtNumber(addn_args)); X } X msgswfd = XtWindow(msg_sw); X XDefineCursor(tool_d, msgswfd, (Cursor)pencil_cursor.bitmap); X} X X/*VARARGS1*/ Xput_msg(format, arg1, arg2, arg3, arg4, arg5) X char *format; X int arg1, arg2, arg3, arg4, arg5; X{ X sprintf(prompt, format, arg1, arg2, arg3, arg4, arg5); X msg_args[4].value = (XtArgVal)prompt; X XtSetValues(msg_sw, &msg_args[4], 1); X} X Xclear_message() X{ X msg_args[4].value = (XtArgVal)""; X XtSetValues(msg_sw, &msg_args[4], 1); X} X Xstatic Xend_char_input() X{ X receiving_msg = 0; /* msg input has been received */ X terminate_char_handler(); X strcpy(&prefix[leng_prefix], suffix); X strcpy(msg_received, prefix); X strcpy(&prompt[len_prompt], prefix); X if (recipient != NULL) (* recipient) (msg_received); X restore_event_proc(); X return; X } X Xinit_msg_receiving(msg_recipient, p) X int (*msg_recipient)(); X char *p; X{ X char reply[100]; X X prompt_string(p, reply); X (*msg_recipient)(reply); X} X Xrestore_event_proc() X{ X canvas_kbd_proc = saved_canvas_kbd_proc; X canvas_locmove_proc = saved_canvas_locmove_proc; X canvas_leftbut_proc = saved_canvas_leftbut_proc; X canvas_middlebut_proc = saved_canvas_middlebut_proc; X canvas_rightbut_proc = saved_canvas_rightbut_proc; X } X Xblink_msg() X{ X int i; X X for (i = 0; i < 2000; i++) X ; X clear_message(); X } END_OF_FILE if test 3980 -ne `wc -c <'xfig/msgsw.c'`; then echo shar: \"'xfig/msgsw.c'\" unpacked with wrong size! fi # end of 'xfig/msgsw.c' fi if test -f 'xfig/popup.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/popup.c'\" else echo shar: Extracting \"'xfig/popup.c'\" \(6300 characters\) sed "s/^X//" >'xfig/popup.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "func.h" X#include "font.h" X X/******************* imported global variables and procedures **************/ X Xextern int figure_modified; Xextern char current_file[]; X Xextern put_msg(); Xextern init_msg_receiving(); Xextern read_file(); Xextern edit_file(); Xextern change_directory(); Xextern save_current_file(); Xextern save_file(); Xextern save_and_exit(); Xextern write_bitmap(); X X/******************** local variables ***************************/ X Xstatic MENUITEM pumenu_items[] = { X {MENU_IMAGESTRING, "Quit", (caddr_t) F_QUIT}, X {MENU_IMAGESTRING, "Undo", (caddr_t) F_UNDO}, X {MENU_IMAGESTRING, "Redisplay", (caddr_t) F_REDISPLAY}, X {MENU_IMAGESTRING, "Remove all", (caddr_t) F_REMOVE_ALL}, X {MENU_IMAGESTRING, "Edit file ...", (caddr_t) F_EDIT}, X {MENU_IMAGESTRING, "Save", (caddr_t) F_SAVE}, X {MENU_IMAGESTRING, "Read file ...", (caddr_t) F_READ}, X {MENU_IMAGESTRING, "Save in ...", (caddr_t) F_SAVE_IN}, X {MENU_IMAGESTRING, "Print Figure", (caddr_t) F_PRINT}, X {MENU_IMAGESTRING, "Status", (caddr_t) F_STATUS}, X {MENU_IMAGESTRING, "Change Directory", (caddr_t) F_CHDIR}, X {MENU_IMAGESTRING, "Print Working Directory", (caddr_t) F_PWDIR}, X {MENU_IMAGESTRING, "Save & Quit", (caddr_t) F_SAVE_N_EXIT}, X /* X {MENU_IMAGESTRING, "Save as BITMAP ..", (caddr_t) F_SAVE_BITMAP}, X */ X }; Xstatic MENU menu_body = { X MENU_IMAGESTRING, X "commands", X sizeof(pumenu_items)/sizeof(MENUITEM), X pumenu_items, X (MENU *) NULL, X (caddr_t) NULL X }; Xstatic MENU *menu_ptr = &menu_body; Xstatic char quit_msg[] = "CONFIRM with LEFT button, CANCEL with RIGHT or MIDDLE button"; Xstatic char edit_msg[] = "Figures are modified; please CONFIRM with LEFT button or CANCEL with RIGHT button"; X Xstatic Arg menu_args[] = X{ X { XtNx, (XtArgVal)0 }, X { XtNy, (XtArgVal)0 }, X { XtNwidth, (XtArgVal)0 }, X { XtNheight, (XtArgVal)0 }, X}; X Xextern void pane_select(); X Xstatic XtCallbackRec pane_callbacks[] = X{ X { pane_select, NULL }, X { NULL, NULL }, X}; X Xstatic Arg pane_args[] = X{ X { XtNx, (XtArgVal)10 }, X { XtNy, (XtArgVal)30 }, X { XtNlabel, (XtArgVal)" " }, X { XtNwidth, (XtArgVal)0 }, X { XtNheight, (XtArgVal)0 }, X { XtNcallback, (XtArgVal)pane_callbacks }, X}; X XTOOL menu; X Xint Xinit_menu(tool) X TOOL tool; X{ X TOOL panes, pane, title; X register int i, tlen, rlen = 0; X register MENUITEM *mi; X XtTranslations popdown_actions, pane_actions; X Arg my_list; X PIX_FONT temp_font; X X menu = XtCreatePopupShell("popup_menu", overrideShellWidgetClass, tool, X menu_args, XtNumber(menu_args)); X popdown_actions = XtParseTranslationTable( X "<Btn3Up>:MenuPopdown()\n"); X /* X <LeaveWindow>:MenuPopdown()\n"); X */ X XtOverrideTranslations(menu, popdown_actions); X panes = XtCreateManagedWidget("menu", boxWidgetClass, menu, menu_args, X XtNumber(menu_args)); X pane_actions = XtParseTranslationTable( X "<EnterWindow>:set()\n\ X <Btn3Up>:notify()unset()\n"); X for (i = 0; i < XtNumber(pumenu_items); i++) X { X mi = &pumenu_items[i]; X tlen = strlen(mi->label); X if( tlen > rlen ) X rlen = tlen; X } X X pane_args[2].value = (XtArgVal)"COMMANDS"; X title = XtCreateManagedWidget("title", labelWidgetClass, X panes, pane_args, 4); X X /* create the first pane */ X mi = &pumenu_items[0]; X pane_args[2].value = (XtArgVal)mi->label; X pane_callbacks[0].closure = (caddr_t)mi; X pane = XtCreateManagedWidget("pane", commandWidgetClass, X panes, pane_args, XtNumber(pane_args)); X XtOverrideTranslations(pane, pane_actions); X X /* get the default font */ X my_list.value = (XtArgVal)&temp_font; X my_list.name = XtNfont; X XtGetValues(pane, &my_list, 1); X X /* set the width of this pane and the title to the correct width */ X pane_args[3].value = char_width(temp_font) * rlen + 10; X XtSetValues(title, &pane_args[3], 1); X XtSetValues(pane, &pane_args[3], 1); X X for (i = 1; i < XtNumber(pumenu_items); ++i) X { X mi = &pumenu_items[i]; X pane_args[2].value = (XtArgVal)mi->label; X pane_callbacks[0].closure = (caddr_t)mi; X pane = XtCreateManagedWidget("pane", commandWidgetClass, X panes, pane_args, XtNumber(pane_args)); X XtOverrideTranslations(pane, pane_actions); X } X return (1); X} X Xset_popupmenu(event) X INPUTEVENT *event; X{ X} X Xvoid pane_select(widget, mi) X TOOL widget; X MENUITEM *mi; X{ X int menu_code = (int)mi->info; X X switch(menu_code) { X case F_UNDO : X undo(); X break; X case F_READ : X init_msg_receiving(read_file, "Read file : "); X break; X case F_SAVE : X (void)save_current_file(); X break; X case F_SAVE_IN : X if (no_object()) { X put_msg("No figure to save; ignored"); X break; X } X init_msg_receiving(save_file, "Save in file : "); X break; X case F_REDISPLAY : X redisplay_canvas(); X break; X case F_EDIT : X if (!no_object() && figure_modified) { X if (wmgr_confirm(canvas_swfd, edit_msg) != -1) break; X } X init_msg_receiving(edit_file, "Edit file : "); X break; X case F_PRINT: X print_figure(); X break; X case F_REMOVE_ALL : X remove_all(); X put_msg("Immediate Undo will restore the figure."); X redisplay_canvas(); X break; X case F_CHDIR : X init_msg_receiving(change_directory, "Directory : "); X break; X case F_PWDIR: X print_directory(); X break; X case F_STATUS : X status(); X break; X case F_SAVE_N_EXIT : X save_n_exit(); X break; X case F_QUIT : X quit(); X break; X case F_SAVE_BITMAP : X if (no_object()) { X put_msg("No figure to save"); X break; X } X init_msg_receiving(write_bitmap, "Save bitmap to file : "); X break; X } X XtPopdown(menu); X } X Xquit() X{ X if (no_object()) { X tool_destroy(tool); X exit(0); X } X if (! figure_modified) { X tool_destroy(tool); X exit(0); X } X if (wmgr_confirm(canvas_swfd, quit_msg) == -1) { X tool_destroy(tool); X exit(0); X } X } X Xsave_n_exit() X { X if (! figure_modified) X quit(); X if (no_object()) X quit(); X if (*current_file != 0) { X if (0 == write_file(current_file, 0)) X quit(); X } X else { X blink_msg(); X init_msg_receiving(save_and_exit, "Save in file : "); X } X } X END_OF_FILE if test 6300 -ne `wc -c <'xfig/popup.c'`; then echo shar: \"'xfig/popup.c'\" unpacked with wrong size! fi # end of 'xfig/popup.c' fi if test -f 'xfig/printfonts.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/printfonts.c'\" else echo shar: Extracting \"'xfig/printfonts.c'\" \(6010 characters\) sed "s/^X//" >'xfig/printfonts.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Added by Brian V. Smith X * X * %W% %G% X*/ X#include "fig.h" X#include "const.h" X#include "resources.h" X#include "func.h" X#include "psfonts.h" /* printer font names */ X X/******************** global variables ***************************/ X Xextern int font_button; /* font number */ Xextern char *font_menu_bits[]; Xextern Pixmap font_menu_bitmaps[]; Xextern struct _fstruct fontnames[]; /* font names */ X X/******************** local variables ***************************/ X Xstatic MENUITEM fontmenu_items[NUMFONTS]; X Xstatic MENU fontmenu_body = { X MENU_IMAGESTRING, X "printerfonts", X sizeof(fontmenu_items)/sizeof(MENUITEM), X fontmenu_items, X (MENU *) NULL, X (caddr_t) NULL X }; Xstatic MENU *fontmenu_ptr = &fontmenu_body; X Xstatic Arg fontmenu_args[] = X{ X /* 0 */{ XtNx, (XtArgVal) 0 }, X /* 1 */{ XtNy, (XtArgVal) 0 }, X /* 2 */{ XtNwidth, (XtArgVal) 0 }, X /* 3 */{ XtNheight, (XtArgVal) 0 }, X /* 4 */{ XtNvSpace, (XtArgVal) 1 }, X}; X Xextern void fontpane_select(); X Xstatic XtCallbackRec pane_callbacks[] = X{ X { fontpane_select, NULL }, X { NULL, NULL }, X}; X Xstatic Arg main_pane_args[] = X{ X /* 0 */ { XtNx, (XtArgVal)10 }, X /* 1 */ { XtNy, (XtArgVal)30 }, X /* 2 */ { XtNlabel, (XtArgVal)" " }, X /* 3 */ { XtNwidth, (XtArgVal) FONT_PANE_WIDTH }, X}; X Xstatic Arg pane_args[] = X{ X /* 0 */ { XtNx, (XtArgVal) 0 }, X /* 1 */ { XtNy, (XtArgVal) 0 }, X /* 2 */ { XtNwidth, (XtArgVal) FONT_PANE_WIDTH }, X /* 3 */ { XtNheight, (XtArgVal) 20 }, X /* 4 */ { XtNcallback, (XtArgVal)pane_callbacks }, X /* 5 */ { XtNbitmap, (XtArgVal) NULL }, X /* 6 */ { XtNinternalWidth, (XtArgVal) 0 }, /* space between pixmap and edge */ X /* 7 */ { XtNinternalHeight, (XtArgVal) 0 }, X /* 8 */ { XtNresize, (XtArgVal) FALSE }, /* don't allow resize */ X}; X Xstatic Arg psfont_args[] = X{ X /* 0 */ { XtNx, (XtArgVal)0 }, X /* 1 */ { XtNy, (XtArgVal)0 }, X /* 2 */ { XtNwidth, (XtArgVal) FONT_PANE_WIDTH }, X /* 3 */ { XtNheight, (XtArgVal) MSG_HEIGHT }, /* same height as message panel */ X /* 4 */ { XtNfromHoriz, (XtArgVal) NULL }, /* flush with panel indicator */ X /* 5 */ { XtNhorizDistance, (XtArgVal) -3*SWITCH_ICON_WIDTH-6*SWITCH_ICON_SPACING }, X /* 6 */ { XtNfromVert, (XtArgVal) NULL }, X /* 7 */ { XtNvertDistance, (XtArgVal) 1 }, /* dist from canvas_sw window */ X /* 8 */ { XtNbitmap, (XtArgVal) NULL }, X /* 9 */ { XtNinternalWidth, (XtArgVal) 0 }, /* space between pixmap and edge */ X /*10 */ { XtNinternalHeight, (XtArgVal) 0 }, X /*11 */ { XtNleft, (XtArgVal) XtChainLeft }, X /*12 */ { XtNright, (XtArgVal) XtChainLeft }, X}; X Xstatic TOOL fontpanes; Xstatic TOOL fontpane[NUMFONTS]; X Xinit_fontmenu(tool) X TOOL tool; X{ X TOOL title; X register int i; X register MENUITEM *mi; X XtTranslations popdown_actions, pane_actions; X Arg my_list; X X fontmenu = XtCreatePopupShell("popup_menu", overrideShellWidgetClass, tool, X fontmenu_args, XtNumber(fontmenu_args)); X popdown_actions = XtParseTranslationTable( X "<Btn1Up>:MenuPopdown()\n"); X XtOverrideTranslations(fontmenu, popdown_actions); X X fontpanes = XtCreateManagedWidget("menu", boxWidgetClass, fontmenu, fontmenu_args, X XtNumber(fontmenu_args)); X pane_actions = XtParseTranslationTable( X "<EnterWindow>:set()\n\ X <Btn1Up>:notify()unset()\n"); X for (i = 0; i < NUMFONTS; i++) X { X fontmenu_items[i].type = MENU_IMAGESTRING; /* put the fontnames in menu */ X fontmenu_items[i].label = fontnames[i].psfont; X fontmenu_items[i].info = (caddr_t) i; /* index for font # */ X mi = &fontmenu_items[i]; X } X X main_pane_args[2].value = (XtArgVal)"Printer Fonts"; X title = XtCreateManagedWidget("title", labelWidgetClass, X fontpanes, main_pane_args, XtNumber(main_pane_args)); X X /* create the first pane */ X mi = &fontmenu_items[0]; X pane_callbacks[0].closure = (caddr_t)mi; X X fontpane[0] = XtCreateManagedWidget("pane", commandWidgetClass, X fontpanes, pane_args, XtNumber(pane_args)); X XtOverrideTranslations(fontpane[0], pane_actions); X X for (i = 1; i < NUMFONTS; ++i) X { X mi = &fontmenu_items[i]; X pane_callbacks[0].closure = (caddr_t)mi; X fontpane[i] = XtCreateManagedWidget("pane", commandWidgetClass, X fontpanes, pane_args, XtNumber(pane_args)); X XtOverrideTranslations(fontpane[i], pane_actions); X } X X /* Now set up the font indicator window */ X X /* position */ X psfont_args[4].value = (XtArgVal)panel_sw; /* flush left with panel window */ X psfont_args[6].value = (XtArgVal)canvas_sw; /* just below the canvas window */ X psfont = XtCreateManagedWidget("indicator", labelWidgetClass, tool, X psfont_args, XtNumber(psfont_args)); X return (1); X} X X/* create the bitmaps for the font menu */ X Xsetup_fontmenu() X { X Arg psargs[2]; X register int i; X X /* Create the bitmaps */ X X for (i=0; i<NUMFONTS; i++) X font_menu_bitmaps[i] = XCreatePixmapFromBitmapData(tool_d, XtWindow(psfont), X font_menu_bits[i], FONT_PANE_WIDTH, FONT_PANE_HEIGHT, X x_bg_color.pixel, x_fg_color.pixel, DefaultDepthOfScreen(tool_s)); X psfont_args[8].value = (XtArgVal) font_menu_bitmaps[0]; X XtSetValues(psfont, &psfont_args[8], 1); /* show default font in window */ X X /* Store the bitmaps in the menu panes */ X for (i=0; i< NUMFONTS; i++) X { X pane_args[5].value = (XtArgVal) font_menu_bitmaps[i]; X XtSetValues(fontpane[i], &pane_args[5], 1); /* bitmap */ X } X } X X/* At this point (called from popup_fonts()), we have the font menu windows X to work with so we can define the cursor */ X Xstatic int cursinit = 0; X Xsetup_fontmenu_cursor() X { X register int i; X X if (cursinit) /* already defined */ X return; X X cursinit = 1; X /* Define the cursor for the main menu form */ X XDefineCursor(tool_d, XtWindow(fontpanes), (Cursor)arrow_cursor.bitmap); X } X Xvoid fontpane_select(widget, mi) XTOOL widget; XMENUITEM *mi; X{ X char * font_name = mi->label; X X font_button = (int) mi->info; X put_msg("Font: %s",font_name); X /* put image of font in indicator window */ X psfont_args[8].value = (XtArgVal) font_menu_bitmaps[font_button]; X XtSetValues(psfont, &psfont_args[8], 1); X XtPopdown(fontmenu); X } END_OF_FILE if test 6010 -ne `wc -c <'xfig/printfonts.c'`; then echo shar: \"'xfig/printfonts.c'\" unpacked with wrong size! fi # end of 'xfig/printfonts.c' fi if test -f 'xfig/save.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/save.c'\" else echo shar: Extracting \"'xfig/save.c'\" \(6610 characters\) sed "s/^X//" >'xfig/save.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985, 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : August 1985. X * 2nd revision : March 1988. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "func.h" X#include "object.h" X#include "const.h" X Xextern F_compound objects; X Xextern int figure_modified; Xextern int errno; X Xextern null_proc(); X Xextern char *sys_errlist[]; Xextern int sys_nerr, errno; Xextern int num_object; X Xwrite_file(file_name, prompt) Xchar *file_name; Xint prompt; X{ X FILE *fp; X struct stat file_status; X char string[180]; X X if (*file_name == 0) { X put_msg("No file. Abort save operation."); X return(-1); X } X if (stat(file_name, &file_status) == 0) { /* file exists */ X if (file_status.st_mode & S_IFDIR) { X put_msg("\"%s\" is a directory", file_name); X return(-1); X } X if (file_status.st_mode & S_IWRITE) { /* writing is permitted */ X if (file_status.st_uid != geteuid()) { X put_msg("\"%s\" permission is denied", file_name); X return(-1); X } X else if (prompt) { X sprintf(string, "\"%s\" File exists. Please click the LEFT button to COMFIRM overwrite. To cancel, click the MIDDLE or RIGHT button.", file_name); X if (wmgr_confirm(canvas_swfd, string) != -1) { X put_msg("Cancel save"); X return(-1); X } X } X } X else { X put_msg("\"%s\" File is read only", file_name); X return(-1); X } X } X else if (errno != ENOENT) X return(-1); /* file does exist but stat fails */ X X if ((fp = fopen(file_name, "w")) == NULL) { X blink_msg(); X put_msg("Couldn't open file %s, %s", file_name, sys_errlist[errno]); X return(-1); X } X else { X figure_modified = 0; X num_object = 0; X write_objects(fp); X put_msg("%d objects saved in \"%s\"", num_object, file_name); X return(0); X } X } X Xwrite_objects(fp) XFILE *fp; X{ X extern char file_header[]; X F_arc *a; X F_compound *c; X F_ellipse *e; X F_line *l; X F_spline *s; X F_text *t; X X /* Number 2 means that the origin (0,0) is at the upper X left corner of the screen (2nd quadrant) */ X X put_msg("Writing . . ."); X fprintf(fp, "%s\n", file_header); X fprintf(fp, "%d %d\n", PIX_PER_INCH, 2); X for (a = objects.arcs; a != NULL; a = a-> next) { X num_object++; X write_arc(fp, a); X } X for (c = objects.compounds; c != NULL; c = c-> next) { X num_object++; X write_compound(fp, c); X } X for (e = objects.ellipses; e != NULL; e = e-> next) { X num_object++; X write_ellipse(fp, e); X } X for (l = objects.lines; l != NULL; l = l-> next) { X num_object++; X write_line(fp, l); X } X for (s = objects.splines; s != NULL; s = s-> next) { X num_object++; X write_spline(fp, s); X } X for (t = objects.texts; t != NULL; t = t-> next) { X num_object++; X write_text(fp, t); X } X fclose(fp); X } X Xwrite_arc(fp, a) XFILE *fp; XF_arc *a; X{ X F_arrow *f, *b; X X fprintf(fp, "%d %d %d %d %d %d %d %d %.3f %d %d %d %.3f %.3f %d %d %d %d %d %d\n", X O_ARC, a->type, a->style, a->thickness, X a->color, a->depth, a->pen, a->area_fill, X a->style_val, a->direction, X ((f = a->for_arrow) ? 1 : 0), ((b = a->back_arrow) ? 1 : 0), X a->center.x, a->center.y, X a->point[0].x, a->point[0].y, X a->point[1].x, a->point[1].y, X a->point[2].x, a->point[2].y); X if (f) X fprintf(fp, "\t%d %d %.3f %.3f %.3f\n", f->type, f->style, X f->thickness, f->wid, f->ht); X if (b) X fprintf(fp, "\t%d %d %.3f %.3f %.3f\n", b->type, b->style, X b->thickness, b->wid, b->ht); X } X Xwrite_compound(fp, com) XFILE *fp; XF_compound *com; X{ X F_arc *a; X F_compound *c; X F_ellipse *e; X F_line *l; X F_spline *s; X F_text *t; X X fprintf(fp, "%d %d %d %d %d\n", O_COMPOUND, com->nwcorner.x, X com->nwcorner.y, com->secorner.x, com->secorner.y); X for (a = com->arcs; a != NULL; a = a-> next) write_arc(fp, a); X for (c = com->compounds; c != NULL; c = c-> next) write_compound(fp, c); X for (e = com->ellipses; e != NULL; e = e-> next) write_ellipse(fp, e); X for (l = com->lines; l != NULL; l = l-> next) write_line(fp, l); X for (s = com->splines; s != NULL; s = s-> next) write_spline(fp, s); X for (t = com->texts; t != NULL; t = t-> next) write_text(fp, t); X fprintf(fp, "%d\n", O_END_COMPOUND); X } X Xwrite_ellipse(fp, e) XFILE *fp; XF_ellipse *e; X{ X if( e->radiuses.x == 0 || e->radiuses.y == 0 ) X return; X X fprintf(fp, "%d %d %d %d %d %d %d %d %.3f %d %.3f %d %d %d %d %d %d %d %d\n", X O_ELLIPSE, e->type, e->style, e->thickness, X e->color, e->depth, e->pen, e->area_fill, X e->style_val, e->direction, e->angle, X e->center.x, e->center.y, X e->radiuses.x, e->radiuses.y, X e->start.x, e->start.y, X e->end.x, e->end.y); X } X Xwrite_line(fp, l) XFILE *fp; XF_line *l; X{ X F_point *p; X F_arrow *f, *b; X X if( l->points == NULL ) X return; X fprintf(fp, "%d %d %d %d %d %d %d %d %.3f %d %d\n", X O_POLYLINE, l->type, l->style, l->thickness, X l->color, l->depth, l->pen, l->area_fill, l->style_val, X ((f = l->for_arrow) ? 1 : 0), ((b = l->back_arrow) ? 1 : 0)); X if (f) X fprintf(fp, "\t%d %d %.3f %.3f %.3f\n", f->type, f->style, X f->thickness, f->wid, f->ht); X if (b) X fprintf(fp, "\t%d %d %.3f %.3f %.3f\n", b->type, b->style, X b->thickness, b->wid, b->ht); X fprintf(fp, "\t"); X for (p = l->points; p!= NULL; p = p->next) { X fprintf(fp, " %d %d", p->x, p->y); X }; X fprintf(fp, " 9999 9999\n"); X } X Xwrite_spline(fp, s) XFILE *fp; XF_spline *s; X{ X F_control *cp; X F_point *p; X F_arrow *f, *b; X X if( s->points == NULL ) X return; X fprintf(fp, "%d %d %d %d %d %d %d %d %.3f %d %d\n", X O_SPLINE, s->type, s->style, s->thickness, X s->color, s->depth, s->pen, s->area_fill, s->style_val, X ((f = s->for_arrow) ? 1 : 0), ((b = s->back_arrow) ? 1 : 0)); X if (f) X fprintf(fp, "\t%d %d %.3f %.3f %.3f\n", f->type, f->style, X f->thickness, f->wid, f->ht); X if (b) X fprintf(fp, "\t%d %d %.3f %.3f %.3f\n", b->type, b->style, X b->thickness, b->wid, b->ht); X fprintf(fp, "\t"); X for (p = s->points; p != NULL; p = p->next) { X fprintf(fp, " %d %d", p->x, p->y); X }; X fprintf(fp, " 9999 9999\n"); /* terminating code */ X X if (s->controls == NULL) return; X fprintf(fp, "\t"); X for (cp = s->controls; cp != NULL; cp = cp->next) { X fprintf(fp, " %.3f %.3f %.3f %.3f", X cp->lx, cp->ly, cp->rx, cp->ry); X }; X fprintf(fp, "\n"); X } X Xwrite_text(fp, t) XFILE *fp; XF_text *t; X{ X if( t->length == 0 ) X return; X fprintf(fp, "%d %d %d %d %d %d %d %.3f %d %d %d %d %d %s\1\n", X O_TEXT, t->type, t->font, t->size, t->pen, X t->color, t->depth, t->angle, X t->style, t->height, t->length, X t->base_x, t->base_y, t->cstring); X } END_OF_FILE if test 6610 -ne `wc -c <'xfig/save.c'`; then echo shar: \"'xfig/save.c'\" unpacked with wrong size! fi # end of 'xfig/save.c' fi if test -f 'xfig/spline.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'xfig/spline.c'\" else echo shar: Extracting \"'xfig/spline.c'\" \(5914 characters\) sed "s/^X//" >'xfig/spline.c' <<'END_OF_FILE' X/* X * FIG : Facility for Interactive Generation of figures X * X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU) X * January 1985. X * 1st revision : Aug 1985, Add closed spline. X * X * %W% %G% X*/ X#include "fig.h" X#include "resources.h" X#include "alloc.h" X#include "func.h" X#include "object.h" X#include "paintop.h" X Xextern (*canvas_kbd_proc)(); Xextern (*canvas_locmove_proc)(); Xextern (*canvas_leftbut_proc)(); Xextern (*canvas_middlebut_proc)(); Xextern (*canvas_rightbut_proc)(); Xextern null_proc(); Xextern set_popupmenu(); X Xextern int cur_line_style, line_thickness; Xextern float cur_styleval; Xextern int cur_color; Xextern int cur_areafill; Xextern int fill_mode; Xextern int fix_x, fix_y, cur_x, cur_y; Xextern int cur_command; Xextern int manhattan_mode, mountain_mode; Xextern int autoforwardarrow_mode; Xextern int autobackwardarrow_mode; Xextern int arrow_ht, arrow_wid; Xextern F_compound objects; Xextern int num_point; Xextern int DEBUG; Xextern F_point *first_point, *cur_point; X Xint create_splineobject(); X init_spline_drawing(); X Xdraw_spline_selected() X{ X canvas_kbd_proc = null_proc; X canvas_locmove_proc = null_proc; X canvas_leftbut_proc = init_spline_drawing; X canvas_middlebut_proc = null_proc; X canvas_rightbut_proc = set_popupmenu; X set_cursor(&arrow_cursor); X reset_action_on(); X } X Xinit_spline_drawing(x, y) Xint x, y; X{ X init_line_drawing(x, y); X canvas_middlebut_proc = create_splineobject; X canvas_rightbut_proc = null_proc; X } X Xcreate_splineobject(x, y) Xint x, y; X{ X extern F_arrow *forward_arrow(), *backward_arrow(); X F_spline *spline; X X if (x != fix_x || y != fix_y) get_intermediatepoint(x, y); X draw_elasticline(); X if (num_point <= 2) { X pw_vector(canvas_pixwin, first_point->x, first_point->y, X cur_point->x, cur_point->y, PAINT, 0); X if (num_point == 1) free((char*)cur_point); X free((char*)first_point); X draw_spline_selected(); X return; X } X Spline_malloc(spline); X spline->style = cur_line_style; X spline->thickness = line_thickness; X spline->style_val = cur_styleval; X spline->color = cur_color; X spline->depth = 0; X spline->pen = NULL; X spline->area_fill = 0; X spline->points = first_point; X spline->controls = NULL; X spline->next = NULL; X cur_x = cur_y = fix_x = fix_y = 0; /* used in draw_movingpoint */ X draw_movingpoint(spline->points, INV_PAINT); /* erase control vector */ X pw_batch_on(canvas_pixwin); X if (cur_command == F_CLOSED_SPLINE) { X spline->type = T_CLOSED_NORMAL; X spline->for_arrow = NULL; X spline->back_arrow = NULL; X /* added 3/1/89 B.V.Smith */ X /* The current area fill color will be saved in the object if X fill_mode is != 0, but the method presently used to draw X the spline doesn't easily lend itself to area fill, X so it is not filled. X The spline is drawn in sections that aren't adjacent, X and have overlapping sections. */ X spline->area_fill = fill_mode? cur_areafill : 0; X num_point++; X append_point(first_point->x, first_point->y, &cur_point); X draw_closed_spline(spline, PAINT); X } X else { /* It must be F_SPLINE */ X if (autoforwardarrow_mode) X spline->for_arrow = forward_arrow(); X else X spline->for_arrow = NULL; X if (autobackwardarrow_mode) X spline->back_arrow = backward_arrow(); X else X spline->back_arrow = NULL; X spline->type = T_OPEN_NORMAL; X draw_open_spline(spline, PAINT); X } X pw_batch_off(canvas_pixwin); X if (DEBUG) { X int xmin, ymin, xmax, ymax; X spline_bound(spline, &xmin, &ymin, &xmax, &ymax); X draw_rectbox(xmin, ymin, xmax, ymax, PAINT, 1); X } X clean_up(); X insert_spline(&objects.splines, spline); X set_action_object(F_CREATE, O_SPLINE); X set_latestspline(spline); X set_modifiedflag(); X draw_spline_selected(); X } X X#define round(x) ((int) (x + .5)) X Xdraw_open_spline(spline, op) XF_spline *spline; Xint op; X{ X F_point *p; X float cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; X float x1, y1, x2, y2; X X p = spline->points; X x1 = p->x; y1 = p->y; X p = p->next; X x2 = p->x; y2 = p->y; X cx1 = (x1 + x2) / 2; cy1 = (y1 + y2) / 2; X cx2 = (cx1 + x2) / 2; cy2 = (cy1 + y2) / 2; X if (spline->back_arrow) /* backward arrow */ X draw_arrow((int)x2, (int)y2, (int)x1, (int)y1, X spline->back_arrow, op); X pw_vector(canvas_pixwin, (int)x1, (int)y1, round(cx1), X round(cy1), op, spline->thickness); X X for (p = p->next; p != NULL; p = p->next) { X x1 = x2; y1 = y2; X x2 = p->x; y2 = p->y; X cx4 = (x1 + x2) / 2; cy4 = (y1 + y2) / 2; X cx3 = (x1 + cx4) / 2; cy3 = (y1 + cy4) / 2; X quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4, op, X spline->thickness); X cx1 = cx4; cy1 = cy4; X cx2 = (cx1 + x2) / 2; cy2 = (cy1 + y2) / 2; X } X pw_vector(canvas_pixwin, round(cx1), round(cy1), X (int)x2, (int)y2, op, spline->thickness); X if (spline->for_arrow) /* forward arrow */ X draw_arrow((int)x1, (int)y1, (int)x2, (int)y2, X spline->for_arrow, op); X } X Xdraw_closed_spline(spline, op) XF_spline *spline; Xint op; X{ X F_point *p; X float cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; X float x1, y1, x2, y2; X X p = spline->points; X x1 = p->x; y1 = p->y; X p = p->next; X x2 = p->x; y2 = p->y; X cx1 = (x1 + x2) / 2; cy1 = (y1 + y2) / 2; X cx2 = (x1 + 3 * x2) / 4; cy2 = (y1 + 3 * y2) / 4; X X for (p = p->next; p != NULL; p = p->next) { X x1 = x2; y1 = y2; X x2 = p->x; y2 = p->y; X cx4 = (x1 + x2) / 2; cy4 = (y1 + y2) / 2; X cx3 = (x1 + cx4) / 2; cy3 = (y1 + cy4) / 2; X quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4, op, X spline->thickness); X cx1 = cx4; cy1 = cy4; X cx2 = (cx1 + x2) / 2; cy2 = (cy1 + y2) / 2; X } X x1 = x2; y1 = y2; X p = spline->points->next; X x2 = p->x; y2 = p->y; X cx4 = (x1 + x2) / 2; cy4 = (y1 + y2) / 2; X cx3 = (x1 + cx4) / 2; cy3 = (y1 + cy4) / 2; X quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4, op, X spline->thickness); X } END_OF_FILE if test 5914 -ne `wc -c <'xfig/spline.c'`; then echo shar: \"'xfig/spline.c'\" unpacked with wrong size! fi # end of 'xfig/spline.c' fi echo shar: End of archive 12 \(of 15\). cp /dev/null ark12isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 15 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 dan ----------------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com 632 Petaluma Ave, Sebastopol, CA 95472 800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104 Opinions expressed reflect those of the author only.