v01i006: xfig: a MacDraw style line editor(X11), Part05/11
Mike Wexler
mikew at wyse.wyse.com
Wed Aug 17 06:26:44 AEST 1988
Submitted-by: ken at cs.rochester.edu (Ken Yap)
Posting-number: Volume 1, Issue 6
Archive-name: xfig/part05
#! /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 5 (of 11)."
# Contents: FORMAT1.4 autoarrow.c copy.c draw.c flip.c line.c
# Wrapped by mikew at wyse on Tue Aug 16 13:14:38 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f FORMAT1.4 -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"FORMAT1.4\"
else
echo shar: Extracting \"FORMAT1.4\" \(9334 characters\)
sed "s/^X//" >FORMAT1.4 <<'END_OF_FORMAT1.4'
XThe following is the format of fig output (fig 1.4).
X
X(1) The very first line is a comment line containing the name and version:
X #FIG 1.4
X
X The character # at the first column of a line indicates that the line
X is a comment line which will be ignored.
X
X(2) The first non-comment line consists of two numbers :
X
X int fig_resolution (pixels/inch)
X int coordinate_system (1 : origin is at the lower left corner
X 2 : Upper left)
X
X Fig_resolution is the resolution fig is using for the current file.
X It may not be the same as screen resolution (which can be higher or
X lower). I assume that a pixel is square, therefore this number
X represents drawing resolution in both direction. I've experimented
X with fig automatically changing this number according to the resolution
X of the monitor it is running on (The screen resolution, width and height
X in pixels, not pixel/inch, can be done by doing a ioctl on the /dev/fb).
X I've found that for monitors with higher resolution but same size
X (19" diagonal), I preferred using the pixels for other things than
X having fig occupying most of the screen. Thus I opted for a fixed
X pixel-per-inch number which make fig window smaller on higher resolution
X monitor (than the standard sun monitor). This however may change in
X the future version.
X
X(3) The rest of the file contains various objects. An object can be one
X of six classes (or types).
X
X i) Arc.
X ii) Ellipse which is a generalization of circle.
X iii) Polyline which includes polygon and box.
X iv) Spline which includes closed/open control/interpolated spline.
X v) Text.
X vi) Compound object which is composed of one or more objects.
X
X In the following elaboration on object formats, every value of fig
X output are separated by blank characters or new line ('\n'). The
X value of the not-used parameters will be -1.
X
X A number of values are described as unused or not applicable to some
X object even though they are defined for those objects. These value
X will (hopefully) be used in the future version of fig. The intention
X of their uses are the following.
X
X Value Usage
X ----- -----
X area_fill The stipple pattern (which will be align) for
X filling object internals. For example, an filled
X arc will look like a piece of pie.
X
X pen This will be a structure defining the shape of
X pen used in drawing objects. It also includes
X the the stipple pattern for line filling.
X The default pen is a circular pen with black
X filling.
X
X thickness Every pen has the thickness of one.
X Thickness scales the size of a pen.
X
X depth This value adds a half dimension to fig.
X It is useful when we have overlapping filled
X objects and we want one to obliterate another.
X An object can have only one depth (including
X compound object). An object that is in less
X depth can obscure the one with greater depth
X if they overlap.
X
X line_style Only polyline (including polygon and box) can
X be rendered with dashed line. However the
X objects created when the dash-line mode was on
X will be recorded as such. Currently the filter
X f2ps (1) is able to render the desired line style
X effect on hard copy. Three line styles are defined.
X
X 0 : SOLID_LINE
X 1 : DASH_LINE
X 2 : DOTTED_LINE
X
X style_val For dash style, it is the length of a dash.
X For dotted line it indicates the approximated
X gap of consecutive dots.
X
X (3.1) ARC
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 5)
X int sub_type (always 1)
X int line_style (See the end of this section)
X int line_thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels, not used)
X int direction (0 : clockwise, 1 : counterclockwise)
X int forward_arrow (0: no forward arrow, 1: on)
X int backward_arrow (0: no forward arrow, 1: on)
X float center_x, center_y (center of the arc)
X int x1, y1 (pixels, the 1st point the user entered)
X int x2, y2 (pixels, the 2nd point)
X int x3, y3 (pixels, the last point)
X
X Forward arrow line (Optional; absent if forward_arrow is 0) :
X type name (brief description)
X ---- ---- -------------------
X int arrow_type (not used)
X int arrow_style (not used)
X int arrow_thickness (not used)
X int arrow_width (pixels)
X int arrow_height (pixels)
X
X Backward arrow line (Optional; absent if backward_arrow is 0) :
X type name (brief description)
X ---- ---- -------------------
X int arrow_type (not used)
X int arrow_style (not used)
X int arrow_thickness (not used)
X int arrow_width (pixels)
X int arrow_height (pixels)
X
X (3.2) COMPOUND
X
X A line with object code 6 signifies the start of a compound.
X There are four more numbers on this line which indicate the
X upper right corner and the lower left corner of the bounding
X box of this compound. A line with object code -6 signifies
X the end of the compound. Compound may be nested.
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 6)
X int upperright_corner_x (pixels)
X int upperright_corner_y (pixels)
X int lowerleft_corner_x (pixels)
X int lowerleft_corner_y (pixels)
X
X Subsequent lines :
X objects
X .
X .
X
X Last line :
X -6
X
X (3.3) ELLIPSE
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 1)
X int sub_type (1 : ellipse defined by radiuses
X 2 : ellipse defined by diameters
X 3 : circle defined by radius
X 4 : circle defined by diameter)
X int line_style (See the end of this section)
X int thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels, not used)
X int direction (always 1)
X float angle (radian, the angle of the x-axis)
X int center_x, center_y (pixels)
X int radius_x, radius_y (pixels)
X int start_x, start_y (pixels; the 1st point entered)
X int end_x, end_y (pixels; the last point entered)
X
X (3.4) POLYLINE
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 1)
X int sub_type (1 : polyline, 2 : box, 3 : polygon)
X int line_style (See the end of this section)
X int thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels)
X int forward_arrow (0: off, 1: on)
X int backward_arrow (0: off, 1: on)
X
X Forward arrow line : same as ARC object
X
X Backward arrow line : same as ARC object
X
X Points line :
X type name (brief description)
X ---- ---- -------------------
X int x1, y1 (pixels)
X int x2, y2 (pixels)
X .
X .
X int xn, yn (this will be the same as the 1st
X point for polygon and box)
X int x, y (always 9999, 9999; marks the end of
X point for polygon and box)
X
X (3.5) SPLINE
X
X First line :
X type name (brief description)
X ---- ---- -------------------
X int object_code (always 1)
X int sub_type (1 : open spline
X 2 : closed spline
X 3 : open interpolated spline
X 4 : closed interpolated spline)
X int line_style (See the end of this section)
X int thickness (pixels, not used)
X int color (not used)
X int depth (not used)
X int pen (not used)
X int area_fill (not used)
X float style_val (pixels, not used)
X int forward_arrow (0: off, 1: on)
X int backward_arrow (0: off, 1: on)
X
X Forward arrow line : same as ARC object
X
X Backward arrow line : same as ARC object
X
X Points line : same as POLYLINE object
X
X Control points line (absent if sub_type is 1 or 2) :
X Control points of interpolated spline. There are two control
X points for each knots. A section i, of the spline is drawn
X using Bezier cubic with the following four points:
X (x ,y ), (rx ,ry ), (lx , ly ), (x , y ).
X i i i i i+1 i+1 i+1 i+1
X For closed interpolated spline the last pair of control points,
X (lxn,lyn) and (rxn,ryn) (which can be ignored), are the same as
X (lx1,ly1) and (rx1,ry1) respectively.
X
X type name (brief description)
X ---- ---- -------------------
X float lx1, ly1 (pixels)
X float rx1, ry1 (pixels)
X float lx2, ly2 (pixels)
X float rx2, ry2 (pixels)
X .
X .
X float lxn, lyn (pixels)
X float rxn, ryn (pixels)
X
X (3.6) TEXT
X type name (brief description)
X ---- ---- -------------------
X int object (always 4)
X int sub_type (0 : Left justified
X 1 : Center justified
X 2 : Right justified)
X int font (not used)
X int font_size (not used)
X int pen (not used)
X int color (not used)
X int depth (not used)
X int angle (radian, not used, the angle of the
X the base line of the string)
X int font_style (not used)
X int height (pixels)
X int length (pixels)
X int x, y (pixels, coordinate of the origin
X of the string. If sub_type = 0, it is
X the lower left corner of the string.
X If sub_type = 1, it is the lower
X center. Otherwise it is the lower
X right corner of the string.)
X char string[] (ascii characters; starts after a blank
X character following the last number and
X ends before the character '\1'. This
X character is not part of the string.
X Note that the string may contain '\n'.)
END_OF_FORMAT1.4
if test 9334 -ne `wc -c <FORMAT1.4`; then
echo shar: \"FORMAT1.4\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f autoarrow.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"autoarrow.c\"
else
echo shar: Extracting \"autoarrow.c\" \(9036 characters\)
sed "s/^X//" >autoarrow.c <<'END_OF_autoarrow.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define TOLERANCE 7
X
Xextern (*canvas_kbd_proc)();
Xextern (*canvas_locmove_proc)();
Xextern (*canvas_leftbut_proc)();
Xextern (*canvas_middlebut_proc)();
Xextern (*canvas_rightbut_proc)();
Xextern null_proc();
Xextern set_popupmenu();
Xextern F_line *line_point_search();
Xextern F_spline *spline_point_search();
Xextern F_arc *arc_point_search();
Xextern F_arrow *forward_arrow(), *backward_arrow();
X
Xextern int foreground_color, background_color;
Xextern int pointmarker_shown;
X
XF_point *selected_point, *left_point;
Xint arcpoint_num;
X add_arrow_head();
X delete_arrow_head();
X
X#define round(x) ((int) (x + .5))
X
Xarrow_head_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = add_arrow_head;
X canvas_middlebut_proc = delete_arrow_head;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&pick9_cursor);
X }
X
Xadd_arrow_head(x, y)
Xint x, y;
X{
X F_line *line;
X F_spline *spline;
X F_arc *arc;
X
X if ((line = line_point_search(x, y, TOLERANCE,
X &left_point, &selected_point)) != NULL) {
X add_linearrow(line);
X }
X else if ((spline = spline_point_search(x, y,
X TOLERANCE, &left_point, &selected_point)) != NULL){
X add_splinearrow(spline);
X }
X else if ((arc = arc_point_search(x, y, TOLERANCE,
X &arcpoint_num)) != NULL) {
X add_arcarrow(arc);
X }
X else
X return;
X
X set_modifiedflag();
X }
X
Xdelete_arrow_head(x, y)
Xint x, y;
X{
X F_line *line;
X F_spline *spline;
X F_arc *arc;
X
X if ((line = line_point_search(x, y, TOLERANCE,
X &left_point, &selected_point)) != NULL) {
X delete_linearrow(line);
X }
X else if ((spline = spline_point_search(x, y,
X TOLERANCE, &left_point, &selected_point)) != NULL){
X delete_splinearrow(spline);
X }
X else if ((arc = arc_point_search(x, y, TOLERANCE,
X &arcpoint_num)) != NULL) {
X delete_arcarrow(arc);
X }
X else
X return;
X
X set_modifiedflag();
X }
X
Xadd_linearrow(line)
XF_line *line;
X{
X F_point *p;
X
X if (line->type == T_POLYGON || line->type == T_BOX) return;
X if (line->points->next == NULL) return; /* A single point line */
X
X if (left_point == NULL) { /* selected_point is the first point */
X if (line->back_arrow) return;
X p = selected_point->next;
X line->back_arrow = backward_arrow();
X if (pointmarker_shown) toggle_linepointmarker(line);
X draw_arrow(p->x, p->y, selected_point->x, selected_point->y,
X line->back_arrow, PAINT);
X if (pointmarker_shown) toggle_linepointmarker(line);
X }
X else if (selected_point->next == NULL) { /* forward arrow */
X if (line->for_arrow) return;
X line->for_arrow = forward_arrow();
X if (pointmarker_shown) toggle_linepointmarker(line);
X draw_arrow(left_point->x, left_point->y,
X selected_point->x, selected_point->y,
X line->for_arrow, PAINT);
X if (pointmarker_shown) toggle_linepointmarker(line);
X }
X clean_up();
X set_action_object(F_ADD_ARROW_HEAD, O_POLYLINE);
X }
X
Xadd_arcarrow(arc)
XF_arc *arc;
X{
X
X if (arcpoint_num == 0) { /* backward arrow */
X if (arc->back_arrow) return;
X arc->back_arrow = backward_arrow();
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X draw_arcarrow(arc, foreground_color);
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X }
X else if (arcpoint_num == 2) { /* for_arrow */
X if (arc->for_arrow) return;
X arc->for_arrow = forward_arrow();
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X draw_arcarrow(arc, foreground_color);
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X }
X clean_up();
X set_action_object(F_ADD_ARROW_HEAD, O_ARC);
X }
X
Xadd_splinearrow(spline)
XF_spline *spline;
X{
X F_point *p;
X F_control *c;
X
X if (closed_spline(spline)) return;
X if (left_point == NULL) { /* add backward arrow */
X if (spline->back_arrow) return;
X p = selected_point->next;
X spline->back_arrow = backward_arrow();
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X if (normal_spline(spline)) {
X draw_arrow(p->x, p->y, selected_point->x,
X selected_point->y, spline->back_arrow, PAINT);
X }
X else {
X c = spline->controls;
X draw_arrow(round(c->rx), round(c->ry), selected_point->x,
X selected_point->y, spline->back_arrow, PAINT);
X }
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X }
X else if (selected_point->next == NULL) { /* add forward arrow */
X if (spline->for_arrow) return;
X spline->for_arrow = forward_arrow();
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X if (normal_spline(spline)) {
X draw_arrow(left_point->x, left_point->y,
X selected_point->x, selected_point->y,
X spline->for_arrow, PAINT);
X }
X else {
X for (c = spline->controls; c->next != NULL; c = c->next);
X draw_arrow(round(c->lx), round(c->ly), selected_point->x,
X selected_point->y, spline->for_arrow, PAINT);
X }
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X }
X clean_up();
X set_action_object(F_ADD_ARROW_HEAD, O_SPLINE);
X }
X
Xdelete_linearrow(line)
XF_line *line;
X{
X if (line->type == T_POLYGON || line->type == T_BOX) return;
X
X if (left_point == NULL) { /* selected_point is the first point */
X if (! line->back_arrow) return;
X if (pointmarker_shown) toggle_linepointmarker(line);
X draw_line(line, INV_PAINT);
X line->back_arrow = 0;
X free((char*)line->back_arrow);
X line->for_arrow = NULL;
X draw_line(line, PAINT);
X if (pointmarker_shown) toggle_linepointmarker(line);
X }
X else if (selected_point->next == NULL) { /* forward arrow */
X if (! line->for_arrow) return;
X if (pointmarker_shown) toggle_linepointmarker(line);
X draw_line(line, INV_PAINT);
X free((char*)line->for_arrow);
X line->for_arrow = NULL;
X draw_line(line, PAINT);
X if (pointmarker_shown) toggle_linepointmarker(line);
X }
X clean_up();
X set_action_object(F_DELETE_ARROW_HEAD, O_POLYLINE);
X }
X
Xdelete_arcarrow(arc)
XF_arc *arc;
X{
X if (arcpoint_num == 0) { /* backward arrow */
X if (! arc->back_arrow) return;
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X draw_arc(arc, background_color);
X free((char*)arc->back_arrow);
X arc->back_arrow = NULL;
X draw_arc(arc, foreground_color);
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X }
X else if (arcpoint_num == 2) { /* for_arrow */
X if (! arc->for_arrow) return;
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X draw_arc(arc, background_color);
X free((char*)arc->for_arrow);
X arc->for_arrow = NULL;
X draw_arc(arc, foreground_color);
X if (pointmarker_shown) toggle_arcpointmarker(arc);
X }
X clean_up();
X set_action_object(F_DELETE_ARROW_HEAD, O_ARC);
X }
X
Xdelete_splinearrow(spline)
XF_spline *spline;
X{
X F_point *p;
X
X if (closed_spline(spline)) return;
X if (left_point == NULL) { /* selected_point is the first point */
X if (! spline->back_arrow) return;
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X p = selected_point->next;
X if (normal_spline(spline)) {
X draw_arrow(p->x, p->y, selected_point->x,
X selected_point->y, spline->back_arrow, ERASE);
X pw_vector(canvas_pixwin, selected_point->x, selected_point->y,
X round((p->x+selected_point->x)/2.0),
X round((p->y+selected_point->y)/2.0), PAINT, 1);
X }
X else {
X F_control *a, *b;
X
X a = spline->controls;
X b = a->next;
X draw_arrow(round(a->rx), round(a->ry), selected_point->x,
X selected_point->y, spline->back_arrow, ERASE);
X bezier_spline(
X (float)selected_point->x, (float)selected_point->y,
X a->rx, a->ry, b->lx, b->ly, (float)p->x, (float)p->y,
X PAINT);
X }
X free((char*)spline->back_arrow);
X spline->back_arrow = NULL;
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X }
X else if (selected_point->next == NULL) { /* forward arrow */
X if (! spline->for_arrow) return;
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X if (normal_spline(spline)) {
X draw_arrow(left_point->x, left_point->y,
X selected_point->x, selected_point->y,
X spline->for_arrow, ERASE);
X pw_vector(canvas_pixwin, selected_point->x, selected_point->y,
X round((selected_point->x+left_point->x)/2.0),
X round((selected_point->y+left_point->y)/2.0),
X PAINT, 1);
X }
X else {
X F_control *a, *b;
X
X a = spline->controls;
X for (b = a->next; b->next != NULL; a = b, b = b->next);
X draw_arrow(round(b->lx), round(b->ly), selected_point->x,
X selected_point->y, spline->for_arrow, ERASE);
X bezier_spline(
X (float)left_point->x, (float)left_point->y,
X a->rx, a->ry, b->lx, b->ly,
X (float)selected_point->x, (float)selected_point->y,
X PAINT);
X }
X free((char*)spline->for_arrow);
X spline->for_arrow = NULL;
X if (pointmarker_shown) toggle_splinepointmarker(spline);
X }
X clean_up();
X set_action_object(F_DELETE_ARROW_HEAD, O_SPLINE);
X }
END_OF_autoarrow.c
if test 9036 -ne `wc -c <autoarrow.c`; then
echo shar: \"autoarrow.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f copy.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"copy.c\"
else
echo shar: Extracting \"copy.c\" \(7706 characters\)
sed "s/^X//" >copy.c <<'END_OF_copy.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "alloc.h"
X#include "func.h"
X#include "object.h"
X#include "paintop.h"
X
X#define TOLERANCE 7
X
Xextern (*canvas_kbd_proc)();
Xextern (*canvas_locmove_proc)();
Xextern (*canvas_leftbut_proc)();
Xextern (*canvas_middlebut_proc)();
Xextern (*canvas_rightbut_proc)();
Xextern (*return_proc)();
Xextern null_proc();
Xextern set_popupmenu();
Xextern F_line *line_search(), *copy_line();
Xextern F_arc *arc_search(), *copy_arc();
Xextern F_ellipse *ellipse_search(), *copy_ellipse();
Xextern F_text *text_search(), *copy_text();
Xextern F_spline *spline_search(), *copy_spline();
Xextern F_compound *compound_search(), *copy_compound();
X
Xextern F_compound objects;
X
Xextern int copy_selected();
X init_copy();
X
Xcopy_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_copy;
X canvas_middlebut_proc = null_proc;
X canvas_rightbut_proc = set_popupmenu;
X return_proc = copy_selected;
X set_cursor(&pick15_cursor);
X reset_action_on();
X }
X
Xinit_copy(x, y)
Xint x, y;
X{
X F_line *l, *line;
X F_ellipse *e, *ellipse;
X F_text *t, *text;
X F_spline *s, *spline;
X F_arc *a, *arc;
X F_compound *c, *compound;
X int px, py;
X
X if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X compound = copy_compound(c);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X clean_up();
X set_action_object(F_CREATE, O_COMPOUND);
X insert_compound(&objects.compounds, compound);
X set_latestcompound(compound);
X init_compounddragging(compound, px, py);
X }
X else if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X line = copy_line(l);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X clean_up();
X set_action_object(F_CREATE, O_POLYLINE);
X insert_line(&objects.lines, line);
X set_latestline(line);
X init_linedragging(line, px, py);
X }
X else if ((t = text_search(x, y)) != NULL) {
X text = copy_text(t);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X clean_up();
X set_action_object(F_CREATE, O_TEXT);
X insert_text(&objects.texts, text);
X set_latesttext(text);
X init_textdragging(text, x, y);
X }
X else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X ellipse = copy_ellipse(e);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X clean_up();
X set_action_object(F_CREATE, O_ELLIPSE);
X insert_ellipse(&objects.ellipses, ellipse);
X set_latestellipse(ellipse);
X init_ellipsedragging(ellipse, px, py);
X }
X else if ((a = arc_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X arc = copy_arc(a);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X clean_up();
X set_action_object(F_CREATE, O_ARC);
X insert_arc(&objects.arcs, arc);
X set_latestarc(arc);
X init_arcdragging(arc, px, py);
X }
X else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X spline = copy_spline(s);
X erase_pointmarker();
X set_temp_cursor(&null_cursor);
X win_setmouseposition(canvas_swfd, px, py);
X clean_up();
X set_action_object(F_CREATE, O_SPLINE);
X insert_spline(&objects.splines, spline);
X set_latestspline(spline);
X init_splinedragging(spline, px, py);
X }
X else
X return;
X canvas_leftbut_proc = canvas_rightbut_proc = null_proc;
X }
X
XF_arc *
Xcopy_arc(a)
XF_arc *a;
X{
X F_arc *arc;
X
X if (NULL == (Arc_malloc(arc))) {
X put_msg(Err_mem);
X return(NULL);
X }
X *arc = *a;
X arc->next = NULL;
X return(arc);
X }
X
XF_ellipse *
Xcopy_ellipse(e)
XF_ellipse *e;
X{
X F_ellipse *ellipse;
X
X if (NULL == (Ellipse_malloc(ellipse))) {
X put_msg(Err_mem);
X return(NULL);
X }
X *ellipse = *e;
X ellipse->next = NULL;
X return(ellipse);
X }
X
XF_line *
Xcopy_line(l)
XF_line *l;
X{
X F_line *line;
X F_point *p, *point, *last_point;
X
X if (NULL == (Line_malloc(line))) {
X put_msg(Err_mem);
X return(NULL);
X }
X *line = *l;
X line->points = Point_malloc(point);
X last_point = point;
X p = l->points;
X *point = *p;
X point->next = NULL;
X for (p = p->next; p != NULL; p = p->next) {
X last_point->next = Point_malloc(point);
X if (point == NULL) return(NULL);
X *point = *p;
X point->next = NULL;
X last_point = point;
X }
X line->next = NULL;
X return(line);
X }
X
XF_spline *
Xcopy_spline(s)
XF_spline *s;
X{
X F_spline *spline;
X F_point *p, *point, *last_point;
X F_control *cntrl_pnt, *cp, *last_cntrl_pnt;
X
X if (NULL == (Spline_malloc(spline))) {
X put_msg(Err_mem);
X return(NULL);
X }
X *spline = *s;
X spline->next = NULL;
X
X Point_malloc(point);
X last_point = spline->points = point;
X p = s->points;
X *point = *p;
X for (p = p->next; p != NULL; p = p->next) {
X last_point->next = Point_malloc(point);
X if (point == NULL) return(NULL);
X *point = *p;
X last_point = point;
X }
X last_point->next = NULL;
X
X spline->controls = NULL;
X if (s->controls == NULL) return(spline);
X
X last_cntrl_pnt = spline->controls = Control_malloc(cntrl_pnt);
X cp = s->controls;
X *cntrl_pnt = *cp;
X for (cp = cp->next; cp != NULL; cp = cp->next) {
X last_cntrl_pnt->next = Control_malloc(cntrl_pnt);
X if (cntrl_pnt == NULL) return(NULL);
X *cntrl_pnt = *cp;
X last_cntrl_pnt = cntrl_pnt;
X }
X last_cntrl_pnt->next = NULL;
X
X return(spline);
X }
X
XF_text *
Xcopy_text(t)
XF_text *t;
X{
X F_text *text;
X extern char *calloc();
X
X if (NULL == (Text_malloc(text))) {
X put_msg(Err_mem);
X return(NULL);
X }
X *text = *t;
X text->cstring = calloc((unsigned)(strlen(t->cstring)+1), sizeof(char));
X if (text->cstring == NULL) {
X free((char*)text);
X put_msg(Err_mem);
X return(NULL);
X }
X strcpy(text->cstring, t->cstring);
X text->next = NULL;
X return(text);
X }
X
XF_compound *
Xcopy_compound(c)
XF_compound *c;
X{
X F_ellipse *e, *ee;
X F_arc *a, *aa;
X F_line *l, *ll;
X F_spline *s, *ss;
X F_text *t, *tt;
X F_compound *cc, *ccc, *compound;
X
X if (NULL == (Compound_malloc(compound))) {
X put_msg(Err_mem);
X return(NULL);
X }
X compound->nwcorner = c->nwcorner;
X compound->secorner = c->secorner;
X compound->arcs = NULL;
X compound->ellipses = NULL;
X compound->lines = NULL;
X compound->splines = NULL;
X compound->texts = NULL;
X compound->compounds = NULL;
X compound->next = NULL;
X for (e = c->ellipses; e != NULL; e = e->next) {
X if (NULL == (ee = copy_ellipse(e))) {
X put_msg(Err_mem);
X return(NULL);
X }
X insert_ellipse(&compound->ellipses, ee);
X }
X for (a = c->arcs; a != NULL; a = a->next) {
X if (NULL == (aa = copy_arc(a))) {
X put_msg(Err_mem);
X return(NULL);
X }
X insert_arc(&compound->arcs, aa);
X }
X for (l = c->lines; l != NULL; l = l->next) {
X if (NULL == (ll = copy_line(l))) {
X put_msg(Err_mem);
X return(NULL);
X }
X insert_line(&compound->lines, ll);
X }
X for (s = c->splines; s != NULL; s = s->next) {
X if (NULL == (ss = copy_spline(s))) {
X put_msg(Err_mem);
X return(NULL);
X }
X insert_spline(&compound->splines, ss);
X }
X for (t = c->texts; t != NULL; t = t->next) {
X if (NULL == (tt = copy_text(t))) {
X put_msg(Err_mem);
X return(NULL);
X }
X insert_text(&compound->texts, tt);
X }
X for (cc = c->compounds; cc != NULL; cc = cc->next) {
X if (NULL == (ccc = copy_compound(cc))) {
X put_msg(Err_mem);
X return(NULL);
X }
X insert_compound(&compound->compounds, ccc);
X }
X return(compound);
X }
END_OF_copy.c
if test 7706 -ne `wc -c <copy.c`; then
echo shar: \"copy.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f draw.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"draw.c\"
else
echo shar: Extracting \"draw.c\" \(7937 characters\)
sed "s/^X//" >draw.c <<'END_OF_draw.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1988 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * March 1988.
X *
X * %W% %G%
X*/
X#include "fig.h"
X#include "resources.h"
X#include "object.h"
X#include "paintop.h"
X
Xextern int pointmarker_shown, compoundbox_shown;
Xextern int background_color, foreground_color;
Xextern PIXRECTREC dot;
X
X/*
Xerase_objects(objects)
XF_compound *objects;
X{
X erase_arcs(objects->arcs);
X erase_ellipses(objects->ellipses);
X erase_lines(objects->lines);
X erase_texts(objects->texts);
X erase_splines(objects->splines);
X erase_compounds(objects->compounds);
X }
X*/
X
Xerase_splines(splines)
XF_spline *splines;
X{
X F_spline *s;
X
X pw_batch_on(canvas_pixwin);
X for (s = splines; s != NULL; s = s->next) {
X if (pointmarker_shown) toggle_splinepointmarker(s);
X draw_spline(s, ERASE);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xerase_ellipses(ellipses)
XF_ellipse *ellipses;
X{
X F_ellipse *e;
X
X pw_batch_on(canvas_pixwin);
X for (e = ellipses; e != NULL; e = e->next) {
X if (pointmarker_shown) toggle_ellipsepointmarker(e);
X draw_ellipse(e, background_color);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xerase_arcs(arcs)
XF_arc *arcs;
X{
X F_arc *a;
X
X pw_batch_on(canvas_pixwin);
X for (a = arcs; a != NULL; a = a->next) {
X if (pointmarker_shown) toggle_arcpointmarker(a);
X draw_arc(a, background_color);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xerase_compounds(compounds)
XF_compound *compounds;
X{
X F_compound *c;
X
X for (c = compounds; c != NULL; c = c->next) {
X if (compoundbox_shown) draw_compoundbox(c, INV_PAINT);
X erase_compound(c);
X };
X }
X
Xerase_lines(lines)
XF_line *lines;
X{
X F_line *l;
X
X for (l = lines; l != NULL; l = l->next) {
X if (pointmarker_shown) toggle_linepointmarker(l);
X draw_line(l, ERASE);
X };
X }
X
Xerase_texts(texts)
XF_text *texts;
X{
X F_text *t;
X
X for (t = texts; t != NULL; t = t->next) {
X draw_text(t, INV_PAINT);
X };
X }
X
X/*
Xdraw_objects(objects)
XF_compound *objects;
X{
X draw_arcs(objects->arcs);
X draw_ellipses(objects->ellipses);
X draw_lines(objects->lines);
X draw_texts(objects->texts);
X draw_splines(objects->splines);
X draw_compounds(objects->compounds);
X }
X*/
X
Xdraw_ellipses(ellipses)
XF_ellipse *ellipses;
X{
X F_ellipse *e;
X
X pw_batch_on(canvas_pixwin);
X for (e = ellipses; e != NULL; e = e->next) {
X draw_ellipse(e, foreground_color);
X if (pointmarker_shown) toggle_ellipsepointmarker(e);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xdraw_arcs(arcs)
XF_arc *arcs;
X{
X F_arc *a;
X
X pw_batch_on(canvas_pixwin);
X for (a = arcs; a != NULL; a = a->next) {
X draw_arc(a, foreground_color);
X if (pointmarker_shown) toggle_arcpointmarker(a);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xdraw_lines(lines)
XF_line *lines;
X{
X F_line *l;
X
X pw_batch_on(canvas_pixwin);
X for (l = lines; l != NULL; l = l->next) {
X draw_line(l, PAINT);
X if (pointmarker_shown) toggle_linepointmarker(l);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xdraw_splines(splines)
XF_spline *splines;
X{
X F_spline *s;
X
X pw_batch_on(canvas_pixwin);
X for (s = splines; s != NULL; s = s->next) {
X draw_spline(s, PAINT);
X if (pointmarker_shown) toggle_splinepointmarker(s);
X };
X pw_batch_off(canvas_pixwin);
X }
X
Xdraw_texts(texts)
XF_text *texts;
X{
X F_text *t;
X
X for (t = texts; t != NULL; t = t->next) {
X draw_text(t, PAINT);
X };
X }
X
Xdraw_compounds(compounds)
XF_compound *compounds;
X{
X F_compound *c;
X
X for (c = compounds; c != NULL; c = c->next) {
X draw_compound(c);
X if (compoundbox_shown) draw_compoundbox(c, INV_PAINT);
X };
X }
X
X/* draw arrow heading from (x1, y1) to (x2, y2) */
X
Xdraw_arrow(x1, y1, x2, y2, arrow, op)
Xint x1, y1, x2, y2, op;
XF_arrow *arrow;
X{
X float x, y, xb, yb, dx, dy, l, sina, cosa;
X int xc, yc, xd, yd;
X float wid = arrow->wid, ht = arrow->ht;
X
X dx = x2 - x1; dy = y1 - y2;
X l = sqrt((double)(dx*dx + dy*dy));
X sina = dy / l; cosa = dx / l;
X xb = x2*cosa - y2*sina;
X yb = x2*sina + y2*cosa;
X x = xb - ht;
X y = yb - wid / 2;
X xc = x*cosa + y*sina + .5;
X yc = -x*sina + y*cosa + .5;
X y = yb + wid / 2;
X xd = x*cosa + y*sina + .5;
X yd = -x*sina + y*cosa + .5;
X pw_vector(canvas_pixwin, xc, yc, x2, y2, op, 1);
X pw_vector(canvas_pixwin, xd, yd, x2, y2, op, 1);
X }
X
Xdraw_spline(spline, op)
XF_spline *spline;
Xint op;
X{
X if (int_spline(spline))
X draw_intspline(spline, op);
X else if (spline->type == T_CLOSED_NORMAL)
X draw_closed_spline(spline, op);
X else if (spline->type == T_OPEN_NORMAL)
X draw_open_spline(spline, op);
X }
X
X#define STACK_DEPTH 32
Xtypedef struct stack {
X float x1, y1, x2, y2, x3, y3, x4, y4;
X }
X Stack;
Xstatic Stack stack[20];
Xstatic Stack *stack_top;
Xstatic int stack_count;
X
Xclear_stack()
X{
X stack_top = stack;
X stack_count = 0;
X }
X
Xpush(x1, y1, x2, y2, x3, y3, x4, y4)
Xfloat x1, y1, x2, y2, x3, y3, x4, y4;
X{
X stack_top->x1 = x1;
X stack_top->y1 = y1;
X stack_top->x2 = x2;
X stack_top->y2 = y2;
X stack_top->x3 = x3;
X stack_top->y3 = y3;
X stack_top->x4 = x4;
X stack_top->y4 = y4;
X stack_top++;
X stack_count++;
X }
X
Xint
Xpop(x1, y1, x2, y2, x3, y3, x4, y4)
Xfloat *x1, *y1, *x2, *y2, *x3, *y3, *x4, *y4;
X{
X if (stack_count == 0) return(0);
X stack_top--;
X stack_count--;
X *x1 = stack_top->x1;
X *y1 = stack_top->y1;
X *x2 = stack_top->x2;
X *y2 = stack_top->y2;
X *x3 = stack_top->x3;
X *y3 = stack_top->y3;
X *x4 = stack_top->x4;
X *y4 = stack_top->y4;
X return(1);
X }
X
Xdraw_line(line, op)
XF_line *line;
Xint op;
X{
X F_point *point;
X int xx, yy, x, y;
X
X point = line->points;
X x = point->x;
X y = point->y;
X if (line->points->next == NULL) { /* A single point */
X#ifndef X11
X pw_write(canvas_pixwin, x, y, 1, 1, op, &dot, 0, 0);
X#else
X XDrawPoint(tool_d, canvas_pixwin, gccache[op], x, y);
X#endif X11
X return;
X }
X if (line->back_arrow) /* backward arrow */
X draw_arrow(point->next->x, point->next->y, x, y,
X line->back_arrow, op);
X for (point = point->next; point != NULL; point = point->next) {
X draw_line_segment(line->style, line->style_val,
X x, y, point->x, point->y, op);
X xx = x; yy = y;
X x = point->x;
X y = point->y;
X }
X if (line->for_arrow)
X draw_arrow(xx, yy, x, y, line->for_arrow, op);
X }
X
X#define round(x) ((int)((x) + .5))
X#define dash_length style_val
X#define dot_gap style_val
X
Xdraw_line_segment(line_style, style_val, x1, y1, x2, y2, op)
Xint line_style, x1, y1, x2, y2, op;
Xfloat style_val;
X{
X switch (line_style) {
X case SOLID_LINE :
X pw_vector(canvas_pixwin, x1, y1, x2, y2, op, 1);
X break;
X case DASH_LINE : {
X float x, y, leng, dx, dy, dash_x, dash_y;
X float spacing_leng, space_x, space_y;
X int num_spacing;
X
X dx = x2 - x1;
X dy = y2 - y1;
X leng = sqrt((double)(dx*dx + dy*dy));
X if (leng <= dash_length) {
X pw_vector(canvas_pixwin, x1, y1, x2, y2, op, 1);
X break;
X }
X dash_x = dash_length * dx / leng;
X dash_y = dash_length * dy / leng;
X num_spacing = (leng - dash_length) / (2 * dash_length);
X spacing_leng = (leng - dash_length * (num_spacing + 1)) /
X ((float)num_spacing);
X space_x = spacing_leng * dx / leng;
X space_y = spacing_leng * dy / leng;
X dx = dash_x + space_x; dy = dash_y + space_y;
X for (x = x1, y = y1; leng > 0;
X x += dx, y += dy, leng -= dash_length + spacing_leng) {
X pw_vector(canvas_pixwin, round(x), round(y),
X round(x + dash_x), round(y + dash_y), op, 1);
X }
X break;
X }
X case DOTTED_LINE : {
X float x, y, leng, dx, dy, gap_x, gap_y;
X int n, color;
X
X dot_gap += 1.0;
X dx = x2 - x1;
X dy = y2 - y1;
X leng = sqrt((double)(dx*dx + dy*dy)) - 1;
X n = round(leng/dot_gap);
X if (op == PAINT)
X color = foreground_color;
X else
X color = background_color;
X if (n <= 1) {
X pw_put(canvas_pixwin, x1, y1, color);
X pw_put(canvas_pixwin, x2, y2, color);
X break;
X }
X dot_gap = leng / n;
X gap_x = dot_gap * dx / leng;
X gap_y = dot_gap * dy / leng;
X for (x = x1, y = y1; n-- >= 0; x += gap_x, y += gap_y)
X pw_put(canvas_pixwin, round(x), round(y), color);
X break;
X }
X }
X }
END_OF_draw.c
if test 7937 -ne `wc -c <draw.c`; then
echo shar: \"draw.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f flip.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"flip.c\"
else
echo shar: Extracting \"flip.c\" \(9354 characters\)
sed "s/^X//" >flip.c <<'END_OF_flip.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
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_text *copy_text();
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 flip_axis;
Xextern int pointmarker_shown;
Xextern int foreground_color, background_color;
X
Xstatic int copy;
X init_flip();
X init_copynflip();
X
Xflip_selected()
X{
X canvas_kbd_proc = null_proc;
X canvas_locmove_proc = null_proc;
X canvas_leftbut_proc = init_copynflip;
X canvas_middlebut_proc = init_flip;
X canvas_rightbut_proc = set_popupmenu;
X set_cursor(&pick15_cursor);
X }
X
Xinit_flip(x, y)
Xint x, y;
X{
X copy = 0;
X flip_search(x, y);
X flip_selected();
X }
X
Xinit_copynflip(x, y)
Xint x, y;
X{
X copy = 1;
X flip_search(x, y);
X flip_selected();
X }
X
Xflip_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_flipline(l, px, py);
X }
X else if ((a = arc_point_search(x, y, TOLERANCE, &px)) != NULL) {
X init_fliparc(a, a->point[px].x, a->point[px].y);
X }
X else if ((e = ellipse_point_search(x, y, TOLERANCE, &px)) != NULL) {
X if (px == 0) /* start point */
X init_flipellipse(e, e->start.x, e->start.y);
X else
X init_flipellipse(e, e->end.x, e->end.y);
X }
X else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipellipse(e, px, py);
X }
X else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipspline(s, px, py);
X }
X else if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
X init_flipcompound(c, px, py);
X }
X set_modifiedflag();
X }
X
Xinit_fliparc(a, px, py)
XF_arc *a;
Xint px, py;
X{
X F_arc *arc;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_arcpointmarker(a);
X if (copy) {
X arc = copy_arc(a);
X flip_arc(arc, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_ARC);
X insert_arc(&objects.arcs, arc);
X }
X else {
X draw_arc(a, background_color);
X flip_arc(a, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_ARC);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X arc = a;
X }
X draw_arc(arc, foreground_color);
X if (pointmarker_shown) {
X toggle_arcpointmarker(arc);
X if (copy) toggle_arcpointmarker(a);
X }
X set_latestarc(arc);
X }
X
Xinit_flipcompound(c, px, py)
XF_compound *c;
Xint px, py;
X{
X F_compound *compound;
X
X win_setmouseposition(canvas_swfd, px, py);
X set_temp_cursor(&wait_cursor);
X if (copy) {
X compound = copy_compound(c);
X flip_compound(compound, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_COMPOUND);
X insert_compound(&objects.compounds, compound);
X }
X else {
X draw_compoundbox(c, INV_PAINT);
X erase_compound(c);
X flip_compound(c, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_COMPOUND);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X compound = c;
X }
X draw_compoundbox(compound, INV_PAINT);
X draw_compound(compound);
X set_latestcompound(compound);
X set_temp_cursor(cur_cursor);
X }
X
Xinit_flipellipse(e, px, py)
XF_ellipse *e;
X{
X F_ellipse *ellipse;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_ellipsepointmarker(e);
X if (copy) {
X ellipse = copy_ellipse(e);
X flip_ellipse(ellipse, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_ELLIPSE);
X insert_ellipse(&objects.ellipses, ellipse);
X }
X else {
X draw_ellipse(e, background_color);
X flip_ellipse(e, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_ELLIPSE);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X ellipse = e;
X }
X draw_ellipse(ellipse, foreground_color);
X if (pointmarker_shown) {
X toggle_ellipsepointmarker(ellipse);
X if (copy) toggle_ellipsepointmarker(e);
X }
X set_latestellipse(ellipse);
X }
X
Xinit_flipline(l, px, py)
XF_line *l;
Xint px, py;
X{
X F_line *line;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_linepointmarker(l);
X if (copy) {
X line = copy_line(l);
X flip_line(line, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_POLYLINE);
X insert_line(&objects.lines, line);
X }
X else {
X draw_line(l, ERASE);
X flip_line(l, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_POLYLINE);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X line = l;
X }
X draw_line(line, PAINT);
X if (pointmarker_shown) {
X toggle_linepointmarker(line);
X if (copy) toggle_linepointmarker(l);
X }
X set_latestline(line);
X }
X
Xinit_flipspline(s, px, py)
XF_spline *s;
Xint px, py;
X{
X F_spline *spline;
X
X win_setmouseposition(canvas_swfd, px, py);
X if (pointmarker_shown) toggle_splinepointmarker(s);
X if (copy) {
X spline = copy_spline(s);
X flip_spline(spline, px, py, flip_axis);
X clean_up();
X set_action_object(F_CREATE, O_SPLINE);
X insert_spline(&objects.splines, spline);
X }
X else { /* delete the original */
X draw_spline(s, ERASE);
X flip_spline(s, px, py, flip_axis);
X clean_up();
X set_action_object(F_FLIP, O_SPLINE);
X set_lastaxis(flip_axis);
X set_lastposition(px, py);
X spline = s;
X }
X draw_spline(spline, PAINT);
X if (pointmarker_shown) {
X toggle_splinepointmarker(spline);
X if (copy) toggle_splinepointmarker(s);
X }
X set_latestspline(spline);
X }
X
Xflip_line(l, x, y, flip_axis)
XF_line *l;
Xint x, y, flip_axis;
X{
X F_point *p;
X
X switch(flip_axis) {
X case 1 : /* x axis */
X for (p = l->points; p != NULL; p = p->next)
X p->y = y + (y - p->y);
X break;
X case 2 : /* y axis */
X for (p = l->points; p != NULL; p = p->next)
X p->x = x + (x - p->x);
X break;
X }
X }
X
Xflip_spline(s, x, y, flip_axis)
XF_spline *s;
Xint x, y, flip_axis;
X{
X F_point *p;
X F_control *cp;
X
X switch(flip_axis) {
X case 1 : /* x axis */
X for (p = s->points; p != NULL; p = p->next)
X p->y = y + (y - p->y);
X for (cp = s->controls; cp != NULL; cp = cp->next) {
X cp->ly = y + (y - cp->ly);
X cp->ry = y + (y - cp->ry);
X }
X break;
X case 2 : /* y axis */
X for (p = s->points; p != NULL; p = p->next)
X p->x = x + (x - p->x);
X for (cp = s->controls; cp != NULL; cp = cp->next) {
X cp->lx = x + (x - cp->lx);
X cp->rx = x + (x - cp->rx);
X }
X break;
X }
X }
X
Xflip_text(t, x, y, flip_axis)
XF_text *t;
Xint x, y, flip_axis;
X{
X switch(flip_axis) {
X case 1 : /* x axis */
X t->base_y = y + (y - t->base_y);
X break;
X case 2 : /* y axis */
X t->base_x = x + (x - t->base_x);
X break;
X }
X }
X
Xflip_ellipse(e, x, y, flip_axis)
XF_ellipse *e;
Xint x, y, flip_axis;
X{
X switch(flip_axis) {
X case 1 : /* x axis */
X e->direction ^= 1;
X e->center.y = y + (y - e->center.y);
X e->start.y = y + (y - e->start.y);
X e->end.y = y + (y - e->end.y);
X break;
X case 2 : /* y axis */
X e->direction ^= 1;
X e->center.x = x + (x - e->center.x);
X e->start.x = x + (x - e->start.x);
X e->end.x = x + (x - e->end.x);
X break;
X }
X }
X
Xflip_arc(a, x, y, flip_axis)
XF_arc *a;
Xint x, y, flip_axis;
X{
X switch(flip_axis) {
X case 1 : /* x axis */
X a->direction ^= 1;
X a->center.y = y + (y - a->center.y);
X a->point[0].y = y + (y - a->point[0].y);
X a->point[1].y = y + (y - a->point[1].y);
X a->point[2].y = y + (y - a->point[2].y);
X break;
X case 2 : /* y axis */
X a->direction ^= 1;
X a->center.x = x + (x - a->center.x);
X a->point[0].x = x + (x - a->point[0].x);
X a->point[1].x = x + (x - a->point[1].x);
X a->point[2].x = x + (x - a->point[2].x);
X break;
X }
X }
X
Xflip_compound(c, x, y, flip_axis)
XF_compound *c;
Xint x, y, flip_axis;
X{
X F_line *l;
X F_arc *a;
X F_ellipse *e;
X F_spline *s;
X F_text *t;
X int p, q;
X
X switch(flip_axis) {
X case 1 : /* x axis */
X p = y + (y - c->nwcorner.y);
X q = y + (y - c->secorner.y);
X c->nwcorner.y = min(p, q);
X c->secorner.y = max(p, q);
X break;
X case 2 : /* y axis */
X p = x + (x - c->nwcorner.x);
X q = x + (x - c->secorner.x);
X c->nwcorner.x = min(p, q);
X c->secorner.x = max(p, q);
X break;
X }
X for (l = c->lines; l != NULL; l = l->next)
X flip_line(l, x, y, flip_axis);
X for (a = c->arcs; a != NULL; a = a->next)
X flip_arc(a, x, y, flip_axis);
X for (e = c->ellipses; e != NULL; e = e->next)
X flip_ellipse(e, x, y, flip_axis);
X for (s = c->splines; s != NULL; s = s->next)
X flip_spline(s, x, y, flip_axis);
X for (t = c->texts; t != NULL; t = t->next)
X flip_text(t, x, y, flip_axis);
X }
END_OF_flip.c
if test 9354 -ne `wc -c <flip.c`; then
echo shar: \"flip.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f line.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"line.c\"
else
echo shar: Extracting \"line.c\" \(8978 characters\)
sed "s/^X//" >line.c <<'END_OF_line.c'
X/*
X * FIG : Facility for Interactive Generation of figures
X *
X * Copyright (c) 1985 by Supoj Sutanthavibul (supoj at sally.UTEXAS.EDU)
X * January 1985.
X * 1st revision : Aug 1985.
X *
X * %W% %G%
X*/
X#include "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;
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 cur_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;
X init_line_drawing();
X
Xint create_lineobject();
X create_latexobject();
X determine_angle();
X freehand_elasticline();
X latex_elasticline();
X angle0_elasticline(), angle90_elasticline();
X angle45_elasticline(), angle135_elasticline();
X get_direction(), get_intermediatepoint(),
X 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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
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_pixwin, fix_x, fix_y, x, y, INV_PAINT,1);
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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
X cur_x = x;
X pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
X win_setmouseposition(canvas_swfd, 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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
X cur_y = y;
X pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
X win_setmouseposition(canvas_swfd, 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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
X win_setmouseposition(canvas_swfd, 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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
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_pixwin, fix_x, fix_y, cur_x, cur_y, INV_PAINT,1);
X win_setmouseposition(canvas_swfd, 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_swfd, 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 if (cur_command == F_POLYLINE || cur_command == F_POLYGON)
X draw_line_segment(cur_line_style, cur_styleval, fix_x, fix_y, x, y,
X PAINT);
X else
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_swfd, cur_x, cur_y);
X }
X create_lineobject(cur_x, cur_y);
X }
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 get_intermediatepoint(x, y);
X draw_elasticline();
X }
X else if (num_point == 1) {
X dot = 1;
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 = cur_line_style;
X line->thickness = line_thickness;
X line->style_val = cur_styleval;
X line->color = cur_color;
X line->depth = 0;
X line->area_fill = NULL;
X line->pen = NULL;
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) {
X if (num_point >= 3) {
X line->type = T_POLYGON;
X num_point++;
X append_point(firstx, firsty, &cur_point);
X draw_line_segment(cur_line_style, cur_styleval,
X firstx, firsty, fix_x, fix_y, PAINT);
X }
X }
X else if (dot) {
X pw_vector(canvas_pixwin, fix_x, fix_y, cur_x, cur_y, PAINT, 1);
X line->style = SOLID_LINE;
X }
X else if (num_point > 1) {
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 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 }
END_OF_line.c
if test 8978 -ne `wc -c <line.c`; then
echo shar: \"line.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 5 \(of 11\).
cp /dev/null ark5isdone
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