Esempio n. 1
0
int
XFillPolygon(Display * display, Drawable d, GC gc,
	XPoint * points, int npoints, int shape, int mode)
{
	int i;
	GR_POINT *gr_points;

	gr_points = ALLOCA(npoints * sizeof(GR_POINT));

	if (mode == CoordModeOrigin) {
		for (i = 0; i < npoints; i++) {
			gr_points[i].x = points[i].x;
			gr_points[i].y = points[i].y;
		}
	} else {		/* CoordModePrevious */
		int px = 0, py = 0;
		for (i = 0; i < npoints; i++) {
			gr_points[i].x = px + points[i].x;
			gr_points[i].y = py + points[i].y;

			px += points[i].x;
			py += points[i].y;
		}
	}

	if (shape == Complex || shape == Convex)
		printf("XFillPolygon: Complex/Convex\n");

	GrFillPoly(d, gc->gid, npoints, gr_points);

	FREEA(gr_points);
	return 1;
}
Esempio n. 2
0
Region
XPolygonRegion(XPoint *points, int n, int rule)
{
	Region		region;
	int		i;
	GR_POINT *	local;

	region = (Region)Xcalloc(1, sizeof(Region *));
	if (!region)
		return NULL;

	/* must copy points, since dimensions differ*/
	local = ALLOCA(n * sizeof(GR_POINT));
	if (!local) {
		Xfree(region);
		return 0;
	}

	for (i=0; i < n; i++) {
		local[i].x = points[i].x;
		local[i].y = points[i].y;
	}

	/* convert rule to NX format*/
	rule = (rule == EvenOddRule)? GR_POLY_EVENODD: GR_POLY_WINDING;

	region->rid = GrNewPolygonRegion(rule, n, local);
	FREEA(local);

	return region;
}
Esempio n. 3
0
static void
GrSetGCDashWrapper(void *r)
{
	nxSetGCDashReq *req = r;
	char *buffer = ALLOCA(req->count);

	memcpy((void *) buffer, GetReqData(req), req->count);
	GrSetGCDash(req->gcid, buffer, req->count);
	FREEA(buffer);
}
Esempio n. 4
0
static void
GrSetGCStippleWrapper(void *r)
{
	nxSetGCStippleReq *req = r;
	GR_BITMAP *buffer;
	
	buffer = ALLOCA(GR_BITMAP_SIZE(req->width, req->height) *
		sizeof(GR_BITMAP));

	memcpy((void *) buffer, GetReqData(req),
	       GR_BITMAP_SIZE(req->width, req->height) * sizeof(GR_BITMAP));

	GrSetGCStipple(req->gcid, (GR_BITMAP *)buffer, req->width, req->height);
	FREEA(buffer);
}
Esempio n. 5
0
void
GdFillPoly(PSD psd, int count, MWPOINT *pointtable)
{
    MWCOORD xl = 0, xr = 0;     /* x vals of left and right edges */
    int dl = 0, dr = 0;         /* decision variables             */
    int ml = 0, m1l = 0;        /* left edge slope and slope+1    */
    int mr = 0, m1r = 0;        /* right edge slope and slope+1   */
    int incr1l = 0, incr2l = 0; /* left edge error increments     */
    int incr1r = 0, incr2r = 0; /* right edge error increments    */
    int dy;                     /* delta y                        */
    MWCOORD y;                  /* current scanline               */
    int left, right;            /* indices to first endpoints     */
    int i;                      /* loop counter                   */
    int nextleft, nextright;    /* indices to second endpoints    */
    MWPOINT *ptsOut, *FirstPoint;/* output buffer                 */
    MWCOORD *width, *FirstWidth;/* output buffer                  */
    int imin;                   /* index of smallest vertex (in y)*/
    int ymin;                   /* y-extents of polygon           */
    int ymax;

    /*
     *  find leftx, bottomy, rightx, topy, and the index
     *  of bottomy.
     */

    imin = getPolyYBounds(pointtable, count, &ymin, &ymax);

    if (gr_fillmode != MWFILL_SOLID) {
      int xmin, xmax;
      getPolyXBounds(pointtable, count, &xmin, &xmax);
      set_ts_origin(xmin, ymin);
    }

    dy = ymax - ymin + 1;
    if ((count < 3) || (dy < 0))
	return;
    ptsOut = FirstPoint = (MWPOINT *)ALLOCA(sizeof(MWPOINT) * dy);
    width = FirstWidth = (MWCOORD *)ALLOCA(sizeof(MWCOORD) * dy);
    if(!FirstPoint || !FirstWidth)
    {
	if (FirstWidth) FREEA(FirstWidth);
	if (FirstPoint) FREEA(FirstPoint);
	return;
    }

    nextleft = nextright = imin;
    y = pointtable[nextleft].y;

    /*
     *  loop through all edges of the polygon
     */
    do {
        /*
         *  add a left edge if we need to
         */
        if (pointtable[nextleft].y == y) {
            left = nextleft;

            /*
             *  find the next edge, considering the end
             *  conditions of the array.
             */
            nextleft++;
            if (nextleft >= count)
                nextleft = 0;

            /*
             *  now compute all of the random information
             *  needed to run the iterative algorithm.
             */
            BRESINITPGON(pointtable[nextleft].y-pointtable[left].y,
                         pointtable[left].x,pointtable[nextleft].x,
                         xl, dl, ml, m1l, incr1l, incr2l);
        }

        /*
         *  add a right edge if we need to
         */
        if (pointtable[nextright].y == y) {
            right = nextright;

            /*
             *  find the next edge, considering the end
             *  conditions of the array.
             */
            nextright--;
            if (nextright < 0)
                nextright = count-1;

            /*
             *  now compute all of the random information
             *  needed to run the iterative algorithm.
             */
            BRESINITPGON(pointtable[nextright].y-pointtable[right].y,
                         pointtable[right].x,pointtable[nextright].x,
                         xr, dr, mr, m1r, incr1r, incr2r);
        }

        /*
         *  generate scans to fill while we still have
         *  a right edge as well as a left edge.
         */
        i = MWMIN(pointtable[nextleft].y, pointtable[nextright].y) - y;
	/* in case we're called with non-convex polygon */
	if(i < 0)
        {
	    FREEA(FirstWidth);
	    FREEA(FirstPoint);
	    return;
	}
        while (i-- > 0) 
        {
            ptsOut->y = y;

            /*
             *  reverse the edges if necessary
             */
            if (xl < xr) 
            {
                *(width++) = xr - xl;
                (ptsOut++)->x = xl;
            }
            else 
            {
                *(width++) = xl - xr;
                (ptsOut++)->x = xr;
            }
            y++;

            /* increment down the edges */
            BRESINCRPGON(dl, xl, ml, m1l, incr1l, incr2l);
            BRESINCRPGON(dr, xr, mr, m1r, incr1r, incr2r);
        }
    }  while (y != ymax);

    /*
     * Finally, fill the spans
     */
    i = ptsOut-FirstPoint;
    ptsOut = FirstPoint;
    width = FirstWidth;
    while (--i >= 0) {
	/* calc x extent from width*/
	int e = *width++ - 1;
	if (e >= 0) {
	  if (gr_fillmode != MWFILL_SOLID) 
	    ts_drawrow(psd, ptsOut->x, ptsOut->x + e, ptsOut->y);
	   else
	     drawrow(psd, ptsOut->x, ptsOut->x + e, ptsOut->y);
	}
	++ptsOut;
    }

    FREEA(FirstWidth);
    FREEA(FirstPoint);
    GdFixCursor(psd);
}