william@CS.UCLA.EDU (William Cheng) (03/14/91)
Submitted-by: william@CS.UCLA.EDU (William Cheng) Posting-number: Volume 12, Issue 27 Archive-name: tgif/part11 ---------------------------------> cut here <--------------------------------- #! /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 23)." # Contents: raster.c rcbox.c # Wrapped by william@oahu on Wed Mar 6 09:57:33 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'raster.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'raster.c'\" else echo shar: Extracting \"'raster.c'\" \(17765 characters\) sed "s/^X//" >'raster.c' <<'END_OF_FILE' X/* X * Author: William Chia-Wei Cheng (william@cs.ucla.edu) X * X * Copyright (C) 1990, 1991, William Cheng. X */ X#ifndef lint Xstatic char RCSid[] = X "@(#)$Header: /tmp_mnt/n/kona/tangram/u/william/X11/TGIF2/RCS/raster.c,v 2.0 91/03/05 12:48:04 william Exp $"; X#endif X X#include <X11/Xlib.h> X#include "const.h" X#include "types.h" X X#include "choice.e" X#include "color.e" X#include "font.e" X#include "pattern.e" X#include "setup.e" X X#include "xbm/arrow.xbm" X#include "xbm/text.xbm" X#include "xbm/box.xbm" X#include "xbm/oval.xbm" X#include "xbm/poly.xbm" X#include "xbm/polygon.xbm" X#include "xbm/arc.xbm" X#include "xbm/rcbox.xbm" X X#include "xbm/pat0.xbm" X#include "xbm/pat1.xbm" X#include "xbm/pat2.xbm" X#include "xbm/pat3.xbm" X#include "xbm/pat4.xbm" X#include "xbm/pat5.xbm" X#include "xbm/pat6.xbm" X#include "xbm/pat7.xbm" X#include "xbm/pat8.xbm" X#include "xbm/pat9.xbm" X#include "xbm/pat10.xbm" X#include "xbm/pat11.xbm" X#include "xbm/pat12.xbm" X#include "xbm/pat13.xbm" X#include "xbm/pat14.xbm" X#include "xbm/pat15.xbm" X#include "xbm/pat16.xbm" X#include "xbm/pat17.xbm" X#include "xbm/pat18.xbm" X#include "xbm/pat19.xbm" X#include "xbm/pat20.xbm" X X#include "xbm/just_l.xbm" X#include "xbm/just_c.xbm" X#include "xbm/just_r.xbm" X X#include "xbm/align_n.xbm" X X#include "xbm/align_l.xbm" X#include "xbm/align_c.xbm" X#include "xbm/align_r.xbm" X X#include "xbm/align_t.xbm" X#include "xbm/align_m.xbm" X#include "xbm/align_b.xbm" X X#include "xbm/lw0.xbm" X#include "xbm/lw1.xbm" X#include "xbm/lw2.xbm" X#include "xbm/lw3.xbm" X#include "xbm/lw4.xbm" X#include "xbm/lw5.xbm" X#include "xbm/lw6.xbm" X X#include "xbm/lt0.xbm" X#include "xbm/lt1.xbm" X X#include "xbm/ls0.xbm" X#include "xbm/ls1.xbm" X#include "xbm/ls2.xbm" X#include "xbm/ls3.xbm" X X#include "xbm/ld0.xbm" X#include "xbm/ld1.xbm" X#include "xbm/ld2.xbm" X#include "xbm/ld3.xbm" X#include "xbm/ld4.xbm" X X#include "xbm/lw0s.xbm" X#include "xbm/lw1s.xbm" X#include "xbm/lw2s.xbm" X#include "xbm/lw3s.xbm" X#include "xbm/lw4s.xbm" X#include "xbm/lw5s.xbm" X#include "xbm/lw6s.xbm" X X#include "xbm/lt0s.xbm" X#include "xbm/lt1s.xbm" X X#include "xbm/ls0s.xbm" X#include "xbm/ls1s.xbm" X#include "xbm/ls2s.xbm" X#include "xbm/ls3s.xbm" X X#include "xbm/ld0s.xbm" X#include "xbm/ld1s.xbm" X#include "xbm/ld2s.xbm" X#include "xbm/ld3s.xbm" X#include "xbm/ld4s.xbm" X X#include "xbm/printer.xbm" X#include "xbm/latex.xbm" X#include "xbm/psfile.xbm" X#include "xbm/xbm.xbm" X X#include "xbm/file.xbm" X#include "xbm/special.xbm" X X#include "xbm/rotate_0.xbm" X#include "xbm/rotate_90.xbm" X#include "xbm/rotate_180.xbm" X#include "xbm/rotate_270.xbm" X XGC rasterGC; X XPixmap patPixmap[MAXPATTERNS+1]; XGC patGC; X XGC drawGC = NULL; XGC defaultGC; XGC revDefaultGC; X XPixmap choicePixmap[MAXCHOICES]; XPixmap lineWidthPixmap[MAXLINEWIDTHS]; XPixmap lineTypePixmap[MAXLINETYPES]; XPixmap dashPixmap[MAXDASHES]; XPixmap lineStylePixmap[MAXLINEWIDTHS+MAXLINETYPES+MAXDASHES+MAXLINESTYLES]; XPixmap justPixmap[MAXJUSTS]; XPixmap alignHoriPixmap[MAXALIGNS]; XPixmap alignVertPixmap[MAXALIGNS]; XPixmap shortLineWidthPixmap[MAXLINEWIDTHS]; XPixmap filePixmap; XPixmap specialPixmap; XPixmap rotatePixmap[4]; XPixmap whereToPrintPixmap[MAXWHERETOPRINT]; XPixmap shortLineTypePixmap[MAXLINETYPES]; XPixmap shortLineStylePixmap[MAXLINESTYLES]; XPixmap shortDashPixmap[MAXDASHES]; X Xint pat_w[MAXPATTERNS+1], pat_h[MAXPATTERNS+1]; Xint dashListLength[MAXDASHES] = { 0, 2, 2, 2, 4 }; Xchar * dashList[MAXDASHES] = X {"","\004\014","\010\010","\014\004","\024\004\004\004"}; X Xstatic char * patData[MAXPATTERNS+1]; X Xvoid InitPattern () X{ X register int i; X XGCValues values; X X values.foreground = myFgPixel; X values.background = myBgPixel; X values.fill_style = FillOpaqueStippled; X X rasterGC = XCreateGC (mainDisplay, mainWindow, X GCForeground | GCBackground | GCFillStyle, &values); X X values.fill_style = FillOpaqueStippled; X patGC = XCreateGC (mainDisplay, mainWindow, X GCForeground | GCBackground | GCFillStyle, &values); X X values.join_style = JoinBevel; X values.background = myBgPixel; X drawGC = XCreateGC (mainDisplay, mainWindow, X GCBackground | GCJoinStyle, &values); X X values.font = defaultFontPtr->fid; X defaultGC = XCreateGC (mainDisplay, mainWindow, X GCForeground | GCBackground | GCFont, &values); X X values.foreground = 1; X values.background = 0; X values.function = GXxor; X revDefaultGC = XCreateGC (mainDisplay, mainWindow, X GCForeground | GCBackground | GCFunction, &values); X X pat_w[0] = pat0_width; pat_h[0] = pat0_height; patData[0] = pat0_bits; X pat_w[1] = pat1_width; pat_h[1] = pat1_height; patData[1] = pat1_bits; X pat_w[2] = pat2_width; pat_h[2] = pat2_height; patData[2] = pat2_bits; X pat_w[3] = pat3_width; pat_h[3] = pat3_height; patData[3] = pat3_bits; X pat_w[4] = pat4_width; pat_h[4] = pat4_height; patData[4] = pat4_bits; X pat_w[5] = pat5_width; pat_h[5] = pat5_height; patData[5] = pat5_bits; X pat_w[6] = pat6_width; pat_h[6] = pat6_height; patData[6] = pat6_bits; X pat_w[7] = pat7_width; pat_h[7] = pat7_height; patData[7] = pat7_bits; X pat_w[8] = pat8_width; pat_h[8] = pat8_height; patData[8] = pat8_bits; X pat_w[9] = pat9_width; pat_h[9] = pat9_height; patData[9] = pat9_bits; X pat_w[10] = pat10_width; pat_h[10] = pat10_height; patData[10] = pat10_bits; X pat_w[11] = pat11_width; pat_h[11] = pat11_height; patData[11] = pat11_bits; X pat_w[12] = pat12_width; pat_h[12] = pat12_height; patData[12] = pat12_bits; X pat_w[13] = pat13_width; pat_h[13] = pat13_height; patData[13] = pat13_bits; X pat_w[14] = pat14_width; pat_h[14] = pat14_height; patData[14] = pat14_bits; X pat_w[15] = pat15_width; pat_h[15] = pat15_height; patData[15] = pat15_bits; X pat_w[16] = pat16_width; pat_h[16] = pat16_height; patData[16] = pat16_bits; X pat_w[17] = pat17_width; pat_h[17] = pat17_height; patData[17] = pat17_bits; X pat_w[18] = pat18_width; pat_h[18] = pat18_height; patData[18] = pat18_bits; X pat_w[19] = pat19_width; pat_h[19] = pat19_height; patData[19] = pat19_bits; X pat_w[20] = pat20_width; pat_h[20] = pat20_height; patData[20] = pat20_bits; X X for (i = 0; i < MAXPATTERNS+1; i++) X patPixmap[i] = XCreateBitmapFromData (mainDisplay, mainWindow, X patData[i], pat_w[i], pat_h[i]); X X justPixmap[JUST_L] = XCreateBitmapFromData (mainDisplay, mainWindow, X just_l_bits, just_l_width, just_l_height); X justPixmap[JUST_C] = XCreateBitmapFromData (mainDisplay, mainWindow, X just_c_bits, just_c_width, just_c_height); X justPixmap[JUST_R] = XCreateBitmapFromData (mainDisplay, mainWindow, X just_r_bits, just_r_width, just_r_height); X X alignHoriPixmap[ALIGN_N] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_n_bits, align_n_width, align_n_height); X alignHoriPixmap[ALIGN_L] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_l_bits, align_l_width, align_l_height); X alignHoriPixmap[ALIGN_C] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_c_bits, align_c_width, align_c_height); X alignHoriPixmap[ALIGN_R] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_r_bits, align_r_width, align_r_height); X X alignVertPixmap[ALIGN_N] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_n_bits, align_n_width, align_n_height); X alignVertPixmap[ALIGN_T] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_t_bits, align_t_width, align_t_height); X alignVertPixmap[ALIGN_M] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_m_bits, align_m_width, align_m_height); X alignVertPixmap[ALIGN_B] = XCreateBitmapFromData (mainDisplay, mainWindow, X align_b_bits, align_b_width, align_b_height); X X lineWidthPixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw0_bits, lw0_width, lw0_height); X lineWidthPixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw1_bits, lw1_width, lw1_height); X lineWidthPixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw2_bits, lw2_width, lw2_height); X lineWidthPixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw3_bits, lw3_width, lw3_height); X lineWidthPixmap[4] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw4_bits, lw4_width, lw4_height); X lineWidthPixmap[5] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw5_bits, lw5_width, lw5_height); X lineWidthPixmap[6] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw6_bits, lw6_width, lw6_height); X X lineTypePixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X lt0_bits, lt0_width, lt0_height); X lineTypePixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X lt1_bits, lt1_width, lt1_height); X X dashPixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld0_bits, ld0_width, ld0_height); X dashPixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld1_bits, ld1_width, ld1_height); X dashPixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld2_bits, ld2_width, ld2_height); X dashPixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld3_bits, ld3_width, ld3_height); X dashPixmap[4] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld4_bits, ld4_width, ld4_height); X X lineStylePixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw0_bits, lw0_width, lw0_height); X lineStylePixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw1_bits, lw1_width, lw1_height); X lineStylePixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw2_bits, lw2_width, lw2_height); X lineStylePixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw3_bits, lw3_width, lw3_height); X lineStylePixmap[4] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw4_bits, lw4_width, lw4_height); X lineStylePixmap[5] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw5_bits, lw5_width, lw5_height); X lineStylePixmap[6] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw6_bits, lw6_width, lw6_height); X X lineStylePixmap[7] = XCreateBitmapFromData (mainDisplay, mainWindow, X lt0_bits, lt0_width, lt0_height); X lineStylePixmap[8] = XCreateBitmapFromData (mainDisplay, mainWindow, X lt1_bits, lt1_width, lt1_height); X X lineStylePixmap[9] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld0_bits, ld0_width, ld0_height); X lineStylePixmap[10] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld1_bits, ld1_width, ld1_height); X lineStylePixmap[11] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld2_bits, ld2_width, ld2_height); X lineStylePixmap[12] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld3_bits, ld3_width, ld3_height); X lineStylePixmap[13] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld4_bits, ld4_width, ld4_height); X X lineStylePixmap[14] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls0_bits, ls0_width, ls0_height); X lineStylePixmap[15] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls1_bits, ls1_width, ls1_height); X lineStylePixmap[16] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls2_bits, ls2_width, ls2_height); X lineStylePixmap[17] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls3_bits, ls3_width, ls3_height); X X shortLineStylePixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls0s_bits, ls0s_width, ls0s_height); X shortLineStylePixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls1s_bits, ls1s_width, ls1s_height); X shortLineStylePixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls2s_bits, ls2s_width, ls2s_height); X shortLineStylePixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X ls3s_bits, ls3s_width, ls3s_height); X X filePixmap = XCreateBitmapFromData (mainDisplay, mainWindow, X file_bits, file_width, file_height); X X specialPixmap = XCreateBitmapFromData (mainDisplay, mainWindow, X special_bits, special_width, special_height); X X rotatePixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X rotate_0_bits, rotate_0_width, rotate_0_height); X rotatePixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X rotate_90_bits, rotate_90_width, rotate_90_height); X rotatePixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X rotate_180_bits, rotate_180_width, rotate_180_height); X rotatePixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X rotate_270_bits, rotate_270_width, rotate_270_height); X X whereToPrintPixmap[PRINTER] = XCreateBitmapFromData (mainDisplay, mainWindow, X printer_bits, printer_width, printer_height); X whereToPrintPixmap[LATEX_FIG] = XCreateBitmapFromData (mainDisplay, X mainWindow, latex_bits, latex_width, latex_height); X whereToPrintPixmap[PS_FILE] = XCreateBitmapFromData (mainDisplay, X mainWindow, psfile_bits, psfile_width, psfile_height); X whereToPrintPixmap[XBM_FILE] = XCreateBitmapFromData (mainDisplay, X mainWindow, xbm_bits, xbm_width, xbm_height); X X shortLineTypePixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X lt0s_bits, lt0s_width, lt0s_height); X shortLineTypePixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X lt1s_bits, lt1s_width, lt1s_height); X X shortDashPixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld0s_bits, ld0s_width, ld0s_height); X shortDashPixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld1s_bits, ld1s_width, ld1s_height); X shortDashPixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld2s_bits, ld2s_width, ld2s_height); X shortDashPixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld3s_bits, ld3s_width, ld3s_height); X shortDashPixmap[4] = XCreateBitmapFromData (mainDisplay, mainWindow, X ld4s_bits, ld4s_width, ld4s_height); X X shortLineWidthPixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw0s_bits, lw0s_width, lw0s_height); X shortLineWidthPixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw1s_bits, lw1s_width, lw1s_height); X shortLineWidthPixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw2s_bits, lw2s_width, lw2s_height); X shortLineWidthPixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw3s_bits, lw3s_width, lw3s_height); X shortLineWidthPixmap[4] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw4s_bits, lw4s_width, lw4s_height); X shortLineWidthPixmap[5] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw5s_bits, lw5s_width, lw5s_height); X shortLineWidthPixmap[6] = XCreateBitmapFromData (mainDisplay, mainWindow, X lw6s_bits, lw6s_width, lw6s_height); X X choicePixmap[0] = XCreateBitmapFromData (mainDisplay, mainWindow, X arrow_bits, arrow_width, arrow_height); X choicePixmap[1] = XCreateBitmapFromData (mainDisplay, mainWindow, X text_bits, text_width, text_height); X choicePixmap[2] = XCreateBitmapFromData (mainDisplay, mainWindow, X box_bits, box_width, box_height); X choicePixmap[3] = XCreateBitmapFromData (mainDisplay, mainWindow, X oval_bits, oval_width, oval_height); X choicePixmap[4] = XCreateBitmapFromData (mainDisplay, mainWindow, X poly_bits, poly_width, poly_height); X choicePixmap[5] = XCreateBitmapFromData (mainDisplay, mainWindow, X polygon_bits, polygon_width, polygon_height); X choicePixmap[6] = XCreateBitmapFromData (mainDisplay, mainWindow, X arc_bits, arc_width, arc_height); X choicePixmap[7] = XCreateBitmapFromData (mainDisplay, mainWindow, X rcbox_bits, rcbox_width, rcbox_height); X} X Xvoid RedrawChoiceWindow () X{ X ShowMode (); X ShowColor (FALSE); X ShowHoriAlign (); X ShowVertAlign (); X ShowJust (); X ShowCurFont (); X ShowRotate (); X ShowSpecial (); X ShowLineWidth (); X ShowLineStyle (); X ShowLineType (); X ShowDash (); X ShowWhereToPrint (); X ShowFile (); X ShowFill (); X ShowPen (); X} X Xvoid CleanUpRasters () X{ X register int i; X X for (i = 0; i < MAXCHOICES; i++) XFreePixmap (mainDisplay, choicePixmap[i]); X for (i = 0; i < MAXPATTERNS+1; i++) XFreePixmap (mainDisplay, patPixmap[i]); X for (i = 0; i < MAXLINEWIDTHS; i++) X XFreePixmap (mainDisplay, lineWidthPixmap[i]); X for (i = 0; i < MAXLINEWIDTHS+MAXLINETYPES+MAXLINESTYLES; i++) X XFreePixmap (mainDisplay, lineStylePixmap[i]); X for (i = 0; i < MAXLINETYPES; i++) X XFreePixmap (mainDisplay, lineTypePixmap[i]); X for (i = 0; i < MAXDASHES; i++) X XFreePixmap (mainDisplay, dashPixmap[i]); X for (i = 0; i < MAXJUSTS; i++) XFreePixmap (mainDisplay, justPixmap[i]); X XFreePixmap (mainDisplay, alignHoriPixmap[0]); X for (i = 1; i < MAXALIGNS; i++) X XFreePixmap (mainDisplay, alignHoriPixmap[i]); X for (i = 1; i < MAXALIGNS; i++) X XFreePixmap (mainDisplay, alignVertPixmap[i]); X for (i = 0; i < MAXLINEWIDTHS; i++) X XFreePixmap (mainDisplay, shortLineWidthPixmap[i]); X XFreePixmap (mainDisplay, filePixmap); X XFreePixmap (mainDisplay, specialPixmap); X for (i = 0; i < 4; i++) X XFreePixmap (mainDisplay, rotatePixmap[i]); X for (i = 0; i < MAXWHERETOPRINT; i++) X XFreePixmap (mainDisplay, whereToPrintPixmap[i]); X for (i = 0; i < MAXLINETYPES; i++) X XFreePixmap (mainDisplay, shortLineTypePixmap[i]); X for (i = 0; i < MAXLINESTYLES; i++) X XFreePixmap (mainDisplay, shortLineStylePixmap[i]); X for (i = 0; i < MAXDASHES; i++) X XFreePixmap (mainDisplay, shortDashPixmap[i]); X X XFreeGC (mainDisplay, rasterGC); X XFreeGC (mainDisplay, patGC); X XFreeGC (mainDisplay, drawGC); drawGC = NULL; X XFreeGC (mainDisplay, defaultGC); X XFreeGC (mainDisplay, revDefaultGC); X} END_OF_FILE if test 17765 -ne `wc -c <'raster.c'`; then echo shar: \"'raster.c'\" unpacked with wrong size! fi # end of 'raster.c' fi if test -f 'rcbox.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'rcbox.c'\" else echo shar: Extracting \"'rcbox.c'\" \(15782 characters\) sed "s/^X//" >'rcbox.c' <<'END_OF_FILE' X/* X * Author: William Chia-Wei Cheng (william@cs.ucla.edu) X * X * Copyright (C) 1990, 1991, William Cheng. X */ X#ifndef lint Xstatic char RCSid[] = X "@(#)$Header: /tmp_mnt/n/kona/tangram/u/william/X11/TGIF2/RCS/rcbox.c,v 2.0 91/03/05 12:48:08 william Exp $"; X#endif X X#include <stdio.h> X#include <X11/Xlib.h> X#include "const.h" X#include "types.h" X X#include "color.e" X#include "cursor.e" X#include "file.e" X#include "grid.e" X#include "obj.e" X#include "pattern.e" X#include "poly.e" X#include "raster.e" X#include "ruler.e" X#include "setup.e" X X#define RC_DEF_R (EIGHTH_INCH) X Xint rcBoxDrawn = FALSE; X Xstatic XSegment rcbSegs[4]; Xstatic XArc rcbArcs[4]; Xstatic int rcbArcsInitialized = FALSE; X Xvoid SetRCBoxVertex (x1, y1, x2, y2, r) X int x1, y1, x2, y2, r; X{ X register int inc_x, inc_y, d=2*r; X X inc_x = (x2 > x1); X inc_y = (y2 > y1); X rcbSegs[0].x1 = (inc_x) ? (x1+r) : (x1-r); rcbSegs[0].y1 = y1; X rcbSegs[0].x2 = (inc_x) ? (x2-r) : (x2+r); rcbSegs[0].y2 = y1; X rcbSegs[1].x1 = x2; rcbSegs[1].y1 = (inc_y) ? (y1+r) : (y1-r); X rcbSegs[1].x2 = x2; rcbSegs[1].y2 = (inc_y) ? (y2-r) : (y2+r); X rcbSegs[2].x1 = (inc_x) ? (x1+r) : (x1-r); rcbSegs[2].y1 = y2; X rcbSegs[2].x2 = (inc_x) ? (x2-r) : (x2+r); rcbSegs[2].y2 = y2; X rcbSegs[3].x1 = x1; rcbSegs[3].y1 = (inc_y) ? (y1+r) : (y1-r); X rcbSegs[3].x2 = x1; rcbSegs[3].y2 = (inc_y) ? (y2-r) : (y2+r); X X if (!rcbArcsInitialized) X { X rcbArcsInitialized = TRUE; X X rcbArcs[0].angle1 = 90*64; rcbArcs[0].angle2 = 90*64; X rcbArcs[1].angle1 = 0; rcbArcs[1].angle2 = 90*64; X rcbArcs[2].angle1 = -90*64; rcbArcs[2].angle2 = 90*64; X rcbArcs[3].angle1 = -180*64; rcbArcs[3].angle2 = 90*64; X } X rcbArcs[0].width=rcbArcs[1].width=rcbArcs[2].width=rcbArcs[3].width=d; X rcbArcs[0].height=rcbArcs[1].height=rcbArcs[2].height=rcbArcs[3].height=d; X X if (inc_x) X { X if (inc_y) X { X rcbArcs[0].x=x1; rcbArcs[0].y=y1; X rcbArcs[1].x=x2-d; rcbArcs[1].y=y1; X rcbArcs[2].x=x2-d; rcbArcs[2].y=y2-d; X rcbArcs[3].x=x1; rcbArcs[3].y=y2-d; X } X else X { X rcbArcs[0].x=x1; rcbArcs[0].y=y2; X rcbArcs[1].x=x2-d; rcbArcs[1].y=y2; X rcbArcs[2].x=x2-d; rcbArcs[2].y=y1-d; X rcbArcs[3].x=x1; rcbArcs[3].y=y1-d; X } X } X else X { X if (inc_y) X { X rcbArcs[0].x=x2; rcbArcs[0].y=y1; X rcbArcs[1].x=x1-d; rcbArcs[1].y=y1; X rcbArcs[2].x=x1-d; rcbArcs[2].y=y2-d; X rcbArcs[3].x=x2; rcbArcs[3].y=y2-d; X } X else X { X rcbArcs[0].x=x2; rcbArcs[0].y=y2; X rcbArcs[1].x=x1-d; rcbArcs[1].y=y2; X rcbArcs[2].x=x1-d; rcbArcs[2].y=y1-d; X rcbArcs[3].x=x2; rcbArcs[3].y=y1-d; X } X } X} X Xvoid MyRCBox (window, gc, x1, y1, x2, y2, r) X Window window; X GC gc; X int x1, y1, x2, y2, r; X{ X if (abs(x1-x2) < 2*r || abs(y1-y2) < 2*r) X MyBox (window, gc, x1, y1, x2, y2); X else X { X XDrawSegments (mainDisplay, window, gc, rcbSegs, 4); X XDrawArcs (mainDisplay, window, gc, rcbArcs, 4); X } X} X Xstatic Xvoid MyFillRCBox (window, gc, x1, y1, x2, y2, r) X Window window; X GC gc; X int x1, y1, x2, y2, r; X{ X if (abs(x1-x2) < 2*r || abs(y1-y2) < 2*r) X XFillRectangle (mainDisplay, window, gc, x1, y1, x2-x1, y2-y1); X else X { X XFillRectangle (mainDisplay, window, gc, x1+r, y1, x2-x1-2*r, y2-y1); X XFillRectangle (mainDisplay, window, gc, x1, y1+r, x2-x1, y2-y1-2*r); X XFillArcs (mainDisplay, window, gc, rcbArcs, 4); X } X} X Xstatic Xvoid DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, blank1, blank2) X FILE * FP; X int ltx, lty, rbx, rby, r; X char * blank1, * blank2; X{ X if (abs(ltx-rbx) < 2*r || abs(lty-rby) < 2*r) X { X fprintf (FP, "%snewpath\n%s%1d %1d moveto\n", blank1, blank2, rbx, lty); X fprintf (FP, "%s%1d %1d lineto\n", blank2, rbx, rby); X fprintf (FP, "%s%1d %1d lineto\n", blank2, ltx, rby); X fprintf (FP, "%s%1d %1d lineto\n", blank2, ltx, lty); X } X else X { X fprintf (FP, "%snewpath\n%s%1d %1d moveto\n", blank1, blank2, rbx-r, lty); X fprintf (FP, "%s%1d %1d %1d %1d %1d arcto 4 {pop} repeat\n", blank2, X rbx, lty, rbx, rby, r); X fprintf (FP, "%s%1d %1d lineto\n", blank2, rbx, rby-r); X fprintf (FP, "%s%1d %1d %1d %1d %1d arcto 4 {pop} repeat\n", blank2, X rbx, rby, ltx, rby, r); X fprintf (FP, "%s%1d %1d lineto\n", blank2, ltx+r, rby); X fprintf (FP, "%s%1d %1d %1d %1d %1d arcto 4 {pop} repeat\n", blank2, X ltx, rby, ltx, lty, r); X fprintf (FP, "%s%1d %1d lineto\n", blank2, ltx, lty+r); X fprintf (FP, "%s%1d %1d %1d %1d %1d arcto 4 {pop} repeat\n", blank2, X ltx, lty, rbx, lty, r); X } X} X Xvoid DumpRCBoxObj (FP, ObjPtr) X FILE * FP; X struct ObjRec * ObjPtr; X{ X register int ltx, lty, rbx, rby, i; X int fill, width, pen, dash, color_index, r; X X ltx = ObjPtr->obbox.ltx; X lty = ObjPtr->obbox.lty; X rbx = ObjPtr->obbox.rbx; X rby = ObjPtr->obbox.rby; X X fill = ObjPtr->detail.rcb->fill; X pen = ObjPtr->detail.rcb->pen; X width = ObjPtr->detail.rcb->width; X dash = ObjPtr->detail.rcb->dash; X r = ObjPtr->detail.rcb->radius; X X if (fill == NONEPAT && pen == NONEPAT) return; X X color_index = ObjPtr->color; X if (colorDump) X fprintf (FP, "%.3f %.3f %.3f setrgbcolor\n", X ((float)tgifColors[color_index].red/maxRGB), X ((float)tgifColors[color_index].green/maxRGB), X ((float)tgifColors[color_index].blue/maxRGB)); X X switch (fill) X { X case NONEPAT: break; X case SOLIDPAT: X DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, "", " "); X fprintf (FP, "closepath fill\n"); X break; X case BACKPAT: X DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, "", " "); X fprintf (FP, "closepath 1 setgray fill\n"); X if (colorDump) X fprintf (FP, "%.3f %.3f %.3f setrgbcolor\n", X ((float)tgifColors[color_index].red/maxRGB), X ((float)tgifColors[color_index].green/maxRGB), X ((float)tgifColors[color_index].blue/maxRGB)); X else X fprintf (FP, "0 setgray\n"); X break; X default: X fprintf (FP, "gsave\n"); X if (!colorDump) X fprintf (FP, " pat%1d 8 1 0 72 300 32 div div setpattern\n",fill); X DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, " ", " "); X if (colorDump) X { X fprintf (FP, " closepath eoclip\n"); X DumpPatFill (FP, fill, 8, ObjPtr->bbox, " "); X } X else X fprintf (FP, " closepath fill\n"); X fprintf (FP, "grestore\n"); X break; X } X X fprintf (FP, "%1d setlinewidth\n", widthOfLine[width]); X if (dash != 0) X { X fprintf (FP, "["); X for (i = 0; i < dashListLength[dash]-1; i++) X fprintf (FP, "%1d ", (int)(dashList[dash][i])); X fprintf (FP, "%1d] 0 setdash\n", X (int)(dashList[dash][dashListLength[dash]-1])); X } X X switch (pen) X { X case NONEPAT: break; X case SOLIDPAT: X DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, "", " "); X fprintf (FP, "closepath stroke\n"); X break; X case BACKPAT: X DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, "", " "); X fprintf (FP, "closepath 1 setgray stroke 0 setgray\n"); X break; X default: X fprintf (FP, "gsave\n"); X if (!colorDump) X fprintf (FP, " pat%1d 8 1 0 72 300 32 div div setpattern\n", pen); X DumpRCBoxPSPath (FP, ltx, lty, rbx, rby, r, " ", " "); X if (colorDump) X { X fprintf (FP, " closepath strokepath clip\n"); X DumpPatFill (FP, pen, 8, ObjPtr->bbox, " "); X } X else X fprintf (FP, " closepath stroke\n"); X fprintf (FP, "grestore\n"); X break; X } X if (dash != 0) fprintf (FP, "[] 0 setdash\n"); X fprintf (FP, "1 setlinewidth\n\n"); X} X Xvoid DrawRCBoxObj (win, XOff, YOff, ObjPtr) X Window win; X struct ObjRec * ObjPtr; X{ X struct RCBoxRec * rcbox_ptr = ObjPtr->detail.rcb; X int fill, pen, pixel, func, ltx, lty, rbx, rby, width, dash; X int real_x_off, real_y_off, radius; X XGCValues values; X X pen = rcbox_ptr->pen; X fill = rcbox_ptr->fill; X width = rcbox_ptr->width; X dash = rcbox_ptr->dash; X radius = rcbox_ptr->radius; X pixel = colorPixels[ObjPtr->color]; X X if (fill == 0 && pen == 0) return; X X real_x_off = (XOff >> zoomScale) << zoomScale; X real_y_off = (YOff >> zoomScale) << zoomScale; X ltx = (ObjPtr->obbox.ltx - real_x_off) >> zoomScale; X lty = (ObjPtr->obbox.lty - real_y_off) >> zoomScale; X rbx = (ObjPtr->obbox.rbx - real_x_off) >> zoomScale; X rby = (ObjPtr->obbox.rby - real_y_off) >> zoomScale; X func = GXcopy; X X SetRCBoxVertex (ltx, lty, rbx, rby, radius); X X if (fill != 0) X { X values.foreground = (fill == 2) ? myBgPixel : pixel; X values.function = GXcopy; X values.fill_style = FillOpaqueStippled; X values.stipple = patPixmap[fill]; X XChangeGC (mainDisplay, drawGC, X GCForeground | GCFunction | GCFillStyle | GCStipple, &values); X MyFillRCBox (win, drawGC, ltx, lty, rbx, rby, radius); X } X X if (pen != 0) X { X values.foreground = (pen == 2) ? myBgPixel : pixel; X values.function = GXcopy; X values.fill_style = FillOpaqueStippled; X values.stipple = patPixmap[pen]; X values.line_width = widthOfLine[width] >> zoomScale; X if (dash != 0) X { X XSetDashes (mainDisplay, drawGC, 0, dashList[dash], X dashListLength[dash]); X values.line_style = LineOnOffDash; X } X else X values.line_style = LineSolid; X XChangeGC (mainDisplay, drawGC, X GCForeground | GCFunction | GCFillStyle | GCStipple | GCLineWidth | X GCLineStyle, &values); X MyRCBox (win, drawGC, ltx, lty, rbx, rby, radius); X } X} X Xstatic Xvoid CreateRCBoxObj (X1, Y1, X2, Y2) X int X1, Y1, X2, Y2; X{ X struct RCBoxRec * rcbox_ptr; X struct ObjRec * obj_ptr; X int w, ltx, lty, rbx, rby; X X rcbox_ptr = (struct RCBoxRec *) calloc (1, sizeof(struct RCBoxRec)); X rcbox_ptr->fill = objFill; X rcbox_ptr->width = lineWidth; X rcbox_ptr->pen = penPat; X rcbox_ptr->dash = curDash; X rcbox_ptr->radius = RC_DEF_R; X X obj_ptr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec)); X X if (X1 < X2) X if (Y1 < Y2) X { X ltx = X1; lty = Y1; rbx = X2; rby = Y2; X } X else X { X ltx = X1; lty = Y2; rbx = X2; rby = Y1; X } X else X if (Y1 < Y2) X { X ltx = X2; lty = Y1; rbx = X1; rby = Y2; X } X else X { X ltx = X2; lty = Y2; rbx = X1; rby = Y1; X } X X obj_ptr->bbox.ltx = obj_ptr->obbox.ltx = obj_ptr->x = (ltx << zoomScale) + X drawOrigX; X obj_ptr->bbox.lty = obj_ptr->obbox.lty = obj_ptr->y = (lty << zoomScale) + X drawOrigY; X obj_ptr->bbox.rbx = obj_ptr->obbox.rbx = (rbx << zoomScale) + drawOrigX; X obj_ptr->bbox.rby = obj_ptr->obbox.rby = (rby << zoomScale) + drawOrigY; X w = widthOfLine[lineWidth]; X obj_ptr->bbox.ltx -= w; X obj_ptr->bbox.lty -= w; X obj_ptr->bbox.rbx += w; X obj_ptr->bbox.rby += w; X obj_ptr->type = OBJ_RCBOX; X obj_ptr->color = colorIndex; X obj_ptr->id = objId++; X obj_ptr->dirty = FALSE; X obj_ptr->detail.rcb = rcbox_ptr; X obj_ptr->fattr = obj_ptr->lattr = NULL; X AddObj (NULL, topObj, obj_ptr); X} X Xstatic Xvoid ContinueRCBox (OrigX, OrigY) X int OrigX, OrigY; X{ X int end_x, end_y, grid_x, grid_y, saved_x, saved_y; X int done = FALSE; X int pixel, xor_pixel; X XGCValues values; X XEvent input; X XMotionEvent * motion_ev; X X pixel = colorPixels[colorIndex]; X xor_pixel = xorColorPixels[colorIndex]; X X values.foreground = xor_pixel; X values.function = GXxor; X values.fill_style = FillSolid; X values.line_width = 0; X values.line_style = LineSolid; X X XChangeGC (mainDisplay, drawGC, X GCForeground | GCFunction | GCFillStyle | GCLineWidth | GCLineStyle, X &values); X X saved_x = grid_x = OrigX; X saved_y = grid_y = OrigY; X XGrabPointer (mainDisplay, drawWindow, FALSE, X PointerMotionMask | ButtonReleaseMask, X GrabModeAsync, GrabModeAsync, None, handCursor, CurrentTime); X X SetRCBoxVertex (OrigX, OrigY, saved_x, saved_y, RC_DEF_R); X while (!done) X { X XNextEvent (mainDisplay, &input); X if (input.type == ButtonRelease) X { X XUngrabPointer (mainDisplay, CurrentTime); X MyRCBox (drawWindow,drawGC,OrigX,OrigY,saved_x,saved_y,RC_DEF_R); X done = TRUE; X } X else if (input.type == MotionNotify) X { X motion_ev = &(input.xmotion); X end_x = motion_ev->x; X end_y = motion_ev->y; X GridXY (end_x, end_y, &grid_x, &grid_y); X if (grid_x != saved_x || grid_y != saved_y) X { X MyRCBox (drawWindow,drawGC,OrigX,OrigY,saved_x,saved_y,RC_DEF_R); X saved_x = grid_x; X saved_y = grid_y; X SetRCBoxVertex (OrigX, OrigY, saved_x, saved_y, RC_DEF_R); X MyRCBox (drawWindow,drawGC,OrigX,OrigY,saved_x,saved_y,RC_DEF_R); X } X MarkRulers (grid_x, grid_y); X } X } X if (OrigX != grid_x && OrigY != grid_y) X { X CreateRCBoxObj (OrigX, OrigY, grid_x, grid_y); X DrawRCBoxObj (drawWindow, drawOrigX, drawOrigY, topObj); X rcBoxDrawn = TRUE; X SetFileModified (TRUE); X } X} X Xvoid DrawRCBox (input) X XEvent * input; X{ X XButtonEvent * button_ev; X int mouse_x, mouse_y, grid_x, grid_y; X X if (input->type != ButtonPress) return; X X button_ev = &(input->xbutton); X if (button_ev->button == Button1) X { X mouse_x = button_ev->x; X mouse_y = button_ev->y; X GridXY (mouse_x, mouse_y, &grid_x, &grid_y); X ContinueRCBox (grid_x, grid_y); X } X} X Xvoid SaveRCBoxObj (FP, ObjPtr) X FILE * FP; X struct ObjRec * ObjPtr; X{ X fprintf (FP, "rcbox('%s',", colorMenuItems[ObjPtr->color]); X fprintf (FP, "%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,%1d,", ObjPtr->obbox.ltx, X ObjPtr->obbox.lty, ObjPtr->obbox.rbx, ObjPtr->obbox.rby, X ObjPtr->detail.rcb->fill, ObjPtr->detail.rcb->width, X ObjPtr->detail.rcb->pen, ObjPtr->detail.rcb->dash, X ObjPtr->detail.rcb->radius, ObjPtr->id); X SaveAttrs (FP, ObjPtr->lattr); X fprintf (FP, ")"); X} X Xvoid ReadRCBoxObj (Inbuf, ObjPtr) X char * Inbuf; X struct ObjRec * * ObjPtr; X{ X struct RCBoxRec * rcbox_ptr; X char color_str[20], * s; X int ltx, lty, rbx, rby, fill, width, pen, dash, w, radius; X X *ObjPtr = (struct ObjRec *) calloc (1, sizeof(struct ObjRec)); X s = FindChar ('(', Inbuf); X s = ParseStr (s, ',', color_str); X rcbox_ptr = (struct RCBoxRec *) calloc (1, sizeof(struct RCBoxRec)); X X if (fileVersion > 8) X { X sscanf (s, "%d , %d , %d , %d , %d , %d , %d , %d , %d , %d", X <x, <y, &rbx, &rby, &fill, &width, &pen, &dash, &radius, X &((*ObjPtr)->id)); X if ((*ObjPtr)->id >= objId) objId = (*ObjPtr)->id + 1; X } X X rcbox_ptr->fill = fill; X rcbox_ptr->width = width; X rcbox_ptr->pen = pen; X rcbox_ptr->dash = dash; X rcbox_ptr->radius = radius; X (*ObjPtr)->x = ltx; X (*ObjPtr)->y = lty; X (*ObjPtr)->color = FindColorIndex (color_str); X (*ObjPtr)->dirty = FALSE; X (*ObjPtr)->type = OBJ_RCBOX; X (*ObjPtr)->obbox.ltx = ltx; X (*ObjPtr)->obbox.lty = lty; X (*ObjPtr)->obbox.rbx = rbx; X (*ObjPtr)->obbox.rby = rby; X w = widthOfLine[width]; X (*ObjPtr)->bbox.ltx = ltx - w; X (*ObjPtr)->bbox.lty = lty - w; X (*ObjPtr)->bbox.rbx = rbx + w; X (*ObjPtr)->bbox.rby = rby + w; X (*ObjPtr)->detail.rcb = rcbox_ptr; X} X Xvoid FreeRCBoxObj (ObjPtr) X struct ObjRec * ObjPtr; X{ X cfree (ObjPtr->detail.rcb); X cfree (ObjPtr); X} END_OF_FILE if test 15782 -ne `wc -c <'rcbox.c'`; then echo shar: \"'rcbox.c'\" unpacked with wrong size! fi # end of 'rcbox.c' fi echo shar: End of archive 11 \(of 23\). 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 22 23 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 23 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 ---------------------------------> cut here <--------------------------------- -- Bill Cheng // UCLA Computer Science Department // (213) 206-7135 3277 Boelter Hall // Los Angeles, California 90024 // USA william@CS.UCLA.EDU ...!{uunet|ucbvax}!cs.ucla.edu!william -- Dan Heller ------------------------------------------------ O'Reilly && Associates Z-Code Software Senior Writer President argv@ora.com argv@zipcode.com ------------------------------------------------ General Email: argv@sun.com Comp-sources-x stuff: comp-sources.x@uunet.uu.net