v01i004: xfig: a MacDraw style line editor(X11), Part03/11
Mike Wexler
mikew at wyse.wyse.com
Wed Aug 17 06:23:35 AEST 1988
Submitted-by: ken at cs.rochester.edu (Ken Yap)
Posting-number: Volume 1, Issue 4
Archive-name: xfig/part03
#! /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 3 (of 11)."
# Contents: Makefile arc.c deletept.c grid.c popup.c scale.c spline.c
# text.c util.c
# Wrapped by mikew at wyse on Tue Aug 16 13:14:36 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(5383 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Warning: the cpp used on this machine replaces
X# all newlines and multiple tabs/spaces in a macro
X# expansion with a single space. Imake tries to
X# compensate for this, but is not always
X# successful.
X#
X
X#
X# This makefile is automatically generated by imake... do not modify
X# or you may lose your changes when imake generates makefiles again.
X# Ignore this message if you are not using imake.
X#
X
X TOP = /usr/new/src/x/x11.2
X AS = as
X CC = cc
X CPP = /lib/cpp
X LD = ld
X LINT = lint
X INSTALL = install
X TAGS = ctags
X RM = rm -f
X MV = mv
X LN = ln -s
X RANLIB = ranlib
X AR = ar clq
X LS = ls
X LINTOPTS = -axz
X LINTLIBFLAG = -C
X MAKE = make
X STD_DEFINES =
X CDEBUGFLAGS = -O4
X DESTDIR = /usr/new
X
X PATHSEP = /
X DEPEND = $(DEPENDSRC)/makedepend
X IMAKE = $(IMAKESRC)/imake
X RGB = $(RGBSRC)/rgb
X CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
X LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
X LDFLAGS = $(CDEBUGFLAGS) $(SYS_LIBRARIES) $(SYSAUX_LIBRARIES)
X INSTUIDFLAGS = -m 4755
X INSTLIBFLAGS = -m 0664
X INSTINCFLAGS = -m 0444
X INSTMANFLAGS = -m 0444
X INSTAPPFLAGS = -m 0444
X
X USRLIBDIR = $(DESTDIR)/usr/lib
X BINDIR = $(DESTDIR)/usr/bin/X11
X LIBDIR = $(USRLIBDIR)/X11
X LINTLIBDIR = $(USRLIBDIR)/lint
X INCDIR = $(DESTDIR)/usr/include/X11
X FONTDIR = $(LIBDIR)/fonts
X UWMDIR = $(LIBDIR)/uwm
X AWMDIR = $(LIBDIR)/awm
X MANDIR = $(DESTDIR)/usr/man/mann
X XAPPLOADDIR = $(LIBDIR)/app-defaults
X ADMDIR = $(DESTDIR)/usr/adm
X
X CLIENTSRC = $(TOP)/clients
X DEMOSRC = $(TOP)/demos
X LIBSRC = $(TOP)/lib
X FONTSRC = $(TOP)/fonts
X INCLUDESRC = $(TOP)/X11
X SERVERSRC = $(TOP)/server
X UTILSRC = $(TOP)/util
X EXAMPLESRC = $(TOP)/examples
X CONTRIBSRC = $(TOP)/contrib
X DOCSRC = $(TOP)/doc
X DEPENDSRC = $(UTILSRC)/makedepend
X IMAKESRC = $(UTILSRC)/imake
X IRULESRC = $(UTILSRC)/imake.includes
X RGBSRC = $(UTILSRC)/rgb
X XLIBSRC = $(LIBSRC)/X
X TOOLKITSRC = $(LIBSRC)/Xt
X AWIDGETSRC = $(LIBSRC)/Xaw
X OLDXLIBSRC = $(LIBSRC)/oldX
X EXTENSIONSRC = $(TOP)/extensions
X XMANSRC = $(DOCSRC)/Xlib/Xman
X EXTENSIONLIB = $(EXTENSIONSRC)/lib/libXext.a
X XLIB = $(XLIBSRC)/libX11.a
X OLDXLIB = $(OLDXLIBSRC)/liboldX.a
X XTOOLLIB = $(TOOLKITSRC)/libXt.a
X XAWLIB = $(AWIDGETSRC)/libXaw.a
X LINTXLIB = $(XLIBSRC)/llib-lX11.ln
X LINTXTOOL = $(TOOLKITSRC)/llib-lXt.ln
X LINTXAW = $(AWIDGETSRC)/llib-lXaw.ln
X INCLUDES = -I$(TOP)
X MACROFILE = Sun.macros
X IMAKE_CMD = $(NEWTOP)$(IMAKE) -TImake.tmpl \
X -I$(NEWTOP)$(IRULESRC) \
X -s Makefile
X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a \
X tags TAGS make.log
X
XDEFINES = -I/usr/new/include -DX11
XSYS_LIBRARIES = -lm
XSYSAUX_LIBRARIES = -L/usr/new/lib -lXaw -lXt -lX
X
XSRCS= addpt.c arc.c arrow.c autoarrow.c\
X bitmap.c blink.c bound.c box.c break.c\
X canvas.c char.c color.c copy.c cursor.c curve.c\
X deletept.c dir.c drag.c draw.c ellipse.c\
X file.c flip.c font.c free.c\
X geom.c global.c glue.c graphics.c grid.c\
X intspline.c latex_line.c line.c list.c\
X main.c move.c movept.c msgsw.c\
X panel.c popup.c puterr.c\
X read.c read1_3.c redisplay.c remove.c rotate.c ruler.c\
X save.c scale.c search.c spline.c\
X text.c trans.c turn.c undo.c util.c xtra.c
X
XOBJS= addpt.o arc.o arrow.o autoarrow.o\
X bitmap.o blink.o bound.o box.o break.o\
X canvas.o char.o color.o copy.o cursor.o curve.o\
X deletept.o dir.o drag.o draw.o ellipse.o\
X file.o flip.o font.o free.o\
X geom.o global.o glue.o graphics.o grid.o\
X intspline.o latex_line.o line.o list.o\
X main.o move.o movept.o msgsw.o\
X panel.o popup.o puterr.o\
X read.o read1_3.o redisplay.o remove.o rotate.o ruler.o\
X save.o scale.o search.o spline.o\
X text.o trans.o turn.o undo.o util.o xtra.o
X
XF2PSRC = arrow.c f2p.c free.c read.c read1_3.c
XF2POBJ = arrow.o f2p.o free.o read.o read1_3.o
X
XF2PSSRC = arrow.c bound.c f2ps.c free.c read.c read1_3.c
XF2PSOBJ = arrow.o bound.o f2ps.o free.o read.o read1_3.o
X
X PROGRAM = xfig
X
Xall:: xfig
X
Xxfig: $(OBJS) $(LOCAL_LIBRARIES)
X $(RM) $@
X $(CC) -o $@ $(OBJS) $(LOCAL_LIBRARIES) $(LDFLAGS)
X
Xrelink::
X $(RM) $(PROGRAM)
X $(MAKE) $(MFLAGS) $(PROGRAM)
X
Xinstall:: xfig
X $(INSTALL) -c $(INSTALLFLAGS) xfig $(BINDIR)
X
Xdepend:: $(DEPEND)
X
Xdepend::
X $(DEPEND) -s "# DO NOT DELETE" -- $(CFLAGS) -- $(SRCS)
X
X$(DEPEND):
X @echo "making $(DEPENDSRC)"; \
X cd $(DEPENDSRC); $(MAKE)
X
Xclean::
X $(RM) $(PROGRAM)
X
Xf2p: $(F2POBJ)
X $(RM) $@
X $(CC) -o $@ $(F2POBJ) $(LDFLAGS)
X
Xrelink::
X $(RM) f2p
X $(MAKE) $(MFLAGS) f2p
X
Xclean::
X $(RM) f2p
X
Xf2ps: $(F2PSOBJ)
X $(RM) $@
X $(CC) -o $@ $(F2PSOBJ) $(LDFLAGS)
X
Xrelink::
X $(RM) f2ps
X $(MAKE) $(MFLAGS) f2ps
X
Xclean::
X $(RM) f2ps
X
Xclean::
X $(RM_CMD) \#*
X
XMakefile:: $(IMAKE)
X
XMakefile:: Imakefile \
X $(IRULESRC)/Imake.tmpl \
X $(IRULESRC)/Imake.rules \
X $(IRULESRC)/$(MACROFILE)
X -$(RM) Makefile.bak; $(MV) Makefile Makefile.bak
X $(IMAKE_CMD) -DTOPDIR=$(TOP)
X
X$(IMAKE):
X @echo "making $(IMAKESRC)"; \
X cd $(IMAKESRC); $(MAKE)
X
Xtags::
X $(TAGS) -w *.[ch]
X $(TAGS) -xw *.[ch] > TAGS
X
Xinstall::
X @echo "install done"
X
XMakefiles::
X
END_OF_Makefile
if test 5383 -ne `wc -c <Makefile`; then
echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f arc.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"arc.c\"
else
echo shar: Extracting \"arc.c\" \(5097 characters\)
sed "s/^X//" >arc.c <<'END_OF_arc.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 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 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) create_arcobject(x, y);
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 arc->area_fill = NULL;
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);
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(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 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_arc.c
if test 5097 -ne `wc -c <arc.c`; then
echo shar: \"arc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f deletept.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"deletept.c\"
else
echo shar: Extracting \"deletept.c\" \(5960 characters\)
sed "s/^X//" >deletept.c <<'END_OF_deletept.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 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) {
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_deletept.c
if test 5960 -ne `wc -c <deletept.c`; then
echo shar: \"deletept.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f grid.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"grid.c\"
else
echo shar: Extracting \"grid.c\" \(4768 characters\)
sed "s/^X//" >grid.c <<'END_OF_grid.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 "const.h"
X#include "func.h"
X#include "paintop.h"
X
Xstatic int cur_grid = -1;
Xextern int CANVAS_WIDTH, CANVAS_HEIGHT;
X
X#ifndef X11
Xstatic PIXRECT h_grid_pr, v_grid1_pr, v_grid2_pr;
X
Xinit_grid()
X{
X int x, y;
X
X h_grid_pr = mem_create(CANVAS_WIDTH, 1, 1);
X v_grid1_pr = mem_create(1, CANVAS_HEIGHT, 1);
X v_grid2_pr = mem_create(1, CANVAS_HEIGHT, 1);
X for (x = 4; x < CANVAS_WIDTH; x +=5)
X pr_put(h_grid_pr, x, 0, 1);
X for (x = 0, y = 4; y <= CANVAS_HEIGHT; x++, y +=5)
X if (x == 3)
X x = -1;
X else
X pr_put(v_grid1_pr, 0, y, 1);
X for (x = 0, y = 4; y <= CANVAS_HEIGHT; x++, y +=5)
X if (x == 7)
X x = -1;
X else
X pr_put(v_grid2_pr, 0, y, 1);
X }
X
Xsetup_grid(grid)
Xint grid;
X{
X if (cur_grid == grid) {
X cur_grid = -1;
X }
X else {
X if (grid == F_GRID1)
X put_msg("Quarter inch GRID");
X else
X put_msg("Half inch GRID");
X if (cur_grid != -1) {
X draw_grid(cur_grid);
X }
X cur_grid = grid;
X }
X draw_grid(grid);
X }
X
X
Xdraw_grid(grid)
Xint grid;
X{
X int x, y, resolution;
X PIXRECT v_grid_pr;
X
X if (grid == F_GRID1) {
X v_grid_pr = v_grid1_pr;
X resolution = PIX_PER_INCH / 4;
X }
X else {
X v_grid_pr = v_grid2_pr;
X resolution = PIX_PER_INCH / 2;
X }
X
X /* vertical grid */
X for (x = resolution - 1; x <= CANVAS_WIDTH; x += resolution)
X pw_write(canvas_pixwin, x, 0, 1, CANVAS_HEIGHT, INV_PAINT,
X v_grid_pr, 0, 0);
X
X /* horizontal grid */
X for (y = resolution - 1; y <= CANVAS_HEIGHT; y += resolution)
X pw_write(canvas_pixwin, 0, y, CANVAS_WIDTH, 1, INV_PAINT,
X h_grid_pr, 0, 0);
X }
X
Xredisplay_grid()
X{
X if (cur_grid == -1) return;
X draw_grid(cur_grid);
X }
X
X#else
X
X#define null_width 32
X#define null_height 32
Xstatic char null_bits[null_width * null_height / 8] = { 0 };
X
X#define quarter_width 20
X#define quarter_height 20
Xstatic char quarter_bits[] = {
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x42, 0x08};
X
X#define half_width 40
X#define half_height 40
Xstatic char half_bits[] = {
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X 0x00, 0x00, 0x00, 0x10, 0x42, 0x08, 0x21, 0x84};
X
Xstatic Pixmap null_pm, quarter_pm, half_pm;
X
Xinit_grid()
X{
X null_pm = XCreatePixmapFromBitmapData(tool_d, canvas_pixwin,
X null_bits, null_width, null_height,
X BlackPixelOfScreen(tool_s), WhitePixelOfScreen(tool_s), 1);
X quarter_pm = XCreatePixmapFromBitmapData(tool_d, canvas_pixwin,
X quarter_bits, quarter_width, quarter_height,
X BlackPixelOfScreen(tool_s), WhitePixelOfScreen(tool_s), 1);
X half_pm = XCreatePixmapFromBitmapData(tool_d, canvas_pixwin,
X half_bits, half_width, half_height,
X BlackPixelOfScreen(tool_s), WhitePixelOfScreen(tool_s), 1);
X}
X
Xsetup_grid(grid)
X int grid;
X{
X static Arg grid_args[] =
X {
X { XtNbackgroundPixmap, (XtArgVal)NULL },
X };
X
X if (grid == cur_grid)
X {
X grid_args[0].value = (XtArgVal)null_pm;
X grid = -1;
X }
X if (grid == F_GRID1)
X grid_args[0].value = (XtArgVal)quarter_pm;
X else if (grid == F_GRID2)
X grid_args[0].value = (XtArgVal)half_pm;
X cur_grid = grid;
X XtSetValues(canvas_sw, grid_args, XtNumber(grid_args));
X}
X
Xredisplay_grid()
X{
X}
X#endif X11
END_OF_grid.c
if test 4768 -ne `wc -c <grid.c`; then
echo shar: \"grid.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f popup.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"popup.c\"
else
echo shar: Extracting \"popup.c\" \(5798 characters\)
sed "s/^X//" >popup.c <<'END_OF_popup.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 "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, "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, "Status", (caddr_t) F_STATUS},
X {MENU_IMAGESTRING, "Change Directory", (caddr_t) F_CHDIR},
X /*
X {MENU_IMAGESTRING, "Print Directory", (caddr_t) F_PWDIR},
X */
X {MENU_IMAGESTRING, "Save & Exit", (caddr_t) F_SAVE_N_EXIT},
X {MENU_IMAGESTRING, "Quit", (caddr_t) F_QUIT},
X {MENU_IMAGESTRING, "Save as BITMAP ..", (caddr_t) F_SAVE_BITMAP},
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
X#ifdef X11
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)0 },
X { XtNy, (XtArgVal)0 },
X { XtNlabel, (XtArgVal)" " },
X { XtNwidth, (XtArgVal)0 },
X { XtNheight, (XtArgVal)0 },
X { XtNcallback, (XtArgVal)pane_callbacks },
X};
X
XTOOL menu;
X
Xint init_menu(tool)
X TOOL tool;
X{
X TOOL panes, pane;
X register int i, tlen, rlen = 0;
X register MENUITEM *mi;
X XtTranslations popdown_actions, pane_actions;
X
X menu = XtCreatePopupShell("popup_menu", overrideShellWidgetClass, tool,
X menu_args, 0);
X popdown_actions = XtParseTranslationTable(
X "<Btn3Up>:MenuPopdown()\n\
X <LeaveWindow>:MenuPopdown()\n");
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[3].value = char_width(canvas_font) * rlen + 10;
X
X pane_args[2].value = (XtArgVal)"COMMANDS";
X pane = XtCreateManagedWidget("title", labelWidgetClass,
X panes, pane_args, 4);
X for (i = 0; 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#else
X
Xset_popupmenu(ie)
XINPUTEVENT *ie;
X{
X MENUITEM *mi;
X char menu_code;
X int x, y;
X
X x = ie->ie_locx; y = ie->ie_locy;
X if ((mi = menu_display(&menu_ptr, ie, canvas_swfd)) == NULL) return;
X win_setmouseposition(canvas_swfd, x, y);
X menu_code = (short) mi->mi_data;
X#endif X11
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_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_STATUS :
X status();
X break;
X case F_SAVE_N_EXIT :
X if (! figure_modified) quit();
X if (no_object()) quit();
X if (*current_file != 0) {
X if (0 == write_file(current_file, 0)) quit();
X }
X else {
X blink_msg();
X init_msg_receiving(save_and_exit, "Save in file : ");
X }
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#ifdef X11
X XtPopdown(menu);
X#endif X11
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 }
END_OF_popup.c
if test 5798 -ne `wc -c <popup.c`; then
echo shar: \"popup.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f scale.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"scale.c\"
else
echo shar: Extracting \"scale.c\" \(6178 characters\)
sed "s/^X//" >scale.c <<'END_OF_scale.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#define min(a, b) (((a) < (b)) ? (a) : (b))
X#define max(a, b) (((a) > (b)) ? (a) : (b))
X#define round(a) (int)(a + 0.5)
X
Xextern int fix_x, fix_y, cur_x, cur_y;
Xextern F_pos last_position, new_position; /* used in undo */
X
Xextern F_compound *compound_point_search();
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 prescale_compound(), elastic_compoundbox();
X
Xstatic F_compound *compound;
Xstatic double cosa, sina;
Xstatic int fromx, fromy;
X
X init_scale_compound();
X
Xscale_compound_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_scale_compound;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&pick15_cursor);
X reset_action_on();
X }
X
Xinit_scale_compound(x, y)
Xint x, y;
X{
X double dx, dy, l;
X
X if ((compound = compound_point_search(x, y, TOLERANCE, &cur_x, &cur_y))
X == NULL) {
X return;
X }
X if (compound->nwcorner.x == cur_x)
X fix_x = compound->secorner.x;
X else
X fix_x = compound->nwcorner.x;
X if (compound->nwcorner.y == cur_y)
X fix_y = compound->secorner.y;
X else
X fix_y = compound->nwcorner.y;
X
X dx = cur_x - fix_x; dy = cur_y - fix_y;
X l = sqrt(dx*dx + dy*dy);
X cosa = fabs(dx / l); sina = fabs(dy / l);
X
X fromx = cur_x; fromy = cur_y;
X win_setmouseposition(canvas_swfd, cur_x, cur_y);
X draw_compoundbox(compound, INV_PAINT);
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT);
X set_latestcompound(compound);
X canvas_locmove_proc = elastic_compoundbox;
X canvas_middlebut_proc = prescale_compound;
X canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X set_action_on();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, x, y);
X }
X
Xelastic_compoundbox(x, y)
Xint x, y;
X{
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT);
X compute_adjustposition(x, y);
X win_setmouseposition(canvas_swfd, cur_x, cur_y);
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT);
X }
X
Xcompute_adjustposition(x, y)
Xint x, y;
X{
X double xx, yy, d;
X
X xx = x - fix_x;
X yy = y - fix_y;
X d = sqrt(xx*xx + yy*yy);
X if (xx < 0)
X cur_x = fix_x - round(d * cosa);
X else
X cur_x = fix_x + round(d * cosa);
X if (yy < 0)
X cur_y = fix_y - round(d * sina);
X else
X cur_y = fix_y + round(d * sina);
X }
X
Xprescale_compound(x, y)
Xint x, y;
X{
X float scalex, scaley;
X
X draw_rectbox(fix_x, fix_y, cur_x, cur_y, INV_PAINT);
X compute_adjustposition(x, y);
X erase_compound(compound);
X
X scalex = ((float) (cur_x - fix_x)) / (fromx - fix_x);
X scaley = ((float) (cur_y - fix_y)) / (fromy - fix_y);
X scale_compound(compound, scalex, scaley, fix_x, fix_y);
X
X draw_compound(compound);
X draw_compoundbox(compound, INV_PAINT);
X last_position.x = fromx;
X last_position.y = fromy;
X new_position.x = cur_x;
X new_position.y = cur_y;
X clean_up();
X set_action_object(F_SCALE, O_COMPOUND);
X set_latestcompound(compound);
X set_modifiedflag();
X scale_compound_selected();
X }
X
Xscale_compound(c, sx, sy, refx, refy)
XF_compound *c;
Xfloat sx, sy;
Xint refx, refy;
X{
X F_line *l;
X F_spline *s;
X F_ellipse *e;
X F_text *t;
X F_arc *a;
X int x1, y1, x2, y2;
X
X x1 = round(refx + (c->nwcorner.x - refx) * sx);
X y1 = round(refy + (c->nwcorner.y - refy) * sy);
X x2 = round(refx + (c->secorner.x - refx) * sx);
X y2 = round(refy + (c->secorner.y - refy) * sy);
X c->nwcorner.x = min(x1, x2);
X c->nwcorner.y = min(y1, y2);
X c->secorner.x = max(x1, x2);
X c->secorner.y = max(y1, y2);
X
X for (l = c->lines; l != NULL; l = l->next) {
X scale_line(l, sx, sy, refx, refy);
X }
X for (s = c->splines; s != NULL; s = s->next) {
X scale_spline(s, sx, sy, refx, refy);
X }
X for (a = c->arcs; a != NULL; a = a->next) {
X scale_arc(a, sx, sy, refx, refy);
X }
X for (e = c->ellipses; e != NULL; e = e->next) {
X scale_ellipse(e, sx, sy, refx, refy);
X }
X for (t = c->texts; t != NULL; t = t->next) {
X scale_text(t, sx, sy, refx, refy);
X }
X }
X
Xscale_line(l, sx, sy, refx, refy)
XF_line *l;
Xfloat sx, sy;
Xint refx, refy;
X{
X F_point *p;
X
X for (p = l->points; p != NULL; p = p->next) {
X p->x = round(refx + (p->x - refx) * sx);
X p->y = round(refy + (p->y - refy) * sy);
X }
X }
X
Xscale_spline(s, sx, sy, refx, refy)
XF_spline *s;
Xfloat sx, sy;
Xint refx, refy;
X{
X F_point *p;
X F_control *c;
X
X for (p = s->points; p != NULL; p = p->next) {
X p->x = round(refx + (p->x - refx) * sx);
X p->y = round(refy + (p->y - refy) * sy);
X }
X for (c = s->controls; c != NULL; c = c->next) {
X c->lx = refx + (c->lx - refx) * sx;
X c->ly = refy + (c->ly - refy) * sy;
X c->rx = refx + (c->rx - refx) * sx;
X c->ry = refy + (c->ry - refy) * sy;
X }
X }
X
Xscale_arc(a, sx, sy, refx, refy)
XF_arc *a;
Xfloat sx, sy;
Xint refx, refy;
X{
X int i;
X
X for (i = 0; i < 3; i++) {
X a->point[i].x = round(refx + (a->point[i].x - refx) * sx);
X a->point[i].y = round(refy + (a->point[i].y - refy) * sy);
X }
X compute_arccenter(a->point[0], a->point[1], a->point[2],
X &a->center.x, &a->center.y);
X a->direction = compute_direction(a->point[0], a->point[1], a->point[2]);
X }
X
Xscale_ellipse(e, sx, sy, refx, refy)
XF_ellipse *e;
Xfloat sx, sy;
Xint refx, refy;
X{
X e->center.x = round(refx + (e->center.x - refx) * sx);
X e->center.y = round(refy + (e->center.y - refy) * sy);
X e->start.x = round(refx + (e->start.x - refx) * sx);
X e->start.y = round(refy + (e->start.y - refy) * sy);
X e->end.x = round(refx + (e->end.x - refx) * sx);
X e->end.y = round(refy + (e->end.y - refy) * sy);
X e->radiuses.x = round(e->radiuses.x * sx);
X e->radiuses.y = round(e->radiuses.y * sy);
X }
X
Xscale_text(t, sx, sy, refx, refy)
XF_text *t;
Xfloat sx, sy;
Xint refx, refy;
X{
X t->base_x = round(refx + (t->base_x - refx) * sx);
X t->base_y = round(refy + (t->base_y - refy) * sy);
X }
END_OF_scale.c
if test 6178 -ne `wc -c <scale.c`; then
echo shar: \"scale.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f spline.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"spline.c\"
else
echo shar: Extracting \"spline.c\" \(5350 characters\)
sed "s/^X//" >spline.c <<'END_OF_spline.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, 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 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 = NULL;
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 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);
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, 1);
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 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, 1);
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 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 }
END_OF_spline.c
if test 5350 -ne `wc -c <spline.c`; then
echo shar: \"spline.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f text.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"text.c\"
else
echo shar: Extracting \"text.c\" \(5745 characters\)
sed "s/^X//" >text.c <<'END_OF_text.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 * 2nd revision : Feb 1988.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "alloc.h"
X#include "const.h"
X#include "font.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 char *calloc();
Xextern set_popupmenu();
Xextern F_text *text_search();
X
Xextern char_handler();
Xextern int cur_x, cur_y;
Xextern char prefix[], suffix[];
Xextern int leng_prefix, leng_suffix;
Xextern int cur_color;
Xextern int cur_textstyle;
Xextern float cur_angle;
X
Xextern F_compound objects;
X
Xstatic int char_ht, char_wid;
Xstatic int base_x, base_y;
Xstatic PR_SIZE tsize;
Xstatic F_text *cur_text;
X
XF_text *create_text();
Xstatic finish_text_input();
Xstatic finish_n_start();
Xstatic init_text_input();
X
Xstatic
Xfinish_n_start(x, y)
X{
X wrap_up();
X init_text_input(x, y);
X }
X
Xstatic
Xfinish_text_input()
X{
X wrap_up();
X text_drawing_selected();
X }
X
Xstatic
Xwrap_up()
X{
X PR_SIZE size;
X int kbd_received;
X
X reset_action_on();
X kbd_received = terminate_char_handler();
X if ( ! kbd_received) return;
X
X if (cur_text == NULL) { /* a brand new text */
X if (leng_prefix == 0) return;
X pw_text(canvas_pixwin, base_x, base_y, PAINT, canvas_font, prefix);
X cur_text = create_text();
X insert_text(&objects.texts, cur_text);
X }
X else { /* existing text modified */
X strcat(prefix, suffix);
X leng_prefix += leng_suffix;
X if (leng_prefix == 0) {
X delete_text(&objects.texts, cur_text);
X cfree(cur_text->cstring);
X free((char*)cur_text);
X return;
X }
X if (strlen(cur_text->cstring) >= leng_prefix) {
X strcpy(cur_text->cstring, prefix);
X }
X else { /* free old and allocate new */
X cfree(cur_text->cstring);
X cur_text->cstring = calloc((unsigned)(leng_prefix+1), sizeof(char));
X strcpy(cur_text->cstring, prefix);
X }
X size = pf_textwidth(leng_prefix, canvas_font, prefix);
X cur_text->height = size.y;
X cur_text->length = size.x; /* in pixels */
X }
X clean_up();
X set_action_object(F_TEXT, O_TEXT);
X set_latesttext(cur_text);
X set_modifiedflag();
X }
X
Xstatic
Xinit_text_input(x, y)
Xint x, y;
X{
X cur_x = x;
X cur_y = y;
X
X set_action_on();
X canvas_kbd_proc = char_handler;
X canvas_middlebut_proc = finish_text_input;
X canvas_leftbut_proc = finish_n_start;
X canvas_rightbut_proc = null_proc;
X
X if ((cur_text = text_search(cur_x, cur_y)) == NULL) {
X leng_prefix = leng_suffix = 0;
X *suffix = 0;
X prefix[leng_prefix] = '\0';
X base_x = cur_x;
X base_y = cur_y;
X }
X else { /* leng_prefix is # of char in the text before the cursor */
X leng_suffix = strlen(cur_text->cstring);
X leng_prefix = prefix_length(roman_font, cur_text->cstring,
X cur_x - cur_text->base_x);
X leng_suffix -= leng_prefix;
X cpy_n_char(prefix, cur_text->cstring, leng_prefix);
X strcpy(suffix, &cur_text->cstring[leng_prefix]);
X tsize = pf_textwidth(leng_prefix, canvas_font, prefix);
X cur_x = base_x = cur_text->base_x;
X cur_y = base_y = cur_text->base_y;
X cur_x += tsize.x;
X }
X initialize_char_handler(canvas_pixwin, canvas_font,
X finish_text_input, base_x, base_y);
X }
X
Xtext_drawing_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_middlebut_proc = null_proc;
X canvas_leftbut_proc = init_text_input;
X canvas_rightbut_proc = set_popupmenu;
X char_ht = char_height(canvas_font);
X char_wid = char_width(canvas_font);
X set_cursor(&pencil_cursor);
X }
X
XF_text *
Xcreate_text()
X{
X F_text *text;
X PR_SIZE size;
X
X if ((Text_malloc(text)) == NULL) {
X put_msg(Err_mem);
X return(NULL);
X }
X text->cstring = calloc((unsigned)(leng_prefix+1), sizeof(char));
X text->type = T_LEFT_JUSTIFIED;
X text->font = 0;
X text->angle = cur_angle;
X text->style = cur_textstyle;
X text->color = cur_color;
X text->depth = 0;
X text->pen = NULL;
X size = pf_textwidth(leng_prefix, canvas_font, prefix);
X text->size = size.y;
X text->length = size.x; /* in pixels */
X text->height = size.y; /* in pixels */
X text->base_x = base_x;
X text->base_y = base_y;
X strcpy(text->cstring, prefix);
X text->next = NULL;
X return(text);
X }
X
Xcpy_n_char(dst, src, n)
Xchar *dst, *src;
Xint n;
X{
X /* src must be longer than n chars */
X
X while (n--) *dst++ = *src++;
X *dst = '\0';
X }
X
Xint
Xprefix_length(font, string, where_p)
XPIX_FONT font;
Xchar *string;
Xint where_p;
X{
X /* c stands for character unit and p for pixel unit */
X int l, len_c, len_p;
X int char_wid, where_c;
X PR_SIZE size;
X
X if (font == NULL) font = roman_font;
X len_c = strlen(string);
X size = pf_textwidth(len_c, font, string);
X len_p = size.x;
X if (where_p >= len_p) return(len_c); /* entire string is the preffix */
X
X char_wid = char_width(font);
X where_c = where_p / char_wid; /* estimated char position */
X size = pf_textwidth(where_c, font, string);
X l = size.x; /* actual lenght (pixels) of string of where_c chars */
X if (l < where_p) {
X do { /* add the width of next char to l */
X l += (char_wid = char_advance(font,string[where_c++]));
X } while (l < where_p);
X if (l-(char_wid>>1) >= where_p) where_c--;
X }
X else if (l > where_p) {
X do { /* subtract the width of last char from l */
X l -= (char_wid = char_advance(font,string[--where_c]));
X } while (l > where_p);
X if (l+(char_wid>>1) >= where_p) where_c++;
X }
X return(where_c);
X }
X
Xdraw_text(text, op)
XF_text *text;
Xint op;
X{
X pw_text(canvas_pixwin, text->base_x, text->base_y,
X op, canvas_font, text->cstring);
X }
END_OF_text.c
if test 5745 -ne `wc -c <text.c`; then
echo shar: \"text.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f util.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"util.c\"
else
echo shar: Extracting \"util.c\" \(5064 characters\)
sed "s/^X//" >util.c <<'END_OF_util.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
X/*********** The following extern vars for undo purpose **************/
X
X
Xextern int pointmarker_shown;
X
Xstatic u_int marker_pattern[3] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
Xmpr_static(pmarker, 5, 5, 1, marker_pattern);
X
Xtail(ob, tails)
XF_compound *ob, *tails;
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 if (NULL != (a = ob->arcs)) for (; a->next != NULL; a = a->next);
X if (NULL != (c = ob->compounds)) for (; c->next != NULL; c = c->next);
X if (NULL != (e = ob->ellipses)) for (; e->next != NULL; e = e->next);
X if (NULL != (l = ob->lines)) for (; l->next != NULL; l = l->next);
X if (NULL != (s = ob->splines)) for (; s->next != NULL; s = s->next);
X if (NULL != (t = ob->texts)) for (; t->next != NULL; t = t->next);
X
X tails->arcs = a;
X tails->compounds = c;
X tails->ellipses = e;
X tails->lines = l;
X tails->splines = s;
X tails->texts = t;
X }
X
X/*
XMake pointers in tails point to the last element of each list of l1
Xand Append the lists in l2 after those in l1.
XThe tails pointers must be defined prior to calling append.
X*/
Xappend_objects(l1, l2, tails)
XF_compound *l1, *l2, *tails;
X{
X if (tails->arcs)
X tails->arcs->next = l2->arcs;
X else
X l1->arcs = l2->arcs;
X if (tails->compounds)
X tails->compounds->next = l2->compounds;
X else
X l1->compounds = l2->compounds;
X if (tails->ellipses)
X tails->ellipses->next = l2->ellipses;
X else
X l1->ellipses = l2->ellipses;
X if (tails->lines)
X tails->lines->next = l2->lines;
X else
X l1->lines = l2->lines;
X if (tails->splines)
X tails->splines->next = l2->splines;
X else
X l1->splines = l2->splines;
X if (tails->texts)
X tails->texts->next = l2->texts;
X else
X l1->texts = l2->texts;
X }
X
X/* Cut is the dual of append. */
X
Xcut_objects(objects, tails)
XF_compound *objects, *tails;
X{
X if (tails->arcs)
X tails->arcs->next = NULL;
X else
X objects->arcs = NULL;
X if (tails->compounds)
X tails->compounds->next = NULL;
X else
X objects->compounds = NULL;
X if (tails->ellipses)
X tails->ellipses->next = NULL;
X else
X objects->ellipses = NULL;
X if (tails->lines)
X tails->lines->next = NULL;
X else
X objects->lines = NULL;
X if (tails->splines)
X tails->splines->next = NULL;
X else
X objects->splines = NULL;
X if (tails->texts)
X tails->texts->next = NULL;
X else
X objects->texts = NULL;
X }
X
Xno_object()
X{
X if (objects.texts != NULL) return(0);
X if (objects.lines != NULL) return(0);
X if (objects.ellipses != NULL) return(0);
X if (objects.splines != NULL) return(0);
X if (objects.arcs != NULL) return(0);
X if (objects.compounds != NULL) return(0);
X return(1);
X }
X
Xshow_pointmarker()
X{
X if (pointmarker_shown) return;
X pointmarker_shown = 1;
X toggle_pointmarker();
X }
X
Xerase_pointmarker()
X{
X if (! pointmarker_shown) return;
X pointmarker_shown = 0;
X toggle_pointmarker();
X }
X
Xtoggle_pointmarker()
X{
X F_ellipse *e;
X F_arc *a;
X F_line *l;
X F_spline *s;
X
X for (e = objects.ellipses; e != NULL; e = e->next) {
X toggle_ellipsepointmarker(e);
X }
X for (a = objects.arcs; a != NULL; a = a->next) {
X toggle_arcpointmarker(a);
X }
X for (l = objects.lines; l != NULL; l = l->next) {
X toggle_linepointmarker(l);
X }
X for (s = objects.splines; s != NULL; s = s->next) {
X toggle_splinepointmarker(s);
X }
X }
X
Xtoggle_ellipsepointmarker(e)
XF_ellipse *e;
X{
X set_marker(canvas_pixwin, e->start.x-2, e->start.y-2, 5, 5, INV_PAINT,
X &pmarker, 0, 0);
X set_marker(canvas_pixwin, e->end.x-2, e->end.y-2, 5, 5, INV_PAINT,
X &pmarker, 0, 0);
X }
X
Xtoggle_arcpointmarker(a)
XF_arc *a;
X{
X set_marker(canvas_pixwin, a->point[0].x-2, a->point[0].y-2, 5, 5,
X INV_PAINT, &pmarker, 0, 0);
X set_marker(canvas_pixwin, a->point[1].x-2, a->point[1].y-2, 5, 5,
X INV_PAINT, &pmarker, 0, 0);
X set_marker(canvas_pixwin, a->point[2].x-2, a->point[2].y-2, 5, 5,
X INV_PAINT, &pmarker, 0, 0);
X }
X
Xtoggle_linepointmarker(l)
XF_line *l;
X{
X F_point *p;
X int fx, fy, x, y;
X
X p = l->points;
X fx = p->x; fy = p->y;
X for (p = p->next; p!= NULL; p = p->next) {
X x = p->x; y = p->y;
X set_marker(canvas_pixwin, x-2, y-2, 5, 5, INV_PAINT, &pmarker, 0, 0);
X }
X if (x != fx || y != fy) {
X set_marker(canvas_pixwin, fx-2, fy-2, 5, 5, INV_PAINT,
X &pmarker, 0, 0);
X }
X }
X
Xtoggle_splinepointmarker(s)
XF_spline *s;
X{
X F_point *p;
X int fx, fy, x, y;
X
X p = s->points;
X fx = p->x; fy = p->y;
X for (p = p->next; p!= NULL; p = p->next) {
X x = p->x; y = p->y;
X set_marker(canvas_pixwin, x-2, y-2, 5, 5, INV_PAINT, &pmarker, 0, 0);
X }
X if (x != fx || y != fy) {
X set_marker(canvas_pixwin, fx-2, fy-2, 5, 5, INV_PAINT,
X &pmarker, 0, 0);
X }
X }
X
Xnum_points(points)
XF_point *points;
X{
X int n;
X F_point *p;
X
X for (p = points, n = 0; p != NULL; p = p->next, n++);
X return(n);
X }
END_OF_util.c
if test 5064 -ne `wc -c <util.c`; then
echo shar: \"util.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 3 \(of 11\).
cp /dev/null ark3isdone
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