⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miwideline.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 4 页
字号:
}#define V_TOP	    0#define V_RIGHT	    1#define V_BOTTOM    2#define V_LEFT	    3static voidmiWideDashSegment (pDrawable, pGC, spanData, pDashOffset, pDashIndex,	   x1, y1, x2, y2, projectLeft, projectRight, leftFace, rightFace)    DrawablePtr	    pDrawable;    register GCPtr  pGC;    int		    *pDashOffset, *pDashIndex;    SpanDataPtr	    spanData;    int		    x1, y1, x2, y2;    Bool	    projectLeft, projectRight;    LineFacePtr	    leftFace, rightFace;{    int		    dashIndex, dashRemain;    unsigned char   *pDash;    double	    L, l;    double	    k;    PolyVertexRec   vertices[4];    PolyVertexRec   saveRight, saveBottom;    PolySlopeRec    slopes[4];    PolyEdgeRec	    left[2], right[2];    LineFaceRec	    lcapFace, rcapFace;    int		    nleft, nright;    int		    h;    int		    y;    int		    dy, dx;    unsigned long   pixel;    double	    LRemain;    double	    r;    double	    rdx, rdy;    double	    dashDx, dashDy;    double	    saveK;    Bool	    first = TRUE;    double	    lcenterx, lcentery, rcenterx, rcentery;    unsigned long   fgPixel, bgPixel;        dx = x2 - x1;    dy = y2 - y1;    dashIndex = *pDashIndex;    pDash = pGC->dash;    dashRemain = pDash[dashIndex] - *pDashOffset;    fgPixel = pGC->fgPixel;    bgPixel = pGC->bgPixel;    if (pGC->fillStyle == FillOpaqueStippled ||	pGC->fillStyle == FillTiled)    {	bgPixel = fgPixel;    }    l = ((double) pGC->lineWidth) / 2.0;    if (dx == 0)    {	L = dy;	rdx = 0;	rdy = l;	if (dy < 0)	{	    L = -dy;	    rdy = -l;	}    }    else if (dy == 0)    {	L = dx;	rdx = l;	rdy = 0;	if (dx < 0)	{	    L = -dx;	    rdx = -l;	}    }    else    {	L = hypot ((double) dx, (double) dy);	r = l / L;	rdx = r * dx;	rdy = r * dy;    }    k = l * L;    LRemain = L;    /* All position comments are relative to a line with dx and dy > 0,     * but the code does not depend on this */    /* top */    slopes[V_TOP].dx = dx;    slopes[V_TOP].dy = dy;    slopes[V_TOP].k = k;    /* right */    slopes[V_RIGHT].dx = -dy;    slopes[V_RIGHT].dy = dx;    slopes[V_RIGHT].k = 0;    /* bottom */    slopes[V_BOTTOM].dx = -dx;    slopes[V_BOTTOM].dy = -dy;    slopes[V_BOTTOM].k = k;    /* left */    slopes[V_LEFT].dx = dy;    slopes[V_LEFT].dy = -dx;    slopes[V_LEFT].k = 0;    /* preload the start coordinates */    vertices[V_RIGHT].x = vertices[V_TOP].x = rdy;    vertices[V_RIGHT].y = vertices[V_TOP].y = -rdx;    vertices[V_BOTTOM].x = vertices[V_LEFT].x = -rdy;    vertices[V_BOTTOM].y = vertices[V_LEFT].y = rdx;    if (projectLeft)    {	vertices[V_TOP].x -= rdx;	vertices[V_TOP].y -= rdy;	vertices[V_LEFT].x -= rdx;	vertices[V_LEFT].y -= rdy;	slopes[V_LEFT].k = rdx * dx + rdy * dy;    }    lcenterx = x1;    lcentery = y1;    if (pGC->capStyle == CapRound)    {	lcapFace.dx = dx;	lcapFace.dy = dy;	lcapFace.x = x1;	lcapFace.y = y1;	rcapFace.dx = -dx;	rcapFace.dy = -dy;	rcapFace.x = x1;	rcapFace.y = y1;    }    while (LRemain > dashRemain)    {	dashDx = (dashRemain * dx) / L;	dashDy = (dashRemain * dy) / L;	rcenterx = lcenterx + dashDx;	rcentery = lcentery + dashDy;	vertices[V_RIGHT].x += dashDx;	vertices[V_RIGHT].y += dashDy;	vertices[V_BOTTOM].x += dashDx;	vertices[V_BOTTOM].y += dashDy;	slopes[V_RIGHT].k = vertices[V_RIGHT].x * dx + vertices[V_RIGHT].y * dy;	if (pGC->lineStyle == LineDoubleDash || !(dashIndex & 1))	{	    if (pGC->lineStyle == LineOnOffDash && 	        pGC->capStyle == CapProjecting)	    {		saveRight = vertices[V_RIGHT];		saveBottom = vertices[V_BOTTOM];		saveK = slopes[V_RIGHT].k;				if (!first)		{		    vertices[V_TOP].x -= rdx;		    vertices[V_TOP].y -= rdy;    		    vertices[V_LEFT].x -= rdx;		    vertices[V_LEFT].y -= rdy;		    slopes[V_LEFT].k = vertices[V_LEFT].x *				       slopes[V_LEFT].dy -				       vertices[V_LEFT].y *				       slopes[V_LEFT].dx;		}				vertices[V_RIGHT].x += rdx;		vertices[V_RIGHT].y += rdy;		vertices[V_BOTTOM].x += rdx;		vertices[V_BOTTOM].y += rdy;		slopes[V_RIGHT].k = vertices[V_RIGHT].x *				   slopes[V_RIGHT].dy -				   vertices[V_RIGHT].y *				   slopes[V_RIGHT].dx;	    }	    y = miPolyBuildPoly (vertices, slopes, 4, x1, y1,			     	 left, right, &nleft, &nright, &h);	    pixel = (dashIndex & 1) ? bgPixel : fgPixel;	    miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, h, left, right, nleft, nright);	    if (pGC->lineStyle == LineOnOffDash)	    {		switch (pGC->capStyle)		{		case CapProjecting:		    vertices[V_BOTTOM] = saveBottom;		    vertices[V_RIGHT] = saveRight;		    slopes[V_RIGHT].k = saveK;		    break;		case CapRound:		    if (!first)		    {		    	if (dx < 0)		    	{		    	    lcapFace.xa = -vertices[V_LEFT].x;		    	    lcapFace.ya = -vertices[V_LEFT].y;			    lcapFace.k = slopes[V_LEFT].k;		    	}		    	else		    	{		    	    lcapFace.xa = vertices[V_TOP].x;		    	    lcapFace.ya = vertices[V_TOP].y;			    lcapFace.k = -slopes[V_LEFT].k;		    	}		    	miLineArc (pDrawable, pGC, pixel, spanData,			       	   &lcapFace, (LineFacePtr) NULL,			       	   lcenterx, lcentery, FALSE);		    }		    if (dx < 0)		    {		    	rcapFace.xa = vertices[V_BOTTOM].x;		    	rcapFace.ya = vertices[V_BOTTOM].y;			rcapFace.k = slopes[V_RIGHT].k;		    }		    else		    {		    	rcapFace.xa = -vertices[V_RIGHT].x;		    	rcapFace.ya = -vertices[V_RIGHT].y;			rcapFace.k = -slopes[V_RIGHT].k;		    }		    miLineArc (pDrawable, pGC, pixel, spanData,			       (LineFacePtr) NULL, &rcapFace,			       rcenterx, rcentery, FALSE);		    break;	    	}	    }	}	LRemain -= dashRemain;	++dashIndex;	if (dashIndex == pGC->numInDashList)	    dashIndex = 0;	dashRemain = pDash[dashIndex];	lcenterx = rcenterx;	lcentery = rcentery;	vertices[V_TOP] = vertices[V_RIGHT];	vertices[V_LEFT] = vertices[V_BOTTOM];	slopes[V_LEFT].k = -slopes[V_RIGHT].k;	first = FALSE;    }    if (pGC->lineStyle == LineDoubleDash || !(dashIndex & 1))    {    	vertices[V_TOP].x -= dx;    	vertices[V_TOP].y -= dy;	vertices[V_LEFT].x -= dx;	vertices[V_LEFT].y -= dy;	vertices[V_RIGHT].x = rdy;	vertices[V_RIGHT].y = -rdx;	vertices[V_BOTTOM].x = -rdy;	vertices[V_BOTTOM].y = rdx;		if (projectRight)	{	    vertices[V_RIGHT].x += rdx;	    vertices[V_RIGHT].y += rdy;    	    vertices[V_BOTTOM].x += rdx;	    vertices[V_BOTTOM].y += rdy;	    slopes[V_RIGHT].k = vertices[V_RIGHT].x *				slopes[V_RIGHT].dy -				vertices[V_RIGHT].y *				slopes[V_RIGHT].dx;	}	else	    slopes[V_RIGHT].k = 0;	if (!first && pGC->lineStyle == LineOnOffDash &&	    pGC->capStyle == CapProjecting)	{	    vertices[V_TOP].x -= rdx;	    vertices[V_TOP].y -= rdy;	    vertices[V_LEFT].x -= rdx;	    vertices[V_LEFT].y -= rdy;	    slopes[V_LEFT].k = vertices[V_LEFT].x *			       slopes[V_LEFT].dy -			       vertices[V_LEFT].y *			       slopes[V_LEFT].dx;	}	else	    slopes[V_LEFT].k += dx * dx + dy * dy;	y = miPolyBuildPoly (vertices, slopes, 4, x2, y2,			     left, right, &nleft, &nright, &h);	pixel = (dashIndex & 1) ? pGC->bgPixel : pGC->fgPixel;	miFillPolyHelper (pDrawable, pGC, pixel, spanData, y, h, left, right, nleft, nright);	if (!first && pGC->lineStyle == LineOnOffDash &&	    pGC->capStyle == CapRound)	{	    lcapFace.x = x2;	    lcapFace.y = y2;	    if (dx < 0)	    {		lcapFace.xa = -vertices[V_LEFT].x;		lcapFace.ya = -vertices[V_LEFT].y;		lcapFace.k = slopes[V_LEFT].k;	    }	    else	    {		lcapFace.xa = vertices[V_TOP].x;		lcapFace.ya = vertices[V_TOP].y;		lcapFace.k = -slopes[V_LEFT].k;	    }	    miLineArc (pDrawable, pGC, pixel, spanData,		       &lcapFace, (LineFacePtr) NULL,		       rcenterx, rcentery, FALSE);	}    }    dashRemain = ((double) dashRemain) - LRemain;    if (dashRemain == 0)    {	dashIndex++;	if (dashIndex == pGC->numInDashList)	    dashIndex = 0;	dashRemain = pDash[dashIndex];    }    leftFace->x = x1;    leftFace->y = y1;    leftFace->dx = dx;    leftFace->dy = dy;    leftFace->xa = rdy;    leftFace->ya = -rdx;    leftFace->k = k;    rightFace->x = x2;    rightFace->y = y2;    rightFace->dx = -dx;    rightFace->dy = -dy;    rightFace->xa = -rdy;    rightFace->ya = rdx;    rightFace->k = k;    *pDashIndex = dashIndex;    *pDashOffset = pDash[dashIndex] - dashRemain;}voidmiWideDash (pDrawable, pGC, mode, npt, pPts)    DrawablePtr	pDrawable;    register GCPtr pGC;    int		mode;    register int npt;    register DDXPointPtr pPts;{    int		    x1, y1, x2, y2;    unsigned long   pixel;    Bool	    projectLeft, projectRight;    LineFaceRec	    leftFace, rightFace, prevRightFace;    LineFaceRec	    firstFace;    int		    first;    int		    dashIndex, dashOffset;    register int    prevDashIndex;    SpanDataRec	    spanDataRec;    SpanDataPtr	    spanData;    Bool	    somethingDrawn = FALSE;    Bool	    selfJoin;    Bool	    endIsFg, startIsFg, firstIsFg = FALSE, prevIsFg;    /* XXX backward compatibility */    if (pGC->lineWidth == 0)    {	miZeroDashLine (pDrawable, pGC, mode, npt, pPts);	return;    }    if (pGC->lineStyle == LineDoubleDash && 	(pGC->fillStyle == FillOpaqueStippled || pGC->fillStyle == FillTiled))    {	miWideLine (pDrawable, pGC, mode, npt, pPts);	return;    }    if (npt == 0)	return;    spanData = miSetupSpanData (pGC, &spanDataRec, npt);    x2 = pPts->x;    y2 = pPts->y;    first = TRUE;    selfJoin = FALSE;    if (mode == CoordModePrevious)    {	int nptTmp;	DDXPointPtr pPtsTmp;	x1 = x2;	y1 = y2;	nptTmp = npt;	pPtsTmp = pPts + 1;	while (--nptTmp)	{	    x1 += pPtsTmp->x;	    y1 += pPtsTmp->y;	    ++pPtsTmp;	}	if (x2 == x1 && y2 == y1)	    selfJoin = TRUE;    }    else if (x2 == pPts[npt-1].x && y2 == pPts[npt-1].y)    {	selfJoin = TRUE;    }    projectLeft = pGC->capStyle == CapProjecting && !selfJoin;    projectRight = FALSE;    dashIndex = 0;    dashOffset = 0;    miStepDash ((int)pGC->dashOffset, &dashIndex,	        pGC->dash, (int)pGC->numInDashList, &dashOffset);    while (--npt)    {	x1 = x2;	y1 = y2;	++pPts;	x2 = pPts->x;	y2 = pPts->y;	if (mode == CoordModePrevious)	{	    x2 += x1;	    y2 += y1;	}	if (x1 != x2 || y1 != y2)	{	    somethingDrawn = TRUE;	    if (npt == 1 && pGC->capStyle == CapProjecting && 		(!selfJoin || !firstIsFg))		projectRight = TRUE;	    prevDashIndex = dashIndex;	    miWideDashSegment (pDrawable, pGC, spanData, &dashOffset, &dashIndex,				x1, y1, x2, y2,				projectLeft, projectRight, &leftFace, &rightFace);	    startIsFg = !(prevDashIndex & 1);	    endIsFg = (dashIndex & 1) ^ (dashOffset != 0);	    if (pGC->lineStyle == LineDoubleDash || startIsFg)	    {	    	pixel = startIsFg ? pGC->fgPixel : pGC->bgPixel;	    	if (first || (pGC->lineStyle == LineOnOffDash && !prevIsFg))	    	{	    	    if (first && selfJoin)		    {		    	firstFace = leftFace;			firstIsFg = startIsFg;		    }	    	    else if (pGC->capStyle == CapRound)		    	miLineArc (pDrawable, pGC, pixel, spanData,			       	   &leftFace, (LineFacePtr) NULL,			       	   (double)0.0, (double)0.0, TRUE);	    	}	    	else	    	{	    	    miLineJoin (pDrawable, pGC, pixel, spanData, &leftFace,		            	&prevRightFace);	    	}	    }	    prevRightFace = rightFace;	    prevIsFg = endIsFg;	    first = FALSE;	    projectLeft = FALSE;	}	if (npt == 1 && somethingDrawn)	{	    if (pGC->lineStyle == LineDoubleDash || endIsFg)	    {		pixel = endIsFg ? pGC->fgPixel : pGC->bgPixel;		if (selfJoin && (pGC->lineStyle == LineDoubleDash || firstIsFg))		{		    miLineJoin (pDrawable, pGC, pixel, spanData, &firstFace,				&rightFace);		}		else 		{		    if (pGC->capStyle == CapRound)			miLineArc (pDrawable, pGC, pixel, spanData,				    (LineFacePtr) NULL, &rightFace,				    (double)0.0, (double)0.0, TRUE);		}	    }	    else	    {		/* glue a cap to the start of the line if		 * we're OnOffDash and ended on odd dash		 */		if (selfJoin && firstIsFg)		{		    pixel = pGC->fgPixel;		    if (pGC->capStyle == CapProjecting)			miLineProjectingCap (pDrawable, pGC, pixel, spanData,				    &firstFace, TRUE,				    (double)0.0, (double)0.0, TRUE);		    else if (pGC->capStyle == CapRound)			miLineArc (pDrawable, pGC, pixel, spanData,				    &firstFace, (LineFacePtr) NULL,				    (double)0.0, (double)0.0, TRUE);		}	    }	}    }    /* handle crock where all points are coincident */    if (!somethingDrawn && (pGC->lineStyle == LineDoubleDash || !(dashIndex & 1)))    {	/* not the same as endIsFg computation above */	pixel = (dashIndex & 1) ? pGC->bgPixel : pGC->fgPixel;	switch (pGC->capStyle) {	case CapRound:	    miLineArc (pDrawable, pGC, pixel, spanData,		       (LineFacePtr) NULL, (LineFacePtr) NULL,		       (double)x2, (double)y2,		       FALSE);	    break;	case CapProjecting:	    x1 = pGC->lineWidth;	    miFillRectPolyHelper (pDrawable, pGC, pixel, spanData,				  x2 - (x1 >> 1), y2 - (x1 >> 1), x1, x1);	    break;	}    }    if (spanData)	miCleanupSpanData (pDrawable, pGC, spanData);}/* these are stubs to allow old ddx ValidateGCs to work without change */voidmiMiter(){}voidmiNotMiter(){}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -