v01i003: xfig: a MacDraw like line drawing editor(X11), Part02/11
Mike Wexler
mikew at wyse.wyse.com
Wed Aug 17 06:21:40 AEST 1988
Submitted-by: ken at cs.rochester.edu
Posting-number: Volume 1, Issue 3
Archive-name: xfig/part02
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 2 (of 11)."
# Contents: bitmap.c cursor.c geom.c latex_line.c list.c move.c
# object.h remove.c resources.h search.c trans.c turn.c xtra.c
# Wrapped by mikew at wyse on Tue Aug 16 13:14:35 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f bitmap.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"bitmap.c\"
else
echo shar: Extracting \"bitmap.c\" \(3732 characters\)
sed "s/^X//" >bitmap.c <<'END_OF_bitmap.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at 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 "object.h"
X#include "paintop.h"
X
Xextern F_compound objects;
X
Xextern int errno;
Xextern int DEBUG;
Xextern int pointmarker_shown;
Xextern int compoundbox_shown;
X
Xextern char *sys_errlist[];
Xextern int sys_nerr, errno;
X
Xwrite_bitmap(file_name)
Xchar *file_name;
X{
X FILE *fp;
X struct stat file_status;
X char string[180];
X
X if (*file_name == 0) {
X put_msg("No file");
X return;
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;
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;
X }
X else {
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("No write.");
X return;
X }
X }
X }
X else {
X put_msg("\"%s\" File is read only", file_name);
X return;
X }
X }
X else if (errno != ENOENT) return; /* 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;
X }
X else {
X create_n_write_bitmap(fp);
X }
X }
X
Xcreate_n_write_bitmap(fp)
XFILE *fp;
X{
X int box, marker, xmin, ymin, xmax, ymax;
X PIXRECT bitmap, pw_pixrect, pw_prretained;
X F_text *t;
X
X /* Assume that there is at least one object */
X compound_bound(&objects, &xmin, &ymin, &xmax, &ymax);
X
X if (DEBUG) {
X draw_rectbox(xmin, ymin, xmax, ymax, INV_PAINT);
X }
X#ifndef X11
X bitmap = mem_create(xmax-xmin+1, ymax-ymin+1, 1);
X pw_pixrect = canvas_pixwin->pw_pixrect;
X pw_prretained = canvas_pixwin->pw_prretained;
X canvas_pixwin->pw_pixrect = canvas_pixwin->pw_prretained = bitmap;
X translate_compound(&objects, -xmin, -ymin);
X marker = pointmarker_shown;
X pointmarker_shown = 0;
X box = compoundbox_shown;
X compoundbox_shown = 0;
X pw_batch_on(canvas_pixwin);
X redisplay_arcobject(objects.arcs);
X redisplay_compoundobject(objects.compounds);
X redisplay_ellipseobject(objects.ellipses);
X redisplay_lineobject(objects.lines);
X redisplay_splineobject(objects.splines);
X canvas_pixwin->pw_pixrect = pw_pixrect;
X canvas_pixwin->pw_prretained = pw_prretained;
X pw_batch_off(canvas_pixwin);
X pointmarker_shown = marker;
X compoundbox_shown = box;
X write_pixrect(fp, bitmap);
X for (t = objects.texts; t != NULL; t = t->next) write_text(fp, t);
X translate_compound(&objects, xmin, ymin);
X fclose(fp);
X pr_destroy(bitmap);
X#else
X put_msg("Sorry, write_bitmap not implemented for X11 yet");
X#endif X11
X }
X
X#ifndef X11
Xwrite_pixrect(fp, bitmap)
XFILE *fp;
XPIXRECT bitmap;
X{
X int i, j, width, height, shorts_per_row ;
X u_short *ptr;
X
X width = bitmap->pr_size.x;
X height = bitmap->pr_size.y;
X shorts_per_row = (int) ((width + 15) / 16);
X
X put_msg("Writing . . .");
X
X fprintf(fp, "/* Format_version=1, Width=%d, Height=%d, ",
X width, height);
X fprintf(fp, "Depth=1, Valid_bits_per_item=16\n */\n");
X
X ptr = (u_short*)((MPR_DATA *) bitmap->pr_data)->md_image;
X
X for (i = 0; i < height; i++) {
X fprintf(fp, "\t");
X fprintf(fp, "0x%04X", *ptr++);
X for (j = 1; j < shorts_per_row; j++) fprintf(fp, ",0x%04X", *ptr++);
X if (height-i != 1) fprintf(fp, ","); /* if i is not the last row */
X fprintf(fp, "\n");
X }
X
X put_msg("Done");
X }
X#endif X11
END_OF_bitmap.c
if test 3732 -ne `wc -c <bitmap.c`; then
echo shar: \"bitmap.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f cursor.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"cursor.c\"
else
echo shar: Extracting \"cursor.c\" \(4442 characters\)
sed "s/^X//" >cursor.c <<'END_OF_cursor.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at 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
X#ifdef X11
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}
X#endif X11
END_OF_cursor.c
if test 4442 -ne `wc -c <cursor.c`; then
echo shar: \"cursor.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f geom.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"geom.c\"
else
echo shar: Extracting \"geom.c\" \(4668 characters\)
sed "s/^X//" >geom.c <<'END_OF_geom.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1988 by Supoj Sutanthavibul (supoj at 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_geom.c
if test 4668 -ne `wc -c <geom.c`; then
echo shar: \"geom.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f latex_line.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"latex_line.c\"
else
echo shar: Extracting \"latex_line.c\" \(3275 characters\)
sed "s/^X//" >latex_line.c <<'END_OF_latex_line.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "math.h"
X
Xint pgcd(a,b)
X int a, b;
X/*
X * compute greatest common divisor, assuming 0 < a <= b
X */
X{
X b = b % a;
X return (b)? gcd(b, a): a;
X}
X
Xint gcd(a, b)
X int a, b;
X/*
X * compute greatest common divisor
X */
X{
X if (a < 0) a = -a;
X if (b < 0) b = -b;
X return (a <= b)? pgcd(a, b): pgcd(b, a);
X}
X
X
Xint lcm(a, b)
X int a, b;
X/*
X * compute least common multiple
X */
X{
X return abs(a*b)/gcd(a,b);
X}
X
X
Xdouble rad2deg = 57.295779513082320877;
X
Xstruct angle_table {
X int x, y;
X double angle;
X};
X
Xstruct angle_table line_angles[25] =
X { {0, 1, 90.0},
X {1, 0, 0.0},
X {1, 1, 45.0},
X {1, 2, 63.434948822922010648},
X {1, 3, 71.565051177077989351},
X {1, 4, 75.963756532073521417},
X {1, 5, 78.690067525979786913},
X {1, 6, 80.537677791974382609},
X {2, 1, 26.565051177077989351},
X {2, 3, 56.309932474020213086},
X {2, 5, 68.198590513648188229},
X {3, 1, 18.434948822922010648},
X {3, 2, 33.690067525979786913},
X {3, 4, 53.130102354155978703},
X {3, 5, 59.036243467926478582},
X {4, 1, 14.036243467926478588},
X {4, 3, 36.869897645844021297},
X {4, 5, 51.340191745909909396},
X {5, 1, 11.309932474020213086},
X {5, 2, 21.801409486351811770},
X {5, 3, 30.963756532073521417},
X {5, 4, 38.659808254090090604},
X {5, 6, 50.194428907734805993},
X {6, 1, 9.4623222080256173906},
X {6, 5, 39.805571092265194006}
X };
X
Xstruct angle_table arrow_angles[13] =
X { {0, 1, 90.0},
X {1, 0, 0.0},
X {1, 1, 45.0},
X {1, 2, 63.434948822922010648},
X {1, 3, 71.565051177077989351},
X {1, 4, 75.963756532073521417},
X {2, 1, 26.565051177077989351},
X {2, 3, 56.309932474020213086},
X {3, 1, 18.434948822922010648},
X {3, 2, 33.690067525979786913},
X {3, 4, 53.130102354155978703},
X {4, 1, 14.036243467926478588},
X {4, 3, 36.869897645844021297},
X };
X
Xget_slope(dx, dy, sxp, syp, arrow)
X int dx, dy, *sxp, *syp, arrow;
X{
X double angle;
X int i, s, max;
X double d, d1;
X struct angle_table *st;
X
X if (dx == 0) {
X *sxp = 0;
X *syp = (dy < 0)? -1: 1;
X return;
X }
X angle = atan((double)abs(dy) / (double)abs(dx)) * rad2deg;
X if (arrow) {
X st = arrow_angles;
X max = 13;
X } else {
X st = line_angles;
X max = 25;
X }
X s = 0;
X d = 9.9e9;
X for (i = 0; i < max; i++) {
X d1 = fabs(angle - st[i].angle);
X if (d1 < d) {
X s = i;
X d = d1;
X }
X }
X *sxp = st[s].x;
X if (dx < 0) *sxp = -*sxp;
X *syp = st[s].y;
X if (dy < 0) *syp = -*syp;
X}
X
Xlatex_endpoint(x1, y1, x2, y2, xout, yout, arrow, magnet)
X int x1, y1, x2, y2;
X int *xout, *yout;
X int arrow, magnet;
X{
X int dx, dy, sx, sy, ds, dsx, dsy;
X
X dx = x2-x1;
X dy = y2-y1;
X get_slope(dx, dy, &sx, &sy, arrow);
X if (abs(sx) >= abs(sy)) {
X ds = lcm(sx, magnet*gcd(sx,magnet));
X dsx = (2*abs(dx)/ds + 1)/2;
X dsx = (dx >= 0)? dsx*ds: -dsx*ds;
X *xout = x1 + dsx;
X *yout = y1 + dsx*sy/sx;
X } else {
X ds = lcm(sy, magnet*gcd(sy,magnet));
X dsy = (2*abs(dy)/ds + 1)/2;
X dsy = (dy >= 0)? dsy*ds: -dsy*ds;
X *yout = y1 + dsy;
X *xout = x1 + dsy*sx/sy;
X }
X}
END_OF_latex_line.c
if test 3275 -ne `wc -c <latex_line.c`; then
echo shar: \"latex_line.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f list.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"list.c\"
else
echo shar: Extracting \"list.c\" \(2980 characters\)
sed "s/^X//" >list.c <<'END_OF_list.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1988 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * Febuary 1988.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "object.h"
X
Xdelete_arc(arc_list, arc)
XF_arc **arc_list, *arc;
X{
X F_arc *a, *aa;
X
X if (*arc_list == NULL) return;
X if (arc == NULL) return;
X
X for (a = aa = *arc_list; aa != NULL; a = aa, aa = aa->next) {
X if (aa == arc) {
X if (aa == *arc_list)
X *arc_list = (*arc_list)->next;
X else
X a->next = aa->next;
X break;
X }
X }
X arc->next = NULL;
X }
X
Xdelete_ellipse(ellipse_list, ellipse)
XF_ellipse **ellipse_list, *ellipse;
X{
X F_ellipse *q, *r;
X
X if (*ellipse_list == NULL) return;
X if (ellipse == NULL) return;
X
X for (q = r = *ellipse_list; r != NULL; q = r, r = r->next) {
X if (r == ellipse) {
X if (r == *ellipse_list)
X *ellipse_list = (*ellipse_list)->next;
X else
X q->next = r->next;
X break;
X }
X }
X ellipse->next = NULL;
X }
X
Xdelete_line(line_list, line)
XF_line *line, **line_list;
X{
X F_line *q, *r;
X
X if (*line_list == NULL) return;
X if (line == NULL) return;
X
X for (q = r = *line_list; r != NULL; q = r, r = r->next) {
X if (r == line) {
X if (r == *line_list)
X *line_list = (*line_list)->next;
X else
X q->next = r->next;
X break;
X }
X }
X line->next = NULL;
X }
X
Xdelete_spline(spline_list, spline)
XF_spline **spline_list, *spline;
X{
X F_spline *q, *r;
X
X if (*spline_list == NULL) return;
X if (spline == NULL) return;
X
X for (q = r = *spline_list; r != NULL; q = r, r = r->next) {
X if (r == spline) {
X if (r == *spline_list)
X *spline_list = (*spline_list)->next;
X else
X q->next = r->next;
X break;
X }
X }
X spline->next = NULL;
X }
X
Xdelete_text(text_list, text)
XF_text **text_list, *text;
X{
X F_text *q, *r;
X
X if (*text_list == NULL) return;
X if (text == NULL) return;
X
X for (q = r = *text_list; r != NULL; q = r, r = r->next)
X if (r == text) {
X if (r == *text_list)
X *text_list = text->next;
X else
X q->next = text->next;
X break;
X }
X text->next = NULL;
X }
X
Xdelete_compound(list, compound)
XF_compound **list, *compound;
X{
X F_compound *c, *cc;
X
X if (*list == NULL) return;
X if (compound == NULL) return;
X
X for (cc = c = *list; c != NULL; cc = c, c = c->next) {
X if (c == compound) {
X if (c == *list)
X *list = (*list)->next;
X else
X cc->next = c->next;
X break;
X }
X }
X compound->next = NULL;
X }
X
Xinsert_arc(arc_list, a)
XF_arc **arc_list, *a;
X{
X a->next = *arc_list;
X *arc_list = a;
X }
X
Xinsert_ellipse(ellipse_list, e)
XF_ellipse **ellipse_list, *e;
X{
X e->next = *ellipse_list;
X *ellipse_list = e;
X }
X
Xinsert_line(line_list, l)
XF_line **line_list, *l;
X{
X l->next = *line_list;
X *line_list = l;
X }
X
Xinsert_spline(spline_list, s)
XF_spline **spline_list, *s;
X{
X s->next = *spline_list;
X *spline_list = s;
X }
X
Xinsert_text(text_list, t)
XF_text **text_list, *t;
X{
X t->next = *text_list;
X *text_list = t;
X }
X
X
Xinsert_compound(list, c)
XF_compound **list, *c;
X{
X c->next = *list;
X *list = c;
X }
END_OF_list.c
if test 2980 -ne `wc -c <list.c`; then
echo shar: \"list.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f move.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"move.c\"
else
echo shar: Extracting \"move.c\" \(3916 characters\)
sed "s/^X//" >move.c <<'END_OF_move.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at 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 "font.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 (*return_proc)();
Xextern null_proc();
Xextern set_popupmenu();
X
Xextern F_line *line_search();
Xextern F_arc *arc_search();
Xextern F_ellipse *ellipse_search();
Xextern F_text *text_search();
Xextern F_spline *spline_search();
Xextern F_compound *compound_search();
X
Xextern int foreground_color, background_color;
Xextern int pointmarker_shown, compoundbox_shown;
Xextern int last_object;
Xextern int last_action;
X
X init_move();
X
Xmove_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_move;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X return_proc = move_selected;
X set_cursor(&pick9_cursor);
X reset_action_on();
X }
X
Xinit_move(x, y)
Xint x, y;
X{
X F_line *l;
X F_arc *a;
X F_ellipse *e;
X F_text *t;
X F_spline *s;
X F_compound *c;
X int px, py;
X
X if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X if (compoundbox_shown) draw_compoundbox(c, INV_PAINT);
X erase_compound(c);
X init_compounddragging(c, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_COMPOUND);
X set_latestcompound(c);
X }
X else if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X win_setmouseposition(canvas_swfd, px, py);
X draw_line(l, ERASE);
X init_linedragging(l, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_POLYLINE);
X set_latestline(l);
X }
X else if ((t = text_search(x, y)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X pw_text(canvas_pixwin, t->base_x, t->base_y,
X INV_PAINT, canvas_font, t->cstring);
X init_textdragging(t, x, y);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_TEXT);
X set_latesttext(t);
X }
X else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X pw_batch_on(canvas_pixwin);
X draw_ellipse(e, background_color);
X pw_batch_off(canvas_pixwin);
X init_ellipsedragging(e, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_ELLIPSE);
X set_latestellipse(e);
X }
X else if ((a = arc_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X erase_pointmarker();
X win_setmouseposition(canvas_swfd, px, py);
X pw_batch_on(canvas_pixwin);
X draw_arc(a, background_color);
X pw_batch_off(canvas_pixwin);
X init_arcdragging(a, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_ARC);
X set_latestarc(a);
X }
X else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X set_temp_cursor(&wait_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X erase_pointmarker();
X pw_batch_on(canvas_pixwin);
X draw_spline(s, ERASE);
X pw_batch_off(canvas_pixwin);
X init_splinedragging(s, px, py);
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_MOVE, O_SPLINE);
X set_latestspline(s);
X }
X else
X return;
X canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X }
END_OF_move.c
if test 3916 -ne `wc -c <move.c`; then
echo shar: \"move.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f object.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"object.h\"
else
echo shar: Extracting \"object.h\" \(4595 characters\)
sed "s/^X//" >object.h <<'END_OF_object.h'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * (c) copy right 1985 by Supoj Sutanthavibul (supoj at sally.utexas.edu)
X * January 1985.
X * 1st revision : Aug 1985.
X * 2nd revision : Feb 1988.
X *
X * %W% %G%
X*/
Xtypedef struct f_pattern {
X int w, h;
X int *p;
X }
X F_pattern;
X
Xtypedef struct f_pen {
X int x, y;
X int *p;
X }
X F_pen;
X
Xtypedef struct f_point {
X int x, y;
X struct f_point *next;
X }
X F_point;
X
Xtypedef struct f_pos {
X int x, y;
X }
X F_pos;
X
Xtypedef struct f_arrow {
X int type;
X int style;
X float thickness;
X float wid;
X float ht;
X }
X F_arrow;
X
Xtypedef struct f_ellipse {
X int type;
X#define T_ELLIPSE_BY_RAD 1
X#define T_ELLIPSE_BY_DIA 2
X#define T_CIRCLE_BY_RAD 3
X#define T_CIRCLE_BY_DIA 4
X int style;
X int thickness;
X int color;
X#define BLACK 0
X int depth;
X int direction;
X float style_val;
X float angle;
X struct f_pen *pen;
X struct f_pattern *area_fill;
X struct f_pos center;
X struct f_pos radiuses;
X struct f_pos start;
X struct f_pos end;
X struct f_ellipse *next;
X }
X F_ellipse;
X
Xtypedef struct f_arc {
X int type;
X#define T_3_POINTS_ARC 1
X int style;
X int thickness;
X int color;
X int depth;
X struct f_pen *pen;
X struct f_pattern *area_fill;
X float style_val;
X int direction;
X struct f_arrow *for_arrow;
X struct f_arrow *back_arrow;
X struct {float x, y;} center;
X struct f_pos point[3];
X struct f_arc *next;
X }
X F_arc;
X
Xtypedef struct f_line {
X int type;
X#define T_POLYLINE 1
X#define T_BOX 2
X#define T_POLYGON 3
X int style;
X int thickness;
X int color;
X int depth;
X float style_val;
X struct f_pen *pen;
X struct f_pattern *area_fill;
X struct f_arrow *for_arrow;
X struct f_arrow *back_arrow;
X struct f_point *points;
X struct f_line *next;
X }
X F_line;
X
Xtypedef struct f_text {
X int type;
X#define T_LEFT_JUSTIFIED 0
X#define T_CENTER_JUSTIFIED 1
X#define T_RIGHT_JUSTIFIED 2
X int font;
X int size; /* point size */
X int color;
X int depth;
X float angle; /* in radian */
X
X int style;
X#define PLAIN 1
X#define ITALIC 2
X#define BOLD 4
X#define OUTLINE 8
X#define SHADOW 16
X
X int height; /* pixels */
X int length; /* pixels */
X int base_x;
X int base_y;
X struct f_pen *pen;
X char *cstring;
X struct f_text *next;
X }
X F_text;
X
Xtypedef struct f_control {
X float lx, ly, rx, ry;
X struct f_control *next;
X }
X F_control;
X
X#define int_spline(s) (s->type & 0x2)
X#define normal_spline(s) (!(s->type & 0x2))
X#define closed_spline(s) (s->type & 0x1)
X#define open_spline(s) (!(s->type & 0x1))
X
Xtypedef struct f_spline {
X int type;
X#define T_OPEN_NORMAL 0
X#define T_CLOSED_NORMAL 1
X#define T_OPEN_INTERPOLATED 2
X#define T_CLOSED_INTERPOLATED 3
X int style;
X int thickness;
X int color;
X int depth;
X float style_val;
X struct f_pen *pen;
X struct f_pattern *area_fill;
X struct f_arrow *for_arrow;
X struct f_arrow *back_arrow;
X /*
X For T_OPEN_NORMAL and T_CLOSED_NORMAL points
X are control points while they are knots for
X T_OPEN_INTERPOLATED and T_CLOSED_INTERPOLTED
X whose control points are stored in controls.
X */
X struct f_point *points;
X struct f_control *controls;
X struct f_spline *next;
X }
X F_spline;
X
Xtypedef struct f_compound {
X struct f_pos nwcorner;
X struct f_pos secorner;
X struct f_line *lines;
X struct f_ellipse *ellipses;
X struct f_spline *splines;
X struct f_text *texts;
X struct f_arc *arcs;
X struct f_compound *compounds;
X struct f_compound *next;
X }
X F_compound;
X
X#define ARROW_SIZE sizeof(struct f_arrow)
X#define POINT_SIZE sizeof(struct f_point)
X#define CONTROL_SIZE sizeof(struct f_control)
X#define ELLOBJ_SIZE sizeof(struct f_ellipse)
X#define ARCOBJ_SIZE sizeof(struct f_arc)
X#define LINOBJ_SIZE sizeof(struct f_line)
X#define TEXOBJ_SIZE sizeof(struct f_text)
X#define SPLOBJ_SIZE sizeof(struct f_spline)
X#define COMOBJ_SIZE sizeof(struct f_compound)
X
X/********************** object codes **********************/
X
X#define O_ELLIPSE 1
X#define O_POLYLINE 2
X#define O_SPLINE 3
X#define O_TEXT 4
X#define O_ARC 5
X#define O_COMPOUND 6
X#define O_END_COMPOUND -O_COMPOUND
X#define O_ALL_OBJECT 99
X
X/************ object styles (except for f_text) ************/
X
X#define SOLID_LINE 0
X#define DASH_LINE 1
X#define DOTTED_LINE 2
X
X#define CLOSED_PATH 0
X#define OPEN_PATH 1
END_OF_object.h
if test 4595 -ne `wc -c <object.h`; then
echo shar: \"object.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f remove.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"remove.c\"
else
echo shar: Extracting \"remove.c\" \(3561 characters\)
sed "s/^X//" >remove.c <<'END_OF_remove.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at 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 7
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
X
Xextern int foreground_color, background_color;
X
X init_remove();
X
Xremove_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_remove;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&buster_cursor);
X }
X
Xinit_remove(x, y)
Xint x, y;
X{
X extern F_line *line_search();
X extern F_arc *arc_search();
X extern F_ellipse *ellipse_search();
X extern F_text *text_search();
X extern F_spline *spline_search();
X extern F_compound *compound_search();
X extern F_compound objects;
X F_line *l;
X F_arc *a;
X F_ellipse *e;
X F_text *t;
X F_spline *s;
X F_compound *c;
X int dummy;
X
X if ((c = compound_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
X draw_compoundbox(c, INV_PAINT);
X erase_compound(c);
X delete_compound(&objects.compounds, c);
X clean_up();
X set_action_object(F_REMOVE, O_COMPOUND);
X set_latestcompound(c);
X set_modifiedflag();
X }
X else if ((l = line_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
X toggle_linepointmarker(l);
X draw_line(l, ERASE);
X delete_line(&objects.lines, l);
X clean_up();
X set_action_object(F_REMOVE, O_POLYLINE);
X set_latestline(l);
X set_modifiedflag();
X }
X else if ((t = text_search(x, y)) != NULL) {
X draw_text(t, INV_PAINT);
X delete_text(&objects.texts, t);
X clean_up();
X set_action_object(F_REMOVE, O_TEXT);
X set_latesttext(t);
X set_modifiedflag();
X }
X else if ((e = ellipse_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL){
X toggle_ellipsepointmarker(e);
X pw_batch_on(canvas_pixwin);
X draw_ellipse(e, background_color);
X pw_batch_off(canvas_pixwin);
X delete_ellipse(&objects.ellipses, e);
X clean_up();
X set_action_object(F_REMOVE, O_ELLIPSE);
X set_latestellipse(e);
X set_modifiedflag();
X }
X else if ((a = arc_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL){
X toggle_arcpointmarker(a);
X pw_batch_on(canvas_pixwin);
X draw_arc(a, background_color);
X pw_batch_off(canvas_pixwin);
X delete_arc(&objects.arcs, a);
X clean_up();
X set_action_object(F_REMOVE, O_ARC);
X set_latestarc(a);
X set_modifiedflag();
X }
X else if ((s = spline_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
X toggle_splinepointmarker(s);
X pw_batch_on(canvas_pixwin);
X draw_spline(s, ERASE);
X pw_batch_off(canvas_pixwin);
X delete_spline(&objects.splines, s);
X clean_up();
X set_action_object(F_REMOVE, O_SPLINE);
X set_latestspline(s);
X set_modifiedflag();
X }
X remove_selected();
X }
X
Xremove_all()
X{
X extern F_compound objects;
X extern F_compound saved_objects;
X extern int last_action;
X
X clean_up();
X set_action_object(F_REMOVE, O_ALL_OBJECT);
X
X /* Aggregate assignment between variables is allowed,
X but not from constant (weird!?) */
X
X saved_objects = objects;
X
X objects.arcs = NULL;
X objects.compounds = NULL;
X objects.ellipses = NULL;
X objects.lines = NULL;
X objects.splines = NULL;
X objects.texts = NULL;
X }
END_OF_remove.c
if test 3561 -ne `wc -c <remove.c`; then
echo shar: \"remove.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f resources.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"resources.h\"
else
echo shar: Extracting \"resources.h\" \(3831 characters\)
sed "s/^X//" >resources.h <<'END_OF_resources.h'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#ifdef GLOBAL
X#define EXTERN
X#else
X#define EXTERN extern
X#endif
X
X#ifdef X11
Xtypedef struct
X{
X unsigned int x, y, z;
X caddr_t *m;
X} MprData;
X
X#define mpr_static(name,x,y,z,pix) \
XXImage name = \
X{ \
X(x), (y), 0, XYBitmap, (char *)(pix),\
XMSBFirst, 8, MSBFirst, 8, (z), (x+7)/8, 1, 0, 0, 0, NULL \
X}
X
Xtypedef struct
X{
X int x, y;
X} pr_size;
X
Xtypedef struct
X{
X unsigned int hotx, hoty;
X unsigned int graphop;
X XImage *bitmap;
X} CursorRec;
X
Xtypedef struct
X{
X unsigned int r_width, r_height, r_left, r_top;
X} RectRec;
X
Xtypedef struct
X{
X int type;
X char *label;
X caddr_t info;
X} MenuItemRec;
X
Xstruct Menu
X{
X int m_imagetype;
X#define MENU_IMAGESTRING 0x00 /* imagedata is char * */
X#define MENU_GRAPHIC 0x01 /* imagedata is pixrect * */
X caddr_t m_imagedata;
X int m_itemcount;
X MenuItemRec *m_items;
X struct Menu *m_next;
X caddr_t m_data;
X};
X
Xtypedef struct Menu MenuRec;
X#endif X11
X
X#ifndef X11
Xtypedef struct pixwin * PIXWIN;
Xtypedef struct pixrect PIXRECTREC;
Xtypedef struct pixrect * PIXRECT;
Xtypedef struct pixfont * PIX_FONT;
X/* pixrect/pixfont.h already took PIXFONT, foo! */
Xtypedef struct mpr_data MPR_DATA;
Xtypedef struct cursor CURSORREC;
Xtypedef struct cursor * CURSOR;
Xtypedef struct tool * TOOL;
Xtypedef struct toolsw * TOOLSW;
Xtypedef int FDTYPE;
Xtypedef struct inputevent INPUTEVENT;
Xtypedef struct inputmask INPUTMASK;
Xtypedef struct pr_size PR_SIZE;
Xtypedef struct rect RECT;
Xtypedef struct menuitem MENUITEM;
Xtypedef struct menu MENU;
X#else
Xtypedef Window PIXWIN;
Xtypedef XImage PIXRECTREC;
Xtypedef XImage * PIXRECT;
Xtypedef XFontStruct * PIX_FONT;
Xtypedef MprData MPR_DATA;
Xtypedef CursorRec CURSORREC;
Xtypedef CursorRec * CURSOR;
Xtypedef Widget TOOL;
Xtypedef Widget TOOLSW;
Xtypedef Window FDTYPE;
Xtypedef XButtonEvent INPUTEVENT;
Xtypedef unsigned long INPUTMASK;
Xtypedef pr_size PR_SIZE;
Xtypedef RectRec RECT;
Xtypedef MenuItemRec MENUITEM;
Xtypedef MenuRec MENU;
X#endif X11
X
X#ifndef X11
X#define set_marker(win,x,y,w,h,op,pix,z1,z2) \
X pw_write((win),(x),(y),(w),(h),(op),(pix),(z1),(z2))
X#else
X#define set_marker(win,x,y,w,h,op,pix,z1,z2) \
X XDrawRectangle(tool_d,(win),gccache[(op)],(x),(y),(w),(h))
X#endif X11
X
XEXTERN PIXWIN canvas_pixwin,
X msg_pixwin,
X panel_pixwin,
X sideruler_pixwin,
X topruler_pixwin;
X
XEXTERN CURSOR cur_cursor;
XEXTERN CURSORREC arrow_cursor,
X bull_cursor,
X buster_cursor,
X crosshair_cursor,
X null_cursor,
X pencil_cursor,
X pick15_cursor,
X pick9_cursor,
X wait_cursor;
X
XEXTERN TOOL tool;
X
XEXTERN TOOLSW canvas_sw,
X msg_sw,
X panel_sw,
X sideruler_sw,
X topruler_sw;
X
XEXTERN FDTYPE canvas_swfd,
X panel_swfd,
X msgswfd,
X trswfd,
X srswfd;
X
X#ifdef X11
XEXTERN Display *tool_d;
XEXTERN Screen *tool_s;
XEXTERN int tool_sn;
XEXTERN GC gc, gccache[0x10];
X
Xstruct icon {
X short ic_width, ic_height; /* overall icon dimensions */
X PIXRECT ic_background; /* background pattern (mem pixrect) */
X RECT ic_gfxrect; /* where the graphic goes */
X PIXRECT ic_mpr; /* the graphic (a memory pixrect) */
X RECT ic_textrect; /* where text goes */
X char *ic_text; /* the text */
X PIX_FONT ic_font; /* Font with which to display text */
X int ic_flags;
X};
X
X/* flag values */
X#define ICON_BKGRDPAT 0x02 /* use ic_background to prepare image*/
X#define ICON_BKGRDGRY 0x04 /* use std gray to prepare image*/
X#define ICON_BKGRDCLR 0x08 /* clear to prepare image*/
X#define ICON_BKGRDSET 0x10 /* set to prepare image*/
X#define ICON_FIRSTPRIV 0x0100 /* start of private flags range */
X#define ICON_LASTPRIV 0x8000 /* end of private flags range */
X
X#include "xtra.h"
X
X#endif X11
END_OF_resources.h
if test 3831 -ne `wc -c <resources.h`; then
echo shar: \"resources.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f search.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"search.c\"
else
echo shar: Extracting \"search.c\" \(3347 characters\)
sed "s/^X//" >search.c <<'END_OF_search.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "object.h"
X
Xextern F_compound objects;
X
XF_arc *
Xarc_search(x, y, tolerance, px, py)
Xint x, y, tolerance, *px, *py;
X{ /* (px, py) is the control point on the circumference of an arc
X which is the closest to (x, y) */
X
X F_arc *a;
X int i;
X
X for (a = objects.arcs; a != NULL; a = a->next) {
X for (i = 0; i < 3; i++)
X if ((abs(a->point[i].x - x) <= tolerance) &&
X (abs(a->point[i].y - y) <= tolerance)) {
X *px = a->point[i].x;
X *py = a->point[i].y;
X return(a);
X }
X }
X return(NULL);
X }
X
X
XF_ellipse *
Xellipse_search(x, y, tolerance, px, py)
Xint x, y, tolerance, *px, *py;
X{ /* (px, py) is the point on the circumference of an ellipse
X which is the closest to (x, y) */
X
X F_ellipse *e;
X int a, b, dx, dy;
X float dis, r, tol;
X
X tol = (float) tolerance;
X for (e = objects.ellipses; e != NULL; e = e->next) {
X dx = x - e->center.x;
X dy = y - e->center.y;
X a = e->radiuses.x;
X b = e->radiuses.y;
X dis = sqrt((double)(dx*dx + dy*dy));
X r = a * b * dis / sqrt((double) (b*b*dx*dx + a*a*dy*dy));
X if (fabs(dis - r) <= tol) {
X *px = (int)(r*dx/dis + ((dx < 0) ? -.5 : .5)) + e->center.x;
X *py = (int)(r*dy/dis + ((dy < 0) ? -.5 : .5)) + e->center.y;
X return(e);
X }
X }
X return(NULL);
X }
X
XF_line *
Xline_search(x, y, tolerance, px, py)
Xint x, y, tolerance, *px, *py;
X{ /* return the pointer to lines object if the search is successful
X otherwise return NULL.
X The value returned via (px, py) is the closest point on the
X vector to point (x, y) */
X
X F_line *lines;
X F_point *point;
X int x1, y1, x2, y2;
X float tol2;
X
X tol2 = (float) tolerance * tolerance;
X for (lines = objects.lines; lines != NULL; lines = lines->next) {
X point = lines->points;
X x1 = point->x;
X y1 = point->y;
X if (abs(x - x1) <= tolerance && abs(y - y1) <= tolerance) {
X *px = x1; *py = y1;
X return(lines);
X }
X for (point = point->next; point != NULL; point = point->next) {
X x2 = point->x;
X y2 = point->y;
X if (close_to_vector(x1, y1, x2, y2, x, y, tolerance, tol2,
X px, py))
X return(lines);
X x1 = x2;
X y1 = y2;
X }
X }
X return(NULL);
X }
X
XF_spline *
Xspline_search(x, y, tolerance, px, py)
Xint x, y, tolerance, *px, *py;
X{ /* return the pointer to lines object if the search is successful
X otherwise return NULL. */
X
X F_spline *splines;
X F_point *point;
X int x1, y1, x2, y2;
X float tol2;
X
X tol2 = (float) tolerance * tolerance;
X for (splines = objects.splines; splines != NULL; splines = splines->next) {
X point = splines->points;
X x1 = point->x;
X y1 = point->y;
X for (point = point->next; point != NULL; point = point->next) {
X x2 = point->x;
X y2 = point->y;
X if (close_to_vector(x1, y1, x2, y2, x, y, tolerance, tol2,
X px, py))
X return(splines);
X x1 = x2;
X y1 = y2;
X }
X }
X return(NULL);
X }
X
XF_text *
Xtext_search(x, y)
Xint x, y;
X{
X F_text *t;
X
X for (t = objects.texts; t != NULL; t = t->next) {
X if (t->base_y - t->height > y) continue;
X if (t->base_y < y) continue;
X if (t->base_x > x) continue;
X if (t->base_x + t->length < x) continue;
X return(t);
X }
X return(NULL);
X }
END_OF_search.c
if test 3347 -ne `wc -c <search.c`; then
echo shar: \"search.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f trans.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"trans.c\"
else
echo shar: Extracting \"trans.c\" \(2859 characters\)
sed "s/^X//" >trans.c <<'END_OF_trans.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "object.h"
X
Xtranslate_ellipse(ellipse, dx, dy)
XF_ellipse *ellipse;
Xint dx, dy;
X{
X ellipse->center.x += dx;
X ellipse->center.y += dy;
X ellipse->start.x += dx;
X ellipse->start.y += dy;
X ellipse->end.x += dx;
X ellipse->end.y += dy;
X }
X
Xtranslate_arc(arc, dx, dy)
XF_arc *arc;
Xint dx, dy;
X{
X arc->center.x += (float)dx;
X arc->center.y += (float)dy;
X arc->point[0].x += dx;
X arc->point[0].y += dy;
X arc->point[1].x += dx;
X arc->point[1].y += dy;
X arc->point[2].x += dx;
X arc->point[2].y += dy;
X }
X
Xtranslate_line(line, dx, dy)
XF_line *line;
Xint dx, dy;
X{
X F_point *point;
X
X for (point = line->points; point != NULL; point = point->next) {
X point->x += dx;
X point->y += dy;
X }
X }
X
Xtranslate_text(text, dx, dy)
XF_text *text;
Xint dx, dy;
X{
X text->base_x += dx;
X text->base_y += dy;
X }
X
Xtranslate_spline(spline, dx, dy)
XF_spline *spline;
Xint dx, dy;
X{
X F_point *point;
X F_control *cp;
X
X for (point = spline->points; point != NULL; point = point->next) {
X point->x += dx;
X point->y += dy;
X }
X for (cp = spline->controls; cp != NULL; cp = cp->next) {
X cp->lx += dx;
X cp->ly += dy;
X cp->rx += dx;
X cp->ry += dy;
X }
X }
X
Xtranslate_compound(compound, dx, dy)
XF_compound *compound;
Xint dx, dy;
X{
X compound->nwcorner.x += dx;
X compound->nwcorner.y += dy;
X compound->secorner.x += dx;
X compound->secorner.y += dy;
X
X translate_lines(compound->lines, dx, dy);
X translate_splines(compound->splines, dx, dy);
X translate_ellipses(compound->ellipses, dx, dy);
X translate_arcs(compound->arcs, dx, dy);
X translate_texts(compound->texts, dx, dy);
X translate_compounds(compound->compounds, dx, dy);
X }
X
Xtranslate_arcs(arcs, dx, dy)
XF_arc *arcs;
Xint dx, dy;
X{
X F_arc *a;
X
X for (a = arcs; a != NULL; a = a-> next)
X translate_arc(a, dx, dy);
X }
X
Xtranslate_compounds(compounds, dx, dy)
XF_compound *compounds;
Xint dx, dy;
X{
X F_compound *c;
X
X for (c = compounds; c != NULL; c = c->next)
X translate_compound(c, dx, dy);
X }
X
Xtranslate_ellipses(ellipses, dx, dy)
XF_ellipse *ellipses;
Xint dx, dy;
X{
X F_ellipse *e;
X
X for (e = ellipses; e != NULL; e = e-> next)
X translate_ellipse(e, dx, dy);
X }
X
Xtranslate_lines(lines, dx, dy)
XF_line *lines;
Xint dx, dy;
X{
X F_line *l;
X
X for (l = lines; l != NULL; l = l->next) translate_line(l, dx, dy);
X }
X
Xtranslate_splines(splines, dx, dy)
XF_spline *splines;
Xint dx, dy;
X{
X F_spline *s;
X
X for (s = splines; s != NULL; s = s->next)
X translate_spline(s, dx, dy);
X }
X
Xtranslate_texts(texts, dx, dy)
XF_text *texts;
Xint dx, dy;
X{
X F_text *t;
X
X for (t = texts; t != NULL; t = t->next)
X translate_text(t, dx, dy);
X }
X
END_OF_trans.c
if test 2859 -ne `wc -c <trans.c`; then
echo shar: \"trans.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f turn.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"turn.c\"
else
echo shar: Extracting \"turn.c\" \(3449 characters\)
sed "s/^X//" >turn.c <<'END_OF_turn.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at 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 TOLERANCE 7
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 pointmarker_shown;
X
Xextern F_compound objects;
Xextern F_line *line_search();
Xextern F_spline *spline_search();
X
X init_turn();
X
Xturn_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_turn;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&pick15_cursor);
X }
X
Xinit_turn(x, y)
Xint x, y;
X{
X F_line *l;
X F_spline *s;
X int dummy;
X
X if ((l = line_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
X if (l->type == T_BOX) return;
X line_2_spline(l);
X turn_selected();
X }
X else if ((s = spline_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
X spline_2_line(s);
X turn_selected();
X }
X }
X
Xline_2_spline(l)
XF_line *l;
X{
X F_spline *s;
X
X if (num_points(l->points) < 3) {
X put_msg("Can't turn this line into spline");
X return(-1);
X }
X if (pointmarker_shown) toggle_linepointmarker(l);
X draw_line(l, ERASE);
X delete_line(&objects.lines, l);
X
X if (NULL == (Spline_malloc(s))) {
X put_msg(Err_mem);
X return(-1);
X }
X
X if (l->type == T_POLYGON)
X s->type = T_CLOSED_INTERPOLATED;
X else
X s->type = T_OPEN_INTERPOLATED;
X s->style = l->style;
X s->thickness = l->thickness;
X s->color = l->color;
X s->depth = l->depth;
X s->style_val = l->style_val;
X s->pen = l->pen;
X s->area_fill = l->area_fill;
X s->for_arrow = l->for_arrow;
X s->back_arrow = l->back_arrow;
X s->points = l->points;
X s->controls = NULL;
X s->next = NULL;
X
X l->for_arrow = l->back_arrow = NULL;
X l->area_fill = NULL;
X l->pen = NULL;
X l->points = NULL;
X
X if (-1 == create_control_list(s)) {
X free(s);
X return(-1);
X }
X
X remake_control_points(s);
X draw_spline(s, PAINT);
X if (pointmarker_shown) toggle_splinepointmarker(s);
X clean_up();
X set_action_object(F_TURN, O_POLYLINE);
X insert_spline(&objects.splines, s);
X set_latestspline(s);
X set_latestline(l);
X return(1);
X }
X
Xspline_2_line(s)
XF_spline *s;
X{
X F_line *l;
X
X if (pointmarker_shown) toggle_splinepointmarker(s);
X draw_spline(s, ERASE);
X delete_spline(&objects.splines, s);
X
X /* Now we turn s into a line */
X if (NULL == (Line_malloc(l))) {
X put_msg(Err_mem);
X return(-1);
X }
X
X if (s->type == T_OPEN_INTERPOLATED)
X l->type = T_POLYLINE;
X else if (s->type == T_CLOSED_INTERPOLATED)
X l->type = T_POLYGON;
X l->style = s->style;
X l->thickness = s->thickness;
X l->color = s->color;
X l->depth = s->depth;
X l->style_val = s->style_val;
X l->pen = s->pen;
X l->area_fill = s->area_fill;
X l->for_arrow = s->for_arrow;
X l->back_arrow = s->back_arrow;
X l->points = s->points;
X l->next = NULL;
X
X s->for_arrow = s->back_arrow = NULL;
X s->area_fill = NULL;
X s->pen = NULL;
X s->points = NULL;
X
X draw_line(l, PAINT);
X if (pointmarker_shown) toggle_linepointmarker(l);
X clean_up();
X set_action_object(F_TURN, O_SPLINE);
X insert_line(&objects.lines, l);
X set_latestspline(s);
X set_latestline(l);
X return(1);
X }
END_OF_turn.c
if test 3449 -ne `wc -c <turn.c`; then
echo shar: \"turn.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xtra.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"xtra.c\"
else
echo shar: Extracting \"xtra.c\" \(4679 characters\)
sed "s/^X//" >xtra.c <<'END_OF_xtra.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at 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#include "font.h"
X
Xpr_size pf_textwidth(n, f, s)
X int n;
X XFontStruct *f;
X char *s;
X{
X int dummy;
X XCharStruct ch;
X pr_size ret;
X
X XTextExtents(f, s, n, &dummy, &dummy, &dummy, &ch);
X ret.x = ch.width;
X ret.y = ch.ascent + ch.descent;
X return (ret);
X}
X
Xstatic GC makegc(op)
X{
X register GC ngc;
X XGCValues gcv;
X
X ngc = XCreateGC(tool_d, XtWindow(canvas_sw), 0, &gcv);
X XCopyGC(tool_d, gc, ~0, ngc);
X XSetFunction(tool_d, ngc, op);
X XSetFont(tool_d, ngc, roman_font->fid);
X return (ngc);
X}
X
Xinit_gc()
X{
X gccache[PAINT] = makegc(PAINT);
X gccache[ERASE] = makegc(ERASE);
X gccache[INV_PAINT] = makegc(INV_PAINT);
X gccache[MERGE] = makegc(MERGE);
X}
X
X/*
X** The next routine is easy to implement, but I haven't missed
X** it yet. Generally it is a bad idea to warp the mouse without
X** the users consent, so maybe the original code is wrong?
X*/
Xwin_setmouseposition(w,x,y)
X FDTYPE w;
X int x, y;
X{
X}
X
Xint wmgr_confirm(w, message)
X Window w;
X char *message;
X{
X static TOOL label = NULL, confirm = NULL;
X XEvent event;
X Arg tmp_args[2];
X
X if( confirm == NULL )
X {
X Position rootx, rooty;
X Window win;
X Arg confirm_args[5];
X
X XTranslateCoordinates(tool_d, w, XDefaultRootWindow(tool_d),
X 150, 200, &rootx, &rooty, &win);
X XtSetArg(confirm_args[0], XtNallowShellResize, True);
X XtSetArg(confirm_args[1], XtNx, rootx);
X XtSetArg(confirm_args[2], XtNy, rooty);
X confirm = XtCreatePopupShell("confirm",
X overrideShellWidgetClass, tool,
X confirm_args, 3);
X XtSetArg(tmp_args[0], XtNfont, bold_font);
X label = XtCreateManagedWidget("label", labelWidgetClass,
X confirm, tmp_args, 1);
X }
X
X XtSetArg(tmp_args[0], XtNlabel, message);
X XtSetValues(label, tmp_args, 1);
X XtPopup(confirm, XtGrabNone);
X for (;;)
X {
X XMaskEvent(tool_d, ButtonPressMask|ExposureMask, &event);
X if (event.type == ButtonPress)
X {
X XtPopdown(confirm);
X if (((XButtonEvent *)&event)->button == Button1)
X return (-1);
X else
X return (0);
X }
X /* pass all other events */
X XtDispatchEvent(&event);
X }
X/*NOTREACHED*/
X}
X
Xprompt_string(prompt, reply)
X char *prompt, *reply;
X{
X register int x, y;
X register int len, width;
X register char *r = reply;
X XEvent event;
X register XKeyEvent *ke = (XKeyEvent *)&event;
X char buf[1];
X XWindowAttributes attr;
X
X XClearArea(tool_d, msgswfd, 0, 0, 0, 0, False);
X /* uses knowledge that gccache[PAINT] uses roman_font - tsk */
X len = strlen(prompt);
X width = char_width(roman_font);
X y = char_height(roman_font) + 2;
X XDrawString(tool_d, msgswfd, gccache[PAINT], 2, y, prompt, len);
X x = width * len + 4;
X XGetWindowAttributes(tool_d, msgswfd, &attr);
X XSelectInput(tool_d, msgswfd, attr.your_event_mask | KeyPressMask);
X for (;;)
X {
X XWindowEvent(tool_d, msgswfd, KeyPressMask, &event);
X if (event.type != KeyPress)
X continue;
X if (XLookupString(ke, buf, sizeof(buf), NULL, NULL) <= 0)
X continue;
X switch (buf[0])
X {
X case '\b':
X case '\0177':
X if (r != reply)
X {
X x -= width;
X --r;
X XDrawString(tool_d, msgswfd, gccache[ERASE],
X x, y, r, 1);
X }
X break;
X case 'U' & 0x1f:
X case 'X' & 0x1f:
X while (r != reply)
X {
X x -= width;
X --r;
X XDrawString(tool_d, msgswfd, gccache[ERASE],
X x, y, r, 1);
X }
X break;
X case '\n':
X case '\r':
X *r = '\0';
X XClearArea(tool_d, msgswfd, 0, 0, 0, 0, False);
X return;
X default:
X if (buf[0] < ' ' || buf[0] > '~')
X continue;
X XDrawString(tool_d, msgswfd, gccache[PAINT],
X x, y, buf, 1);
X x += width;
X *r++ = buf[0];
X break;
X }
X }
X}
X
Xstatic void
XCvtStringToFloat(args, num_args, fromVal, toVal)
XXrmValuePtr args;
XCardinal *num_args;
XXrmValuePtr fromVal;
XXrmValuePtr toVal;
X{
X static float f;
X
X if(*num_args != 0 )
X XtWarning("String to Float conversion needs no extra arguments");
X if(sscanf((char *)fromVal->addr, "%f", &f) == 1)
X {
X (*toVal).size = sizeof(float);
X (*toVal).addr = (caddr_t) &f;
X }
X else
X XtStringConversionWarning((char *) fromVal->addr, "Float");
X}
X
Xstatic void
XCvtIntToFloat(args, num_args, fromVal, toVal)
XXrmValuePtr args;
XCardinal *num_args;
XXrmValuePtr fromVal;
XXrmValuePtr toVal;
X{
X static float f;
X
X if(*num_args != 0 )
X XtWarning("Int to Float conversion needs no extra arguments");
X f = *(int *)fromVal->addr;
X (*toVal).size = sizeof(float);
X (*toVal).addr = (caddr_t) &f;
X}
X
Xfix_converters()
X{
X XtAddConverter("String", "Float", CvtStringToFloat, NULL, 0);
X XtAddConverter("Int", "Float", CvtIntToFloat, NULL, 0);
X}
END_OF_xtra.c
if test 4679 -ne `wc -c <xtra.c`; then
echo shar: \"xtra.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 2 \(of 11\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 11 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
--
Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330
More information about the Comp.sources.x
mailing list