v08i020: xfig -- X Drawing Tool, Part11/21

Brian V. Smith envbvs at epb2.lbl.gov
Wed Jul 4 04:01:12 AEST 1990


Submitted-by: envbvs at epb2.lbl.gov (Brian V. Smith)
Posting-number: Volume 8, Issue 20
Archive-name: xfig2.8/part11

#! /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 11 (of 21)."
# Contents:  Makefile line.c rotate.c xtra.c
# Wrapped by envbvs at epb2.lbl.gov on Thu Jun 28 08:52:28 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(11769 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
X#
X# The cpp used on this machine replaces all newlines and multiple tabs and
X# spaces in a macro expansion with a single space.  Imake tries to compensate
X# for this, but is not always successful.
X#
X
X###########################################################################
X# Makefile generated from "Imake.tmpl" and <Imakefile>
X# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
X#
X# Platform-specific parameters may be set in the appropriate .cf
X# configuration files.  Site-wide parameters may be set in the file
X# site.def.  Full rebuilds are recommended if any parameters are changed.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit sun.cf to change
X
X# platform:  $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
X# operating system:  SunOS 4.0.3
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site:  $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
X
X            SHELL = /bin/sh
X
X              TOP = .
X      CURRENT_DIR = .
X
X               AR = ar cq
X  BOOTSTRAPCFLAGS =
X               CC = cc
X
X         COMPRESS = compress
X              CPP = /lib/cpp $(STD_CPP_DEFINES)
X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
X          INSTALL = install
X               LD = ld
X             LINT = lint
X      LINTLIBFLAG = -C
X         LINTOPTS = -axz
X               LN = ln -s
X             MAKE = make
X               MV = mv
X               CP = cp
X           RANLIB = ranlib
X  RANLIBINSTFLAGS =
X               RM = rm -f
X     STD_INCLUDES =
X  STD_CPP_DEFINES =
X      STD_DEFINES =
X EXTRA_LOAD_FLAGS =
X  EXTRA_LIBRARIES =
X             TAGS = ctags
X
X    SHAREDCODEDEF = -DSHAREDCODE
X         SHLIBDEF = -DSUNSHLIB
X
X    PROTO_DEFINES =
X
X     INSTPGMFLAGS =
X
X     INSTBINFLAGS = -m 0755
X     INSTUIDFLAGS = -m 4755
X     INSTLIBFLAGS = -m 0664
X     INSTINCFLAGS = -m 0444
X     INSTMANFLAGS = -m 0444
X     INSTDATFLAGS = -m 0444
X    INSTKMEMFLAGS = -m 4755
X
X          DESTDIR =
X
X     TOP_INCLUDES = -I$(INCROOT)
X
X      CDEBUGFLAGS = -O
X        CCOPTIONS =
X      COMPATFLAGS = -DXAW_BC
X
X      ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
X   LDCOMBINEFLAGS = -X -r
X
X        MACROFILE = sun.cf
X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
X
X    IMAKE_DEFINES =
X
X         IRULESRC = $(CONFIGDIR)
X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
X
X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
X			$(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
X			$(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
X
X###########################################################################
X# X Window System Build Parameters
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X###########################################################################
X# X Window System make variables; this need to be coordinated with rules
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X          PATHSEP = /
X        USRLIBDIR = /usr/local/lib
X           BINDIR = $(DESTDIR)/usr/bin/X11
X          INCROOT = $(DESTDIR)/usr/include
X     BUILDINCROOT = $(TOP)
X      BUILDINCDIR = $(BUILDINCROOT)/X11
X      BUILDINCTOP = ..
X           INCDIR = $(INCROOT)/X11
X           ADMDIR = $(DESTDIR)/usr/adm
X           LIBDIR = $(USRLIBDIR)/X11
X        CONFIGDIR = $(LIBDIR)/config
X       LINTLIBDIR = $(USRLIBDIR)/lint
X
X          FONTDIR = $(LIBDIR)/fonts
X         XINITDIR = $(LIBDIR)/xinit
X           XDMDIR = $(LIBDIR)/xdm
X           AWMDIR = $(LIBDIR)/awm
X           TWMDIR = $(LIBDIR)/twm
X           GWMDIR = $(LIBDIR)/gwm
X          MANPATH = $(DESTDIR)/usr/man
X    MANSOURCEPATH = $(MANPATH)/man
X           MANDIR = $(MANSOURCEPATH)l
X        LIBMANDIR = $(MANSOURCEPATH)3
X      XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X        SOXLIBREV = 4.2
X          SOXTREV = 4.0
X         SOXAWREV = 4.0
X        SOOLDXREV = 4.0
X         SOXMUREV = 4.0
X        SOXEXTREV = 4.0
X
X       FONTCFLAGS = -t
X
X     INSTAPPFLAGS = $(INSTDATFLAGS)
X
X            IMAKE = imake
X           DEPEND = makedepend
X              RGB = rgb
X            FONTC = bdftosnf
X        MKFONTDIR = mkfontdir
X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
X
X        CONFIGSRC = $(TOP)/config
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        SCRIPTSRC = $(UTILSRC)/scripts
X       EXAMPLESRC = $(TOP)/examples
X       CONTRIBSRC = $(TOP)/../contrib
X           DOCSRC = $(TOP)/doc
X           RGBSRC = $(TOP)/rgb
X        DEPENDSRC = $(UTILSRC)/makedepend
X         IMAKESRC = $(CONFIGSRC)
X         XAUTHSRC = $(LIBSRC)/Xau
X          XLIBSRC = $(LIBSRC)/X
X           XMUSRC = $(LIBSRC)/Xmu
X       TOOLKITSRC = $(LIBSRC)/Xt
X       AWIDGETSRC = $(LIBSRC)/Xaw
X       OLDXLIBSRC = $(LIBSRC)/oldX
X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
X     MKFONTDIRSRC = $(FONTSRC)/mkfontdir
X     EXTENSIONSRC = $(TOP)/extensions
X
X  DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
X     EXTENSIONLIB =  -lXext
X
X          DEPXLIB = $(DEPEXTENSIONLIB)
X             XLIB = $(EXTENSIONLIB) -lX11
X
X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
X         XAUTHLIB =  -lXau
X
X        DEPXMULIB =
X           XMULIB = -lXmu
X
X       DEPOLDXLIB =
X          OLDXLIB = -loldX
X
X      DEPXTOOLLIB =
X         XTOOLLIB = -lXt
X
X        DEPXAWLIB =
X           XAWLIB = -lXaw
X
X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
X         LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
X          LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
X        LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
X          LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
X
X        XWLIBSRC = $(CONTRIBSRC)/toolkits/Xw
X        DEPXWLIB = $(USRLIBDIR)/libXw.a
X        XWLIB =  -lXw
X
X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
X
X         DEPLIBS1 = $(DEPLIBS)
X         DEPLIBS2 = $(DEPLIBS)
X         DEPLIBS3 = $(DEPLIBS)
X
X###########################################################################
X# Imake rules for building libraries, programs, scripts, and data files
X# rules:  $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
XSYS_LIBRARIES= 		-lm
XDEPLIBS = 		$(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
XLOCAL_LIBRARIES = 	$(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
XFONTFILE = 		troff_ft_codes
XFONTLIBDIR = 		/usr/lib/X11/troff
XDEFINES = 		-DFONTFILE=\"$(FONTFILE)\"\
X			-DFONTLIBDIR=\"$(FONTLIBDIR)\"
X
XXFIGSRC =	addpt.c arc.c arcbox.c arrow.c autoarrow.c bitmap.c\
X		blink.c bound.c box.c break.c canvas.c change.c\
X		color.c char.c copy.c\
X		cursor.c curve.c deletept.c dir.c drag.c draw.c\
X		ellipse.c file.c flip.c font.c free.c geom.c\
X		global.c glue.c graphics.c grid.c intspline.c\
X		latex_line.c line.c list.c main.c move.c movept.c\
X		msgsw.c panel.c popup.c print.c printfonts.c psbits.c\
X		psfonts.c puterr.c read.c read1_3.c redisplay.c\
X		remove.c rotate.c ruler.c save.c scale.c search.c\
X		spline.c text.c trans.c turn.c undo.c util.c xtra.c
X
XXFIGOBJ =	addpt.o arc.o arcbox.o arrow.o autoarrow.o bitmap.o\
X		blink.o bound.o box.o break.o canvas.o change.o\
X		color.o char.o copy.o\
X		cursor.o curve.o deletept.o dir.o drag.o draw.o\
X		ellipse.o file.o flip.o font.o free.o geom.o global.o\
X		glue.o graphics.o grid.o intspline.o latex_line.o\
X		line.o list.o main.o move.o movept.o msgsw.o panel.o\
X		popup.o print.o printfonts.o psbits.o psfonts.o\
X		puterr.o read.o read1_3.o redisplay.o remove.o\
X		rotate.o ruler.o 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 troff_fonts.c psfonts.c
XF2POBJ =        arrow.o f2p.o free.o read.o read1_3.o troff_fonts.o psfonts.o
X
XF2PSSRC =       arrow.c bound.c f2ps.c free.c read.c read1_3.c psfonts.c
XF2PSOBJ =       arrow.o bound.o f2ps.o free.o read.o read1_3.o psfonts.o
X
XSRCS1 = $(XFIGSRC)
XOBJS1 = $(XFIGOBJ)
XSRCS2 = $(F2PSRC)
XOBJS2 = $(F2POBJ)
XSRCS3 = $(F2PSSRC)
XOBJS3 = $(F2PSOBJ)
X
XPROGRAMS = xfig f2p f2ps
X
X OBJS = $(OBJS1) $(OBJS2) $(OBJS3)
X SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
X
Xall:: $(PROGRAMS)
X
Xxfig: $(OBJS1) $(DEPLIBS1)
X	$(RM) $@
X	$(CC) -o $@ $(LDOPTIONS) $(OBJS1) $(LOCAL_LIBRARIES) $(LDLIBS)  $(EXTRA_LOAD_FLAGS)
X
Xinstall:: xfig
X	$(INSTALL) -c $(INSTPGMFLAGS)   xfig $(BINDIR)
X
Xinstall.man:: xfig.man
X	$(INSTALL) -c $(INSTMANFLAGS) xfig.man $(MANDIR)/xfig.l
X
Xsaber_xfig:
X	#load $(ALLDEFINES) $(SRCS1) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xosaber_xfig:
X	#load $(ALLDEFINES) $(OBJS1) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xdepend::
X	$(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
X
Xlint:
X	$(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
Xlint1:
X	$(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
X
Xclean::
X	$(RM) $(PROGRAMS)
X
Xf2p: $(OBJS2) $(DEPLIBS2)
X	$(RM) $@
X	$(CC) -o $@ $(LDOPTIONS) $(OBJS2)  $(LDLIBS)  $(EXTRA_LOAD_FLAGS)
X
Xsaber_f2p:
X	#load $(ALLDEFINES) $(SRCS2)  $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xosaber_f2p:
X	#load $(ALLDEFINES) $(OBJS2)  $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xinstall:: f2p
X	$(INSTALL) -c $(INSTPGMFLAGS)   f2p $(BINDIR)
X
Xinstall.man:: f2p.man
X	$(INSTALL) -c $(INSTMANFLAGS) f2p.man $(MANDIR)/f2p.l
X
Xf2ps: $(OBJS3) $(DEPLIBS3)
X	$(RM) $@
X	$(CC) -o $@ $(LDOPTIONS) $(OBJS3)  $(LDLIBS)  $(EXTRA_LOAD_FLAGS)
X
Xsaber_f2ps:
X	#load $(ALLDEFINES) $(SRCS3)  $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xosaber_f2ps:
X	#load $(ALLDEFINES) $(OBJS3)  $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X
Xinstall:: f2ps
X	$(INSTALL) -c $(INSTPGMFLAGS)   f2ps $(BINDIR)
X
Xinstall.man:: f2ps.man
X	$(INSTALL) -c $(INSTMANFLAGS) f2ps.man $(MANDIR)/f2ps.l
X
Xinstall:: $(DESTDIR)$(FONTLIBDIR)
X
X$(DESTDIR)$(FONTLIBDIR):
X	mkdir $(DESTDIR)$(FONTLIBDIR)
X
Xinstall:: troff_ft_codes
X	$(INSTALL) -c $(INSTDATFLAGS) troff_ft_codes $(DESTDIR)$(FONTLIBDIR)/$(FONTFILE)
X
X###########################################################################
X# common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X	$(RM_CMD) \#*
X
XMakefile::
X	- at if [ -f Makefile ]; then \
X	echo "	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
X
Xtags::
X	$(TAGS) -w *.[ch]
X	$(TAGS) -xw *.[ch] > TAGS
X
Xsaber:
X	#load $(ALLDEFINES) $(SRCS)
X
Xosaber:
X	#load $(ALLDEFINES) $(OBJS)
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X	@echo "install in $(CURRENT_DIR) done"
X
Xinstall.man::
X	@echo "install.man in $(CURRENT_DIR) done"
X
XMakefiles::
X
Xincludes::
X
X###########################################################################
X# dependencies generated by makedepend
X
END_OF_FILE
if test 11769 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'line.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'line.c'\"
else
echo shar: Extracting \"'line.c'\" \(12215 characters\)
sed "s/^X//" >'line.c' <<'END_OF_FILE'
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
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		fix_x, fix_y, cur_x, cur_y;
Xextern int		fill_mode,cur_areafill;
X
Xextern int		cur_command;
Xextern int		manhattan_mode, mountain_mode;
Xextern int		latexline_mode, latexarrow_mode;
Xextern int		magnet_mode, latexarrow_mode;
Xextern int		autoforwardarrow_mode, autobackwardarrow_mode;
Xextern int		line_style, line_thickness;
Xextern float		cur_styleval;
Xextern int		cur_color;
Xextern F_compound	objects;
Xextern int		num_point;
Xextern int		latex_endpoint();
X
Xextern F_point		*first_point, *cur_point; 
X
X/*************************** locally global variables *********************/
X
Xstatic int		firstx, firsty;
Xextern int		init_line_drawing();
X
Xextern int		create_lineobject();
Xextern int		create_latexobject();
Xextern int		determine_angle();
Xextern int		freehand_elasticline();
Xextern int		latex_elasticline();
Xextern int		angle0_elasticline(), angle90_elasticline(); 
Xextern int		angle45_elasticline(), angle135_elasticline(); 
Xextern int		get_direction(), get_intermediatepoint();
Xextern int		get_latexpoint();
X
X/**********************  polyline and polygon section  **********************/
X
Xline_drawing_selected()
X{
X	canvas_kbd_proc = null_proc;
X	canvas_locmove_proc = null_proc;
X	canvas_leftbut_proc = init_line_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_line_drawing(x, y)
Xint	x, y;
X{
X	first_point = Point_malloc(cur_point);
X	if (cur_point == NULL) {
X	    blink_msg();
X	    put_msg(Err_mem);
X	    return;
X	    }
X	canvas_rightbut_proc = null_proc;
X	set_action_on();
X	cur_point->x = firstx = fix_x = cur_x = x;
X	cur_point->y = firsty = fix_y = cur_y = y;
X	cur_point->next = NULL;
X	num_point = 1;
X	if (latexline_mode || latexarrow_mode) {
X	    canvas_locmove_proc = latex_elasticline;
X	    canvas_leftbut_proc = get_latexpoint;
X	    canvas_middlebut_proc = create_latexobject;
X	    }
X	else if (manhattan_mode || mountain_mode) {
X	    canvas_locmove_proc = determine_angle;
X	    canvas_leftbut_proc = get_direction;
X	    canvas_middlebut_proc = create_lineobject;
X	    }
X	else {
X	    canvas_locmove_proc = freehand_elasticline;
X	    canvas_leftbut_proc = get_intermediatepoint;
X	    canvas_middlebut_proc = create_lineobject;
X	    }
X	set_temp_cursor(&null_cursor);
X	cur_cursor = &null_cursor;
X	draw_elasticline();
X	}
X
Xdraw_elasticline()
X{
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, 
X		INV_PAINT, 1, SOLID_LINE, 0.0);
X	}
X
Xfreehand_elasticline(x, y)
Xint	x, y;
X{
X	draw_elasticline();
X	cur_x = x;  
X	cur_y = y;
X	draw_elasticline();
X	}
X
Xdraw_latexline()
X{
X	int  x, y;
X	CURSOR c;
X
X	latex_endpoint(fix_x, fix_y, cur_x, cur_y, &x, &y, latexarrow_mode, (magnet_mode)? 5: 1);
X	pw_vector(canvas_win, fix_x, fix_y, x, y, INV_PAINT,1,SOLID_LINE, 0.0);
X	c = (x == cur_x  &&  y == cur_y)? &null_cursor: &crosshair_cursor;
X	if (c != cur_cursor) {
X	    set_temp_cursor(c);
X	    cur_cursor = c;
X	    }
X	}
X
Xlatex_elasticline(x, y)
Xint	x, y;
X{
X	draw_latexline();
X	cur_x = x;  
X	cur_y = y;
X	draw_latexline();
X	}
X
Xangle0_elasticline(x, y)
Xint	x, y;
X{
X	if (x == cur_x && y == cur_y) return;
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	cur_x = x;
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	win_setmouseposition(canvas_win, cur_x, cur_y);
X	}
X
Xangle90_elasticline(x, y)
Xint	x, y;
X{
X	if (x == cur_x && y == cur_y) return;
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	cur_y = y;
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	win_setmouseposition(canvas_win, cur_x, cur_y);
X	}
X
Xangle45_elasticline(x, y)
Xint	x, y;
X{
X	if (x == cur_x && y == cur_y) return;
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	if (abs(x - cur_x) < abs(y - cur_y)) {
X	    cur_x += cur_y - y;
X	    cur_y = y;
X	    }
X	else {
X	    cur_y -= x - cur_x;
X	    cur_x = x;
X	    }
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	win_setmouseposition(canvas_win, cur_x, cur_y);
X	}
X
Xangle135_elasticline(x, y)
Xint	x, y;
X{
X	if (x == cur_x && y == cur_y) return;
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	if (abs(x - cur_x) < abs(y - cur_y)) {
X	    cur_x += y - cur_y;
X	    cur_y = y;
X	    }
X	else {
X	    cur_y += x - cur_x;
X	    cur_x = x;
X	    }
X	pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1,SOLID_LINE, 0.0);
X	win_setmouseposition(canvas_win, cur_x, cur_y);
X	}
X
Xget_direction(x, y)
Xint	x, y;
X{
X	(*canvas_locmove_proc) (x, y);
X	canvas_locmove_proc = determine_angle;
X	get_intermediatepoint(cur_x, cur_y);
X	}
X
Xdetermine_angle(x, y)
Xint	x, y;
X{
X	float	angle, dx, dy;
X
X	dx = x - fix_x;  dy = fix_y - y;
X	if (sqrt((double)(dx*dx + dy*dy)) < 7) return;
X	if (dx == 0)
X	    angle = -90;
X	else
X	    angle = 180 * atan((double)(dy / dx)) / 3.1416;
X
X	if (manhattan_mode) {
X	    if (mountain_mode) {
X		if (angle < -67.5) canvas_locmove_proc = angle90_elasticline;
X		else if (angle < -22.5) canvas_locmove_proc = angle135_elasticline;
X		else if (angle <  22.5) canvas_locmove_proc = angle0_elasticline;
X		else if (angle <  67.5) canvas_locmove_proc = angle45_elasticline;
X		else canvas_locmove_proc = angle90_elasticline;
X		}
X	    else {
X		if (angle < -45) canvas_locmove_proc = angle90_elasticline;
X		else if (angle < 45) canvas_locmove_proc = angle0_elasticline;
X		else canvas_locmove_proc = angle90_elasticline;
X		}
X	    }
X	else {
X	    if (angle < 0) canvas_locmove_proc = angle135_elasticline;
X	    else canvas_locmove_proc = angle45_elasticline;
X	    }
X	    
X	(*canvas_locmove_proc)(x, y);
X	}
X
Xget_latexpoint(x, y)
Xint	x, y;
X{
X	draw_latexline();
X	latex_endpoint(fix_x, fix_y, x, y, &cur_x, &cur_y, latexarrow_mode, (magnet_mode)? 5: 1);
X	if (cur_cursor != &null_cursor) {
X	    set_temp_cursor(&null_cursor);
X	    cur_cursor = &null_cursor;
X	    }
X	win_setmouseposition(canvas_win, cur_x, cur_y);
X	get_intermediatepoint(cur_x, cur_y);
X	}
X
Xget_intermediatepoint(x, y)
Xint	x, y;
X{
X	draw_elasticline();	/* erase elastic line */
X	cur_x = x;
X	cur_y = y;
X	draw_elasticline();
X	num_point++;
X	fix_x = x;
X	fix_y = y;
X	draw_elasticline();
X	append_point(fix_x, fix_y, &cur_point);
X	}
X
Xcreate_latexobject(x, y)
Xint	x, y;
X{
X	if (x != fix_x || y != fix_y || num_point == 1) {
X	    draw_latexline();
X	    latex_endpoint(fix_x, fix_y, x, y, &cur_x, &cur_y, latexarrow_mode, (magnet_mode)? 5: 1);
X	    if (cur_cursor != &null_cursor) {
X		set_temp_cursor(&null_cursor);
X		cur_cursor = &null_cursor;
X		}
X	    win_setmouseposition(canvas_win, cur_x, cur_y);
X	    }
X	create_lineobject(cur_x, cur_y);
X	}
X
X/* come here upon pressing middle button (last point of lineobject) */
X
Xcreate_lineobject(x, y)
Xint	x, y;
X{
X	extern F_arrow	*forward_arrow(), *backward_arrow();
X	F_point		*p, *q;
X	F_line		*line;
X	int		dot;
X
X	dot = 0;
X	if (x != fix_x || y != fix_y) {
X	    if( manhattan_mode || mountain_mode )
X		    get_direction(x, y);
X	    else if( latexline_mode || latexarrow_mode )
X		    get_latexpoint(x, y);
X	    else
X		    get_intermediatepoint(x, y);
X	    draw_elasticline();
X	    }
X	else if (num_point == 1) {
X	    dot = 1;
X	    if( manhattan_mode || mountain_mode )
X		    get_direction(x, y);
X	    else if( latexline_mode || latexarrow_mode )
X		    get_latexpoint(x, y);
X	    else
X		    get_intermediatepoint(x, y);
X	    draw_elasticline();
X	    }
X	if (NULL == (Line_malloc(line))) {
X	    put_msg(Err_mem);
X	    line_drawing_selected();
X	    return;
X	    }
X	line->type = T_POLYLINE;
X	line->style = SOLID_LINE;
X	line->thickness = 1;		/* these will be changed to final values */
X	line->style_val = 0;
X	line->color = cur_color;
X	line->depth = 0;
X	line->area_fill = 0;
X	line->pen = 0;
X	line->points = first_point;
X	line->next = NULL;
X	line->for_arrow = NULL;
X	line->back_arrow = NULL;
X	if (cur_command == F_POLYGON) {  /* polygon; close it off with one more point */
X	    if (num_point >= 3) {
X		line->type = T_POLYGON;
X		num_point++;
X		append_point(firstx, firsty, &cur_point);
X		draw_elasticline();
X		fix_x=firstx;
X		fix_y=firsty;
X		draw_elasticline();		/* fix last elastic line */
X		}
X	    }
X	else if (dot) {			/* single point */
X	    pw_vector(canvas_win, fix_x, fix_y, cur_x, cur_y, PAINT, 2, SOLID_LINE, 0.0);
X	    line->style = SOLID_LINE;
X	    }
X	else if (num_point > 1) {		/* polyline; draw any arrows */
X	    if (autoforwardarrow_mode) {
X		line->for_arrow = forward_arrow();
X		for (p = line->points; p != cur_point; q = p, p = p->next);
X		draw_arrow(q->x, q->y, p->x, p->y, line->for_arrow, PAINT);
X		}
X	    if (autobackwardarrow_mode) {
X		line->back_arrow = backward_arrow();
X		p = line->points->next;
X		draw_arrow(p->x, p->y, firstx, firsty, line->back_arrow, PAINT);
X		}
X	    }
X	if (!dot)
X		{
X		line->thickness = 1;
X		line->area_fill = 0;
X		draw_line(line,INV_PAINT);	/* erase temporary outline */
X		line->thickness = line_thickness;
X		line->area_fill = fill_mode? cur_areafill : 0;
X		line->thickness = line_thickness;
X		line->style = line_style;
X		line->style_val = cur_styleval;
X		draw_line(line,PAINT);		/* draw final */
X		}
X	clean_up();
X	set_action_object(F_CREATE, O_POLYLINE);
X	insert_line(&objects.lines, line);
X	set_latestline(line);
X	set_modifiedflag();
X	line_drawing_selected();
X	}
X
Xappend_point(x, y, point)
Xint	x, y;
XF_point	**point;
X{
X	F_point	*p;
X
X	if (NULL == (Point_malloc(p))) {
X	    put_msg(Err_mem);
X	    return;
X	    }
X	p->x = x;
X	p->y = y;
X	p->next = NULL;
X	(*point)->next = p;
X	*point = p;
X	}
X
X
Xfill_object(line, op)
XF_line *line;
Xint op;
X	{
X	int npts,i;
X	struct f_point *pnt;
X	XPoint *points;
X	GC gc;
X
X	if (line->area_fill <= 0 || line->type == T_POLYLINE)
X		return;
X
X	if (op == PAINT)		/* fill */
X		gc = fill_gc[line->area_fill-1];
X	else				/* un-fill */
X		gc = un_fill_gc[line->area_fill-1];
X
X	if (line->type == T_ARC_BOX)
X		{
X		fill_arc_box(line,gc);
X		return;
X		}
X	npts=0;
X	/* count number of points in this object */
X	for (pnt=line->points; pnt != NULL; pnt = pnt->next)
X		npts++;
X	if ((points = (XPoint *) malloc(npts*sizeof(XPoint)))==0)
X		{
X		put_msg(Err_mem);
X		return;
X		}
X	for (pnt=line->points, i=0; i<npts; i++, pnt=pnt->next)
X		{
X		points[i].x = pnt->x;
X		points[i].y = pnt->y;
X		}
X	XFillPolygon(tool_d,canvas_win,gc,points, npts,
X			Complex, CoordModeOrigin);
X	free(points);
X	}
X
Xfill_arc_box(line, gc)
XF_line *line;
XGC gc;
X	{
X	F_point	*point;
X	int	xmin,xmax,ymin,ymax;
X	int	radius,diam;
X
X	point = line->points;
X	radius = line->radius;
X
X	xmin = xmax = point->x;
X	ymin = ymax = point->y;
X	while (point->next)		/* find lower left (upper-left on screen) */
X		{			/* and upper right (lower right on screen) */
X		point = point->next;
X		if (point->x < xmin)
X			xmin = point->x;
X		else if (point->x > xmax)
X			xmax = point->x;
X		if (point->y < ymin)
X			ymin = point->y;
X		else if (point->y > ymax)
X			ymax = point->y;
X		}
X	
X	diam = 2*radius;
X	/* upper left */
X	XFillArc(tool_d, canvas_win, gc, xmin, ymin,
X			diam, diam, 90*64, 90*64);
X	/* lower left */
X	XFillArc(tool_d, canvas_win, gc, xmin, ymax-diam,
X			diam, diam, 180*64, 90*64);
X	/* lower right */
X	XFillArc(tool_d, canvas_win, gc, xmax-diam, ymax-diam,
X			diam, diam, 270*64, 90*64);
X	/* upper right */
X	XFillArc(tool_d, canvas_win, gc, xmax-diam, ymin,
X			diam, diam, 0*64, 90*64);
X	/* fill strip on left side between upper and lower arcs */
X	if (ymax-ymin-diam > 0)
X	    XFillRectangle(tool_d, canvas_win, gc, xmin, ymin+radius,
X			radius, ymax-ymin-diam);
X	/* fill middle section */
X	if (xmax-xmin-diam > 0)
X	    XFillRectangle(tool_d, canvas_win, gc, xmin+radius, ymin,
X			xmax-xmin-diam, ymax-ymin);
X	/* fill strip on right side between upper and lower arcs */
X	if (ymax-ymin-diam > 0)
X	    XFillRectangle(tool_d, canvas_win, gc, xmax-radius, ymin+radius,
X			radius, ymax-ymin-diam);
X	}
END_OF_FILE
if test 12215 -ne `wc -c <'line.c'`; then
    echo shar: \"'line.c'\" unpacked with wrong size!
fi
# end of 'line.c'
fi
if test -f 'rotate.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rotate.c'\"
else
echo shar: Extracting \"'rotate.c'\" \(11098 characters\)
sed "s/^X//" >'rotate.c' <<'END_OF_FILE'
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
Xextern F_line		*line_search(), *copy_line();
Xextern F_ellipse	*ellipse_search(), *copy_ellipse();
Xextern F_ellipse	*ellipse_point_search();
Xextern F_spline		*spline_search(), *copy_spline();
Xextern F_arc		*arc_point_search(), *copy_arc();
Xextern F_compound	*compound_search(), *copy_compound();
X
Xextern F_compound	objects;
X
Xextern int		rotate_angle;
Xextern int		pointmarker_shown;
Xextern int		foreground_color, background_color;
X
Xstatic int		copy;
Xextern int		init_rotate();
Xextern int		init_copynrotate();
X
Xrotate_selected()
X{
X	canvas_kbd_proc = null_proc;
X	canvas_locmove_proc = null_proc;
X	canvas_leftbut_proc = init_copynrotate;
X	canvas_middlebut_proc = init_rotate;
X	canvas_rightbut_proc = set_popupmenu;
X	set_cursor(&pick15_cursor);
X	}
X
Xinit_rotate(x, y)
Xint	x, y;
X{
X	copy = 0;
X	rotate_search(x, y);
X	}
X
Xinit_copynrotate(x, y)
Xint	x, y;
X{
X	copy = 1;
X	rotate_search(x, y);
X	}
X
Xrotate_search(x, y)
Xint	x, y;
X{
X	F_line		*l;
X	F_arc		*a;
X	F_ellipse	*e;
X	F_spline	*s;
X	F_compound	*c;
X	int		px, py;
X
X	if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    init_rotateline(l, px, py);
X	    }
X	else if ((e = ellipse_point_search(x, y, TOLERANCE, &px)) != NULL) {
X	    if (px == 0)
X		init_rotateellipse(e, e->start.x, e->start.y);
X	    else
X		init_rotateellipse(e, e->end.x, e->end.y);
X	    }
X	else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    init_rotateellipse(e, x, y);
X	    }
X	else if ((a = arc_point_search(x, y, TOLERANCE, &px)) != NULL) {
X	    init_rotatearc(a, a->point[px].x, a->point[px].y);
X	    }
X	else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    init_rotatespline(s, px, py);
X	    }
X	else if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X	    init_rotatecompound(c, px, py);
X	    }
X	else {
X	    return;
X	    }
X	set_modifiedflag();
X	}
X
Xinit_rotateline(l, px, py)
XF_line	*l;
Xint	px, py;
X{
X	F_line	*line;
X
X	win_setmouseposition(canvas_win, px, py);
X	if (pointmarker_shown) toggle_linepointmarker(l);
X	if (copy) {
X	    line = copy_line(l);
X	    rotate_line(line, px, py, rotate_angle);
X	    insert_line(&objects.lines, line);
X	    clean_up();
X	    set_action_object(F_CREATE, O_POLYLINE);
X	    draw_line(line, PAINT);
X	    }
X	else {
X	    draw_line(l, ERASE);
X	    rotate_line(l, px, py, rotate_angle);
X	    clean_up();
X	    set_action_object(F_ROTATE, O_POLYLINE);
X	    set_lastangle(rotate_angle);
X	    set_lastposition(px, py);
X	    draw_line(l, PAINT);
X	    line = l;
X	    }
X	if (pointmarker_shown) {
X	    if (copy) toggle_linepointmarker(line);
X	    toggle_linepointmarker(l);
X	    }
X	set_latestline(line);
X	}
X
Xinit_rotateellipse(e, px, py)
XF_ellipse	*e;
Xint		px, py;
X{
X	F_ellipse	*ellipse;
X
X	win_setmouseposition(canvas_win, px, py);
X	if (pointmarker_shown) toggle_ellipsepointmarker(e);
X	if (copy) {
X	    ellipse = copy_ellipse(e);
X	    rotate_ellipse(ellipse, px, py, rotate_angle);
X	    insert_ellipse(&objects.ellipses, ellipse);
X	    clean_up();
X	    set_action_object(F_CREATE, O_ELLIPSE);
X	    draw_ellipse(ellipse, PAINT);
X	    }
X	else {
X	    draw_ellipse(e, background_color);
X	    rotate_ellipse(e, px, py, rotate_angle);
X	    clean_up();
X	    set_action_object(F_ROTATE, O_ELLIPSE);
X	    set_lastangle(rotate_angle);
X	    set_lastposition(px, py);
X	    draw_ellipse(e, foreground_color);
X	    ellipse = e;
X	    }
X	if (pointmarker_shown) {
X	    if (copy) toggle_ellipsepointmarker(ellipse);
X	    toggle_ellipsepointmarker(e);
X	    }
X	set_latestellipse(ellipse);
X	}
X
Xinit_rotatearc(a, px, py)
XF_arc	*a;
Xint	px, py;
X{
X	F_arc	*arc;
X
X	win_setmouseposition(canvas_win, px, py);
X	if (pointmarker_shown) toggle_arcpointmarker(a);
X	if (copy) {
X	    arc = copy_arc(a);
X	    rotate_arc(arc, px, py, rotate_angle);
X	    insert_arc(&objects.arcs, arc);
X	    clean_up();
X	    set_action_object(F_CREATE, O_ARC);
X	    draw_arc(arc, foreground_color);
X	    }
X	else {
X	    draw_arc(a, background_color);
X	    rotate_arc(a, px, py, rotate_angle);
X	    clean_up();
X	    set_action_object(F_ROTATE, O_ARC);
X	    set_lastangle(rotate_angle);
X	    set_lastposition(px, py);
X	    draw_arc(a, foreground_color);
X	    arc = a;
X	    }
X	if (pointmarker_shown) {
X	    if (copy) toggle_arcpointmarker(arc);
X	    toggle_arcpointmarker(a);
X	    }
X	set_latestarc(arc);
X	}
X
Xinit_rotatespline(s, px, py)
XF_spline	*s;
Xint		px, py;
X{
X	F_spline	*spline;
X
X	win_setmouseposition(canvas_win, px, py);
X	if (pointmarker_shown) toggle_splinepointmarker(s);
X	if (copy) {
X	    spline = copy_spline(s);
X	    rotate_spline(spline, px, py, rotate_angle);
X	    insert_spline(&objects.splines, spline);
X	    clean_up();
X	    set_action_object(F_CREATE, O_SPLINE);
X	    draw_spline(spline, PAINT);
X	    }
X	else {
X	    draw_spline(s, ERASE);
X	    rotate_spline(s, px, py, rotate_angle);
X	    clean_up();
X	    set_action_object(F_ROTATE, O_SPLINE);
X	    set_lastangle(rotate_angle);
X	    set_lastposition(px, py);
X	    draw_spline(s, PAINT);
X	    spline = s;
X	    }
X	if (pointmarker_shown) {
X	    if (copy) toggle_splinepointmarker(spline);
X	    toggle_splinepointmarker(s);
X	    }
X	set_latestspline(spline);
X	}
X
Xinit_rotatecompound(c, px, py)
XF_compound	*c;
Xint		px, py;
X{
X	F_compound	*compound;
X
X	win_setmouseposition(canvas_win, px, py);
X	set_temp_cursor(&wait_cursor);
X	if (copy) {
X	    compound = copy_compound(c);
X	    rotate_compound(compound, px, py, rotate_angle);
X	    insert_compound(&objects.compounds, compound);
X	    clean_up();
X	    set_action_object(F_CREATE, O_COMPOUND);
X	    draw_compound(compound);
X	    draw_compoundbox(compound, INV_PAINT);
X	    }
X	else {
X	    draw_compoundbox(c, INV_PAINT);
X	    erase_compound(c);
X	    rotate_compound(c, px, py, rotate_angle);
X	    clean_up();
X	    set_action_object(F_ROTATE, O_COMPOUND);
X	    set_lastangle(rotate_angle);
X	    set_lastposition(px, py);
X	    draw_compound(c);
X	    draw_compoundbox(c, INV_PAINT);
X	    compound = c;
X	    }
X	set_latestcompound(compound);
X	set_temp_cursor(cur_cursor);
X	}
X
Xrotate_line(l, x, y, rotate_angle)
XF_line	*l;
Xint	x, y, rotate_angle;
X{
X	F_point	*p;
X	int	dx;
X
X	switch(rotate_angle) {
X	    case 270 :
X		for (p = l->points; p != NULL; p = p->next) {
X		    dx = p->x - x;
X		    p->x = x + (y - p->y);
X		    p->y = y + dx;
X		    }
X		break;
X	    case 90 :
X		for (p = l->points; p != NULL; p = p->next) {
X		    dx = p->x - x;
X		    p->x = x - (y - p->y);
X		    p->y = y - dx;
X		    }
X		break;
X	    }
X	}
X
Xrotate_spline(s, x, y, rotate_angle)
XF_spline	*s;
Xint		x, y, rotate_angle;
X{
X	F_point		*p;
X	F_control	*cp;
X	int		dx;
X
X	switch(rotate_angle) {
X	    case 270 :
X		for (p = s->points; p != NULL; p = p->next) {
X		    dx = p->x - x;
X		    p->x = x + (y - p->y);
X		    p->y = y + dx;
X		    }
X		for (cp = s->controls; cp != NULL; cp = cp->next) {
X		    dx = cp->lx - x;
X		    cp->lx = x + (y - cp->ly);
X		    cp->ly = y + dx;
X		    dx = cp->rx - x;
X		    cp->rx = x + (y - cp->ry);
X		    cp->ry = y + dx;
X		    }
X		break;
X	    case 90 :
X		for (p = s->points; p != NULL; p = p->next) {
X		    dx = p->x - x;
X		    p->x = x - (y - p->y);
X		    p->y = y - dx;
X		    }
X		for (cp = s->controls; cp != NULL; cp = cp->next) {
X		    dx = cp->lx - x;
X		    cp->lx = x - (y - cp->ly);
X		    cp->ly = y - dx;
X		    dx = cp->rx - x;
X		    cp->rx = x - (y - cp->ry);
X		    cp->ry = y - dx;
X		    }
X		break;
X	    }
X	}
X
Xrotate_text(t, x, y, rotate_angle)
XF_text	*t;
Xint	x, y, rotate_angle;
X{
X	int	dx;
X
X	switch(rotate_angle) {
X	    case 270 :
X		dx = t->base_x - x;
X		t->base_x = x - (t->base_y - y);
X		t->base_y = y + dx;
X		break;
X	    case 90 :	
X		dx = t->base_x - x;
X		t->base_x = x + (t->base_y - y);
X		t->base_y = y - dx;
X		break;
X	    }
X	}
X
Xrotate_ellipse(e, x, y, rotate_angle)
XF_ellipse	*e;
Xint		x, y, rotate_angle;
X{
X	int	dx;
X
X	switch(rotate_angle) {
X	    case 270 :
X		dx = e->center.x - x;
X		e->center.x = x - (e->center.y - y);
X		e->center.y = y + dx;
X		dx = e->radiuses.x;
X		e->radiuses.x = e->radiuses.y;
X		e->radiuses.y = dx;
X		dx = e->start.x - x;
X		e->start.x = x - (e->start.y - y);
X		e->start.y = y + dx;
X		dx = e->end.x - x;
X		e->end.x = x - (e->end.y - y);
X		e->end.y = y + dx;
X		break;
X	    case 90 :	
X		dx = e->center.x - x;
X		e->center.x = x + (e->center.y - y);
X		e->center.y = y - dx;
X		dx = e->radiuses.x;
X		e->radiuses.x = e->radiuses.y;
X		e->radiuses.y = dx;
X		dx = e->start.x - x;
X		e->start.x = x + (e->start.y - y);
X		e->start.y = y - dx;
X		dx = e->end.x - x;
X		e->end.x = x + (e->end.y - y);
X		e->end.y = y - dx;
X		break;
X	    }
X	}
X
Xrotate_arc(a, x, y, rotate_angle)
XF_arc	*a;
Xint	x, y, rotate_angle;
X{
X	int	dx;
X
X	switch(rotate_angle) {
X	    case 270 :
X		dx = a->center.x - x;
X		a->center.x = x - (a->center.y - y);
X		a->center.y = y + dx;
X		dx = a->point[0].x - x;
X		a->point[0].x = x - (a->point[0].y - y);
X		a->point[0].y = y + dx;
X		dx = a->point[1].x - x;
X		a->point[1].x = x - (a->point[1].y - y);
X		a->point[1].y = y + dx;
X		dx = a->point[2].x - x;
X		a->point[2].x = x - (a->point[2].y - y);
X		a->point[2].y = y + dx;
X		break;
X	    case 90 :	
X		dx = a->center.x - x;
X		a->center.x = x + (a->center.y - y);
X		a->center.y = y - dx;
X		dx = a->point[0].x - x;
X		a->point[0].x = x + (a->point[0].y - y);
X		a->point[0].y = y - dx;
X		dx = a->point[1].x - x;
X		a->point[1].x = x + (a->point[1].y - y);
X		a->point[1].y = y - dx;
X		dx = a->point[2].x - x;
X		a->point[2].x = x + (a->point[2].y - y);
X		a->point[2].y = y - dx;
X		break;
X	    }
X	}
X
X#define			min(a, b)	(((a) < (b)) ? (a) : (b))
X#define			max(a, b)	(((a) > (b)) ? (a) : (b))
X
Xrotate_compound(c, x, y, rotate_angle)
XF_compound	*c;
Xint		x, y, rotate_angle;
X{
X	F_line		*l;
X	F_arc		*a;
X	F_ellipse	*e;
X	F_spline	*s;
X	F_text		*t;
X	F_compound	*c1;
X	int		x1, y1, x2, y2;
X
X	switch(rotate_angle) {
X	    case 270 :
X		x1 = x - (c->nwcorner.y - y);
X		y1 = y + (c->nwcorner.x - x);
X		x2 = x - (c->secorner.y - y);
X		y2 = y + (c->secorner.x - x);
X		break;
X	    case 90 :	
X		x1 = x + (c->nwcorner.y - y);
X		y1 = y - (c->nwcorner.x - x);
X		x2 = x + (c->secorner.y - y);
X		y2 = y - (c->secorner.x - x);
X		break;
X	    }
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	for (l = c->lines; l != NULL; l = l->next)
X	    rotate_line(l, x, y, rotate_angle);
X	for (a = c->arcs; a != NULL; a = a->next)
X	    rotate_arc(a, x, y, rotate_angle);
X	for (e = c->ellipses; e != NULL; e = e->next)
X	    rotate_ellipse(e, x, y, rotate_angle);
X	for (s = c->splines; s != NULL; s = s->next)
X	    rotate_spline(s, x, y, rotate_angle);
X	for (t = c->texts; t != NULL; t = t->next)
X	    rotate_text(t, x, y, rotate_angle);
X	for (c1 = c->compounds; c1 != NULL; c1 = c1->next)
X	    rotate_compound(c1, x, y, rotate_angle);
X	}
END_OF_FILE
if test 11098 -ne `wc -c <'rotate.c'`; then
    echo shar: \"'rotate.c'\" unpacked with wrong size!
fi
# end of 'rotate.c'
fi
if test -f 'xtra.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xtra.c'\"
else
echo shar: Extracting \"'xtra.c'\" \(11232 characters\)
sed "s/^X//" >'xtra.c' <<'END_OF_FILE'
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#include "object.h"
X
Xextern int		gc_thickness[0x10], gc_line_style[0x10];
X
Xextern PIX_FONT		lookfont();
X
X/* print "string" in window "w" using font number "font" and size "size" */
X
Xpw_text(w, x, y, op, font, size, string)
XWindow w;
Xint x, y, op, font, size;
Xchar *string;
X	{
X	if (gc_font[op] != font || gc_fontsize[op] != size)
X		{
X		canvas_font = lookfont(font,size);
X		XSetFont(tool_d, gccache[op], canvas_font->fid);
X		gc_font[op] = font;
X		gc_fontsize[op] = size;
X		}
X	XDrawString(tool_d, w, gccache[op], x, y, string, strlen(string));
X	}
X
Xpr_size 
Xpf_textwidth(font, size, n, s)
Xint font,size,n;
Xchar *s;
X	{
X	int		dummy;
X	XCharStruct	ch;
X	pr_size		ret;
X
X	canvas_font = lookfont(font,size);	/* make sure it is the right font */
X	XTextExtents(canvas_font, s, n, &dummy, &dummy, &dummy, &ch);
X	ret.x = ch.width;
X	ret.y = ch.ascent + ch.descent;
X	return (ret);
X	}
X
XGC
Xmakegc(op, fg, bg)
Xint	op;
XPixel	fg;
XPixel	bg;
X{
X	register GC	ngc;
X	XGCValues	gcv;
X	unsigned long	gcmask;
X
X	gcv.font = roman_font->fid;
X	gcv.join_style = JoinMiter;
X	gcmask = GCJoinStyle|GCFunction|GCForeground|GCBackground|GCFont;
X	switch (op) {
X	    case PAINT:
X		gcv.foreground = fg;
X		gcv.background = bg;
X		gcv.function = GXcopy;
X		break;
X	    case ERASE:
X		gcv.foreground = bg;
X		gcv.background = bg;
X		gcv.function = GXcopy;
X		break;
X	    case INV_PAINT:
X		gcv.foreground = fg ^ bg;
X		gcv.background = bg;
X		gcv.function = GXxor;
X		break;
X	    case MERGE:
X		gcv.foreground = fg;
X		gcv.background = bg;
X		gcv.function = GXor;
X		break;
X	}
X	
X	ngc = XCreateGC(tool_d, XtWindow(canvas_sw), gcmask, &gcv);
X	XCopyGC(tool_d, gc, ~(gcmask), ngc);	/* add main gc's values to the new one */
X	return (ngc);
X}
X
Xstatic GC	msg_gccache[0x10];
X
Xinit_gc()
X{
X	Pixel	bg, fg;
X	Arg	tmp_arg[2];
X	
X	gccache[PAINT] = makegc(PAINT, x_fg_color.pixel, x_bg_color.pixel);
X	gccache[ERASE] = makegc(ERASE, x_fg_color.pixel, x_bg_color.pixel);
X	gccache[INV_PAINT] = makegc(INV_PAINT, x_fg_color.pixel,
X				    x_bg_color.pixel);
X	gccache[MERGE] = makegc(MERGE, x_fg_color.pixel, x_bg_color.pixel);
X
X	/* Need to get the values so we can make GC's which XOR correctly */
X	XtSetArg(tmp_arg[0], XtNforeground, &fg);
X	XtSetArg(tmp_arg[1], XtNbackground, &bg);
X	XtGetValues(msg_sw, tmp_arg, 2);
X
X	msg_gccache[PAINT] = makegc(PAINT, fg, bg);
X	msg_gccache[ERASE] = makegc(ERASE, fg, bg);
X	
X	XtSetArg(tmp_arg[0], XtNforeground, &fg);
X	XtSetArg(tmp_arg[1], XtNbackground, &bg);
X	XtGetValues(topruler_sw, tmp_arg, 2);
X
X	topgc = makegc(INV_PAINT, fg, bg);
X	
X	XtSetArg(tmp_arg[0], XtNforeground, &fg);
X	XtSetArg(tmp_arg[1], XtNbackground, &bg);
X	XtGetValues(sideruler_sw, tmp_arg, 2);
X	
X	sidegc = makegc(INV_PAINT, fg, bg);
X}
X
X/* create the gc's for area fill (PAINT and ERASE) */
X/* the fill_pm[] and unfill_pm[] must already be created */
X
Xinit_fill_gc()
X	{
X	XGCValues gcv;
X	int i;
X
X	gcv.fill_style = FillOpaqueStippled;
X	gcv.arc_mode = ArcPieSlice;	/* fill mode for arcs */
X	gcv.fill_rule = EvenOddRule/*WindingRule*/;
X	for (i=0; i<NUMFILLPATS; i++)
X		{
X		fill_gc[i] = makegc(PAINT, x_fg_color.pixel, x_bg_color.pixel);
X		un_fill_gc[i] = makegc(ERASE, x_fg_color.pixel, x_bg_color.pixel);
X		gcv.stipple = fill_pm[i];
X		XChangeGC(tool_d, fill_gc[i], 
X			GCStipple|GCFillStyle|GCFillRule|GCArcMode, &gcv);
X		XChangeGC(tool_d, un_fill_gc[i], 
X			GCStipple|GCFillStyle|GCArcMode, &gcv);
X		}
X	}
X
X/* grey images for fill patterns */
X
X#ifndef TFX
Xstatic char  fill_images[NUMFILLPATS][8] = {
X   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
X   {0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00},
X   {0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00},
X   {0x00, 0x40, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00},
X   {0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00},
X   {0x00, 0x44, 0x00, 0x10, 0x00, 0x44, 0x00, 0x00},
X   {0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00},
X   {0x88, 0x00, 0x32, 0x00, 0x88, 0x00, 0x23, 0x00},
X   {0xc4, 0x00, 0x31, 0x00, 0x8c, 0x00, 0x23, 0x00},
X   {0x99, 0x00, 0xcc, 0x00, 0x66, 0x00, 0x33, 0x00},
X   {0x55, 0x00, 0x55, 0x00, 0x55, 0x00, 0x55, 0x00},
X   {0x55, 0x22, 0x55, 0x08, 0x55, 0x22, 0x55, 0x00},
X   {0x55, 0xa2, 0x55, 0x88, 0x55, 0xa2, 0x55, 0x2a},
X   {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa},
X   {0x55, 0xaa, 0x77, 0xaa, 0x55, 0xaa, 0xdd, 0xaa},
X   {0x55, 0xae, 0x5f, 0xae, 0x55, 0xea, 0xf5, 0xea},
X   {0x5d, 0xb6, 0x7f, 0xd5, 0x7f, 0xb6, 0x5d, 0xaa},
X   {0x77, 0xff, 0x77, 0xaa, 0x77, 0xff, 0x77, 0xaa},
X   {0x77, 0xdd, 0x7f, 0xbe, 0x7f, 0xdd, 0x77, 0xaa},
X   {0x77, 0xff, 0x7f, 0xbe, 0x7f, 0xff, 0x77, 0xaa},
X   {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
X   };
X#else
Xstatic char  fill_images[NUMFILLPATS][8] = {
X   {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
X   {0x55, 0xaa, 0x77, 0xaa, 0x55, 0xaa, 0xdd, 0xaa},
X   {0x55, 0x00, 0x55, 0x00, 0x55, 0x00, 0x55, 0x00},
X   {0x00, 0x44, 0x00, 0x10, 0x00, 0x44, 0x00, 0x00},
X   {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
X   };
X#endif
X
X
X/* generate the fill pixmaps */
X
Xinit_fill_pm()
X	{
X	int i;
X
X	for (i=0; i<NUMFILLPATS; i++)
X	    {
X	    fill_pm[i] = XCreateBitmapFromData(tool_d, XtWindow(canvas_sw),
X			fill_images[i],8,8);
X	    /* create pixmaps of area-fill colors for indicator */
X	    ind_fill_pm[i] = XCreatePixmapFromBitmapData(tool_d, 
X			XtWindow(canvas_sw),
X			fill_images[i],8,8,
X			x_fg_color.pixel,x_bg_color.pixel,
X			DefaultDepthOfScreen(tool_s));
X	    }
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	Window		w;
X	int		x, y;
X	{
X	}
X
X/* popup a confirmation window */
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		int		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, msg_win, 0, 0, 0, 0, False);
X	/* uses knowledge that msg_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, msg_win, msg_gccache[PAINT], 2, y, prompt, len);
X	x = width * len + 4;
X	XGetWindowAttributes(tool_d, msg_win, &attr);
X	XSelectInput(tool_d, msg_win, attr.your_event_mask | KeyPressMask);
X	for (;;)
X	{
X		XWindowEvent(tool_d, msg_win, 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 CTRL_H:
X		case DEL:
X			if (r != reply)
X			{
X				x -= width;
X				--r;
X				XDrawString(tool_d, msg_win, msg_gccache[ERASE],
X					x, y, r, 1);
X			}
X			break;
X		case CTRL_U:
X		case CTRL_X:
X			while (r != reply)
X			{
X				x -= width;
X				--r;
X				XDrawString(tool_d, msg_win, msg_gccache[ERASE],
X					x, y, r, 1);
X			}
X			break;
X		case CR:
X		case NL:
X			*r = '\0';
X			XClearArea(tool_d, msg_win, 0, 0, 0, 0, False);
X			return;
X		default:
X			if (buf[0] < ' ' || buf[0] > '~')
X				continue;
X			XDrawString(tool_d, msg_win, msg_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}
X
Xpw_vector(w, x1, y1, x2, y2, op, line_width, line_style, style_val)
XWindow w;
Xint x1, y1, x2, y2, op, line_width, line_style;
Xfloat style_val;
X	{
X	if (line_width == 0)
X		return;
X	set_line_stuff(line_width,line_style,style_val,op);
X	XDrawLine(tool_d, w, gccache[op], x1, y1, x2, y2);
X	}
X
Xpw_lines(w, points, npoints, op, line_width, line_style, style_val, area_fill)
XWindow	w;
Xint	npoints;
XXPoint	*points;
Xint	op,line_width,line_style,area_fill;
Xfloat	style_val;
X	{
X	GC gc;
X
X	/* if it's a fill pat we know about */
X	if (area_fill && area_fill <= NUMFILLPATS)
X		{
X		if (op == PAINT)
X			gc = fill_gc[area_fill-1];
X		else
X			gc = un_fill_gc[area_fill-1];
X		XFillPolygon(tool_d, w, gc, points, npoints,
X			Complex, CoordModeOrigin);
X		}
X	if (line_width == 0)
X		return;
X	set_line_stuff(line_width, line_style, style_val, op);
X	XDrawLines(tool_d, w, gccache[op], points, npoints, CoordModeOrigin);
X	}
X
Xset_line_stuff(width,style,style_val,op)
Xint	width,style,op;
Xfloat	style_val;
X	{
X	XGCValues gcv;
X	unsigned long mask;
X	char dash_list[2];
X
X	if (width == gc_thickness[op] && style == gc_line_style[op])
X		return;
X	gcv.line_width = (width == 1? 0: width); /* use 0 width for 1 (much faster) */
X	mask = GCLineWidth|GCLineStyle;
X	gcv.line_style = (style==SOLID_LINE)? LineSolid: LineOnOffDash;
X	if (style==SOLID_LINE)
X		XChangeGC(tool_d, gccache[op], mask, &gcv);
X	else
X	    {
X	    mask |= GCDashList;
X	    if (style_val > 0.0)	/* style_val of 0.0 causes problems */
X		{
X		gcv.dashes = (char) style_val;
X		XChangeGC(tool_d, gccache[op], mask, &gcv);
X		/* length of ON/OFF pixels */
X		dash_list[0]=dash_list[1] = (char) style_val;
X		if (style == DOTTED_LINE)
X			dash_list[0] = 1;	/* length of ON pixels for dotted */
X		XSetDashes(tool_d, gccache[op], 0, dash_list, 2);
X		}
X           }
X	gc_thickness[op] = width;
X	gc_line_style[op] = style;
X	}
END_OF_FILE
if test 11232 -ne `wc -c <'xtra.c'`; then
    echo shar: \"'xtra.c'\" unpacked with wrong size!
fi
# end of 'xtra.c'
fi
echo shar: End of archive 11 \(of 21\).
cp /dev/null ark11isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 21 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0

dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list