aboutsummaryrefslogtreecommitdiff
path: root/POLYF.C
blob: a522d0b153b6e7e512cfb04d5011682e0e25cbcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*----------------------------------------------------------------------*/
/*  									*/
/*        polyf.c -- Filled Polygon drawing				*/
/*  									*/
/*----------------------------------------------------------------------*/

#include <system.h>
#include <prism.h>
#include <pnts.h>

#define local static
extern struct RastPort *curRP;
extern BOOL  goToPerm, symON, abortFlag;
extern void (*doit)(), (*xorit)(), (*nop)(), (*killMode)();
extern void FlipIt(), PaintSym(), obmv(), obclr(), vec(), EraseTempChg();
extern PointRec pnts;
extern Point bp;
extern SHORT butwas,usePen;
extern Box clipBox;
extern SHORT clipMaxX, clipMaxY;
extern SHORT xorg,yorg;
extern void (*completeMode)();

#define eraseFB EraseTempChg

local void dotmv() {mDrawDot(mx,my); }

local void chvec() {   mLine(pex,pey,mx,my); }

local void thinvec() {
    SHORT svusePen = usePen; usePen = 0; vec();
    usePen =svusePen; 
    }

local void thinChVec() {
    SHORT svusePen = usePen; usePen = 0; chvec();
    usePen =svusePen; 
    }


/* Filled Polygon ==========================================================*/

/*---------------Magnified Area Flood ------------*/
mFillPoly(points,np) Point *points; int np; {
    SHORT xmin,xmax,ymin,ymax,px,py;
    int i;
    Box b;
    xmin = xmax = points->x;
    ymin = ymax = points->y;
    UpdtON();
    ClipInit(clipBox.x,clipBox.y, clipMaxX, clipMaxY );
    ClipMove(curRP,points[np-1].x+xorg, points[np-1].y+yorg, bp.y);
    for (i=0; i<np; i++) {
	px = points->x;
	py = points->y;
	ClipDraw(curRP, px+xorg, py+yorg);
	xmin = MIN(xmin,px); xmax = MAX(xmax,px);
	ymin = MIN(ymin,py); ymax = MAX(ymax,py);
	points++;
	}
    ClipEnd(curRP);
    UpdtSibs(MakeBox(&b,xmin,ymin,xmax-xmin+1, ymax-ymin+1));
    UpdtOFF();
    }


#define MAXPOLPNTS  50

extern SHORT nPolPnts;
extern Point *polPnts;
extern struct AreaInfo areaInfo;
extern WORD *areaBuff;
    
void RecPnt(x,y) int x,y; {
    if (nPolPnts>=MAXPOLPNTS) return;
    polPnts[nPolPnts].x = x;
    polPnts[nPolPnts].y = y;
    nPolPnts++;
    }

FreePoly() { DFree(polPnts);  polPnts = NULL; DFree(areaBuff); 
	areaBuff = NULL; }
    
void killFPoly() {
    int i; 
    SHORT svusePen = usePen;
    usePen = 0;
    TempXOR();
    for (i=0; i<nPolPnts; i++) {
	mLine(bp.x,bp.y, polPnts[i].x, polPnts[i].y);
	bp.x = polPnts[i].x;
	bp.y = polPnts[i].y;
	}
    FreePoly();
    RestoreMode();
    usePen =svusePen; 
    }

local void drPoly() { mFillPoly(polPnts,nPolPnts);}

local void fpolyBup() {  
    if ((nPolPnts>1)&&(Distance(mx-bp.x,my-bp.y) < 3)) {
	goToPerm = YES;
	mx = bp.x; my = bp.y;
	RecPnt(mx,my);
	if (symON){
	    abortFlag = NO;
	    SymDo(nPolPnts, polPnts, drPoly);
	    CycPaint();
	    }
	else drPoly();
	FreePoly();
	}
    else {
	FlipIt();	/* display the current line */
	RecPnt(mx,my);  /* record the point */
	}
    } 

void complPoly() {
    mx = bp.x; my = bp.y;
    fpolyBup();
    }

XorMode(xorproc,down,up) void (*xorproc)(), (*down)(), (*up)(); {
    xorit = xorproc;
    IModeProcs(FlipIt,nop,FlipIt,down,FlipIt,nop,FlipIt, up);
    }
    
void IMFPoly2() {
    xorit = thinChVec;
    killMode = killFPoly;
    completeMode = complPoly;
    XorMode(thinChVec,nop,fpolyBup);
    }

local void markFStart() {
    bp.x = mx; bp.y = my; 
    RecPnt(mx,my);
    xorit = thinvec;
    }

void IMFPoly(restart) BOOL restart; {
    killMode = killFPoly;
    if (!restart) {
	polPnts = (Point *)ChipAlloc(MAXPOLPNTS*sizeof(Point));
	areaBuff = (WORD *)ChipAlloc(MAXPOLPNTS*5);
	nPolPnts = 0;
	InitArea(&areaInfo, areaBuff, MAXPOLPNTS);
	curRP->AreaInfo = &areaInfo;
	}
    XorMode(dotmv,markFStart,fpolyBup);
    }