| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: mqdraw.c,v 1.1 2003/02/22 02:07:26 greg Exp $";
|
| 3 |
#endif
|
| 4 |
/*
|
| 5 |
* Interface to MacIntosh QuickDraw routines
|
| 6 |
*
|
| 7 |
* 6/5/85
|
| 8 |
*/
|
| 9 |
|
| 10 |
|
| 11 |
#include "meta.h"
|
| 12 |
|
| 13 |
#include "macplot.h"
|
| 14 |
|
| 15 |
|
| 16 |
static short curpat = -1; /* current line drawing pattern */
|
| 17 |
|
| 18 |
static short curpsiz = -1; /* current pen size */
|
| 19 |
|
| 20 |
static short curpmod = -1; /* current pen mode */
|
| 21 |
|
| 22 |
static int xpos = -1, /* current position */
|
| 23 |
ypos = -1;
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
printstr(p) /* output a string */
|
| 28 |
|
| 29 |
register PRIMITIVE *p;
|
| 30 |
|
| 31 |
{
|
| 32 |
char *ctop(), *ptoc();
|
| 33 |
|
| 34 |
MoveTo(mapx(p->xy[XMN]), mapy(p->xy[YMN]));
|
| 35 |
DrawString(ctop(p->args));
|
| 36 |
ptoc(p->args);
|
| 37 |
xpos = -1;
|
| 38 |
ypos = -1;
|
| 39 |
|
| 40 |
}
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
plotlseg(p) /* plot a line segment */
|
| 47 |
|
| 48 |
register PRIMITIVE *p;
|
| 49 |
|
| 50 |
{
|
| 51 |
static short right = FALSE;
|
| 52 |
int x1, x2, y1, y2;
|
| 53 |
short pp, ps;
|
| 54 |
|
| 55 |
pp = (p->arg0 >> 4) & 03;
|
| 56 |
if (p->arg0 & 0100 && pp != 0)
|
| 57 |
pp += 03;
|
| 58 |
if (pp != curpat) {
|
| 59 |
PenPat(macpat[pp]);
|
| 60 |
curpat = pp;
|
| 61 |
}
|
| 62 |
|
| 63 |
ps = WIDTH((p->arg0 >> 2) & 03);
|
| 64 |
if (ps != curpsiz) {
|
| 65 |
PenSize(CONV(ps, dxsize) + 1, CONV(ps, dysize) + 1);
|
| 66 |
curpsiz = ps;
|
| 67 |
}
|
| 68 |
|
| 69 |
if (curpmod != patOr) {
|
| 70 |
PenMode(patOr);
|
| 71 |
curpmod = patOr;
|
| 72 |
}
|
| 73 |
|
| 74 |
x1 = mapx(p->xy[XMN]);
|
| 75 |
x2 = mapx(p->xy[XMX]);
|
| 76 |
|
| 77 |
if (p->arg0 & 0100) {
|
| 78 |
y1 = mapy(p->xy[YMX]);
|
| 79 |
y2 = mapy(p->xy[YMN]);
|
| 80 |
} else {
|
| 81 |
y1 = mapy(p->xy[YMN]);
|
| 82 |
y2 = mapy(p->xy[YMX]);
|
| 83 |
}
|
| 84 |
|
| 85 |
if (x1 == xpos && y1 == ypos) {
|
| 86 |
LineTo(x2, y2);
|
| 87 |
xpos = x2;
|
| 88 |
ypos = y2;
|
| 89 |
} else if (x2 == xpos && y2 == ypos) {
|
| 90 |
LineTo(x1, y1);
|
| 91 |
xpos = x1;
|
| 92 |
ypos = y1;
|
| 93 |
} else if (right = !right) {
|
| 94 |
MoveTo(x1, y1);
|
| 95 |
LineTo(x2, y2);
|
| 96 |
xpos = x2;
|
| 97 |
ypos = y2;
|
| 98 |
} else {
|
| 99 |
MoveTo(x2, y2);
|
| 100 |
LineTo(x1, y1);
|
| 101 |
xpos = x1;
|
| 102 |
ypos = y1;
|
| 103 |
}
|
| 104 |
|
| 105 |
}
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
setfill(a0) /* set filling mode */
|
| 111 |
|
| 112 |
register int a0;
|
| 113 |
|
| 114 |
{
|
| 115 |
short pp, pm;
|
| 116 |
|
| 117 |
pp = pati[(a0 >> 2) & 03];
|
| 118 |
if (pp != curpat) {
|
| 119 |
PenPat(macpat[pp]);
|
| 120 |
curpat = pp;
|
| 121 |
}
|
| 122 |
|
| 123 |
if (a0 & 0100)
|
| 124 |
pm = patXor;
|
| 125 |
else
|
| 126 |
pm = patOr;
|
| 127 |
if (pm != curpmod) {
|
| 128 |
PenMode(pm);
|
| 129 |
curpmod = pm;
|
| 130 |
}
|
| 131 |
|
| 132 |
}
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
fillrect(p) /* fill a rectangle */
|
| 138 |
|
| 139 |
register PRIMITIVE *p;
|
| 140 |
|
| 141 |
{
|
| 142 |
static Rect r;
|
| 143 |
|
| 144 |
r.left = mapx(p->xy[XMN]);
|
| 145 |
r.right = mapx(p->xy[XMX]);
|
| 146 |
r.top = mapy(p->xy[YMX]);
|
| 147 |
r.bottom = mapy(p->xy[YMN]);
|
| 148 |
|
| 149 |
setfill(p->arg0);
|
| 150 |
PaintRect(&r);
|
| 151 |
|
| 152 |
}
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
filltri(p) /* fill a triangle */
|
| 157 |
|
| 158 |
register PRIMITIVE *p;
|
| 159 |
|
| 160 |
{
|
| 161 |
PolyHandle polyh;
|
| 162 |
int x[4], y[4];
|
| 163 |
int skipv;
|
| 164 |
register int i;
|
| 165 |
|
| 166 |
polyh = OpenPoly();
|
| 167 |
|
| 168 |
x[0] = x[1] = mapx(p->xy[XMN]);
|
| 169 |
x[2] = x[3] = mapx(p->xy[XMX]);
|
| 170 |
y[1] = y[2] = mapy(p->xy[YMN]);
|
| 171 |
y[0] = y[3] = mapy(p->xy[YMX]);
|
| 172 |
|
| 173 |
skipv = (p->arg0 >> 4) & 03;
|
| 174 |
if (skipv == 3)
|
| 175 |
MoveTo(x[2], y[2]);
|
| 176 |
else
|
| 177 |
MoveTo(x[3], y[3]);
|
| 178 |
|
| 179 |
for (i = 0; i < 4; i++)
|
| 180 |
if (i != skipv)
|
| 181 |
LineTo(x[i], y[i]);
|
| 182 |
|
| 183 |
ClosePoly();
|
| 184 |
setfill(p->arg0);
|
| 185 |
PaintPoly(polyh);
|
| 186 |
KillPoly(polyh);
|
| 187 |
xpos = -1;
|
| 188 |
ypos = -1;
|
| 189 |
|
| 190 |
}
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
xform(xp, yp, p) /* transform a point according to p */
|
| 196 |
|
| 197 |
register int *xp, *yp;
|
| 198 |
register PRIMITIVE *p;
|
| 199 |
|
| 200 |
{
|
| 201 |
int x, y;
|
| 202 |
|
| 203 |
switch (p->arg0 & 060) {
|
| 204 |
case 0: /* right */
|
| 205 |
x = *xp;
|
| 206 |
y = *yp;
|
| 207 |
break;
|
| 208 |
case 020: /* up */
|
| 209 |
x = (XYSIZE-1) - *yp;
|
| 210 |
y = *xp;
|
| 211 |
break;
|
| 212 |
case 040: /* left */
|
| 213 |
x = (XYSIZE-1) - *xp;
|
| 214 |
y = (XYSIZE-1) - *yp;
|
| 215 |
break;
|
| 216 |
case 060: /* down */
|
| 217 |
x = *yp;
|
| 218 |
y = (XYSIZE-1) - *xp;
|
| 219 |
break;
|
| 220 |
}
|
| 221 |
|
| 222 |
*xp = CONV(x, p->xy[XMX] - p->xy[XMN]) + p->xy[XMN];
|
| 223 |
*yp = CONV(y, p->xy[YMX] - p->xy[YMN]) + p->xy[YMN];
|
| 224 |
|
| 225 |
}
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
fillpoly(p) /* fill a polygon */
|
| 230 |
|
| 231 |
register PRIMITIVE *p;
|
| 232 |
|
| 233 |
{
|
| 234 |
int x0, y0, curx, cury;
|
| 235 |
PolyHandle polyh;
|
| 236 |
char *nextscan();
|
| 237 |
register char *s;
|
| 238 |
|
| 239 |
polyh = OpenPoly();
|
| 240 |
|
| 241 |
if ((s = nextscan(nextscan(p->args, "%d", &x0), "%d", &y0)) == NULL)
|
| 242 |
error(USER, "illegal polygon spec in fillpoly");
|
| 243 |
|
| 244 |
xform(&x0, &y0, p);
|
| 245 |
x0 = mapx(x0); y0 = mapy(y0);
|
| 246 |
MoveTo(x0, y0);
|
| 247 |
|
| 248 |
while ((s = nextscan(nextscan(s, "%d", &curx), "%d", &cury)) != NULL) {
|
| 249 |
xform(&curx, &cury, p);
|
| 250 |
curx = mapx(curx); cury = mapy(cury);
|
| 251 |
LineTo(curx, cury);
|
| 252 |
}
|
| 253 |
LineTo(x0, y0);
|
| 254 |
|
| 255 |
ClosePoly();
|
| 256 |
|
| 257 |
if (p->arg0 & 0100) { /* draw border */
|
| 258 |
if (curpat != 0) {
|
| 259 |
PenPat(macpat[0]);
|
| 260 |
curpat = 0;
|
| 261 |
}
|
| 262 |
if (curpsiz != 1) {
|
| 263 |
PenSize(1, 1);
|
| 264 |
curpsiz = 1;
|
| 265 |
}
|
| 266 |
if (curpmod != patOr) {
|
| 267 |
PenMode(patOr);
|
| 268 |
curpmod = patOr;
|
| 269 |
}
|
| 270 |
FramePoly(polyh);
|
| 271 |
}
|
| 272 |
|
| 273 |
setfill(p->arg0 & 077);
|
| 274 |
PaintPoly(polyh);
|
| 275 |
KillPoly(polyh);
|
| 276 |
xpos = -1;
|
| 277 |
ypos = -1;
|
| 278 |
|
| 279 |
}
|