|
|
1.1 root 1: /***********************************************************
2: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
3: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
4:
5: All Rights Reserved
6:
7: Permission to use, copy, modify, and distribute this software and its
8: documentation for any purpose and without fee is hereby granted,
9: provided that the above copyright notice appear in all copies and that
10: both that copyright notice and this permission notice appear in
11: supporting documentation, and that the names of Digital or MIT not be
12: used in advertising or publicity pertaining to distribution of the
13: software without specific, written prior permission.
14:
15: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21: SOFTWARE.
22:
23: ******************************************************************/
24: /* $Header: mizerline.c,v 1.3 87/09/11 07:20:38 toddb Exp $ */
25: #include "X.h"
26:
27: #include "misc.h"
28: #include "scrnintstr.h"
29: #include "gcstruct.h"
30: #include "windowstr.h"
31: #include "pixmap.h"
32:
33: int
34: miZeroLine(dst, pgc, mode, nptInit, pptInit)
35: DrawablePtr dst;
36: GCPtr pgc;
37: int mode;
38: int nptInit; /* number of points in polyline */
39: DDXPointRec *pptInit; /* points in the polyline */
40: {
41: int xorg, yorg;
42: DDXPointRec *ppt;
43: int npt;
44:
45: DDXPointRec pt1, pt2;
46: int dx, dy;
47: int adx, ady;
48: int signdx, signdy;
49: register int len;
50:
51: int du, dv;
52: register int e, e1, e2;
53:
54: register int x,y; /* current point on the line */
55: int i; /* traditional name for loop counter */
56:
57: ppt = pptInit;
58: npt = nptInit;
59: if (pgc->miTranslate)
60: {
61: if (dst->type == DRAWABLE_WINDOW)
62: {
63: xorg = ((WindowPtr)dst)->absCorner.x;
64: yorg = ((WindowPtr)dst)->absCorner.y;
65: }
66: else
67: {
68: xorg = 0;
69: yorg = 0;
70: }
71:
72: if (mode == CoordModeOrigin)
73: {
74: for (i = 0; i<npt; i++)
75: {
76: ppt->x += xorg;
77: ppt++->y += yorg;
78: }
79: }
80: else
81: {
82: ppt->x += xorg;
83: ppt++->y += yorg;
84: for (i = 1; i<npt; i++)
85: {
86: ppt->x += (ppt-1)->x;
87: ppt->y += (ppt-1)->y;
88: ppt++;
89: }
90: }
91: }
92: else
93: {
94: if (mode == CoordModePrevious)
95: {
96: ppt++;
97: for (i = 1; i<npt; i++)
98: {
99: ppt->x += (ppt-1)->x;
100: ppt->y += (ppt-1)->y;
101: ppt++;
102: }
103: }
104: }
105:
106: ppt = pptInit;
107: npt = nptInit;
108: while (--npt)
109: {
110:
111: DDXPointPtr pspan;
112: DDXPointPtr pspanInit;
113: int *pwidth;
114: int *pwidthInit;
115: int width;
116:
117: pt1 = *ppt++;
118: pt2 = *ppt;
119: dx = pt2.x - pt1.x;
120: dy = pt2.y - pt1.y;
121: adx = abs(dx);
122: ady = abs(dy);
123: signdx = sign(dx);
124: signdy = sign(dy);
125:
126: if (adx > ady)
127: {
128: du = adx;
129: dv = ady;
130: len = adx;
131: }
132: else
133: {
134: du = ady;
135: dv = adx;
136: len = ady;
137: }
138:
139: e1 = dv * 2;
140: e2 = e1 - 2*du;
141: e = e1 - du;
142:
143: pspan = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * (ady+1));
144: pwidth = (int *)ALLOCATE_LOCAL(sizeof(int) * (ady+1));
145: pspanInit = pspan;
146: pwidthInit = pwidth;
147:
148: x = pt1.x;
149: y = pt1.y;
150: if (adx > ady)
151: {
152: /* X_AXIS */
153: width = 0;
154: *pspan = pt1;
155: while(len--)
156: {
157: if (((signdx > 0) && (e < 0)) ||
158: ((signdx <=0) && (e <=0))
159: )
160: {
161: e += e1;
162: x+= signdx;
163: width++;
164: }
165: else
166: {
167: /* give this span a width */
168: width++;
169: *pwidth++ = width;
170:
171: /* force the span the right way */
172: if (signdx < 0)
173: pspan->x -= (width-1);
174:
175: /* initialize next span */
176: x += signdx;
177: y += signdy;
178: e += e2;
179:
180: width = 0;
181: pspan++;
182: pspan->x = x;
183: pspan->y = y;
184:
185: }
186: };
187: /* do the last span */
188: *pwidth++ = width;
189: if (signdx < 0)
190: pspan->x -= (width-1);
191: }
192: else
193: {
194: /* Y_AXIS */
195: while(len--)
196: {
197: if (((signdx > 0) && (e < 0)) ||
198: ((signdx <=0) && (e <=0))
199: )
200: {
201: e +=e1;
202: }
203: else
204: {
205: x += signdx;
206: e += e2;
207: }
208: y += signdy;
209: pspan->x = x;
210: pspan++->y = y;
211: *pwidth++ = 1;
212: };
213: }
214:
215: (*pgc->FillSpans)(dst, pgc, pwidth-pwidthInit,
216: pspanInit, pwidthInit, FALSE);
217: DEALLOCATE_LOCAL(pspanInit);
218: DEALLOCATE_LOCAL(pwidthInit);
219: }
220:
221: if ((pgc->capStyle != CapNotLast) &&
222: ((ppt->x != pptInit->x) ||
223: (ppt->y != pptInit->y)))
224: {
225: int width = 1;
226: (*pgc->FillSpans)(dst, pgc, 1, ppt, &width, TRUE);
227: }
228: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.