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

📄 view9.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 2 页
字号:
lowerleft:
   Yg = (portYmax - Yl) + portoriginY =
   Yg = portYmax + -Yl + portoriginY =

   Yg =  -Yl + C  where C = portoriginY + portYmax 
   Yg = (not Yl) + 1 + C   =
   Yg = (not Yl) + (C + 1)

Let INVERT = 0, and C = (portOrignY - portYmin)  then
   Yg = (Yl xor INVERT) + C would handle the upper left case

Let INVERT = all ones, and C = (portOrignY + portYmax + 1)  then
   Yg = (Yl xor INVERT) + C would also handle the lower left case

The XOR would not be necessary for the X cases if no mirroring in the
X direction is required.

Virtual to Local
----------------

       sub  x, GDS:[grafPort.portVirt.Xmin]	;make relative to min in virtRect
       sub  y, GDS:portVirt.Ymin

       x mul virtXnumer      ( portrect X size )
       x += .5 * virtXdenom  (pre round up)
       x(32) div virtXdenom  ( virtual rect X size )

       y mul virtYnumer 
       y += .5 * virtYdenom  (pre round up)
       y(32) div virtYdenom

       ;at this point the x,y is relative to 0
upper left:
		virtconst	= portOrign =
				 local C + portMin
lower left:
		virtYconst	= (portYmax + portOrignY + 1) - portYmin =
				  local C - portYmin

       ;convert from local 0,0 to global
       add  x, virtXconst
       xor  y, localInvert
       add  y, virtYconst */
void mwGblCoord(void)
{

	/* local X conversion constant */
	localXconst = grafPort.portOrgn.X - grafPort.portRect.Xmin;

	/* local Y conversion constant */
	if (grafPort.portFlags & pfUpper)
	{	/* upper left */
		localYconst = grafPort.portOrgn.Y - grafPort.portRect.Ymin;
	}
	else
	{	/* lower left */
		localYconst = grafPort.portOrgn.Y + grafPort.portRect.Ymax;
	}

	/* precompute virtual factors for standard virtual call */
	mwVirtCoord(&grafPort);

	/* set globalLevel indicator and flag */
	if ((grafPort.portFlags & pfVirtual) || (localXconst | localYconst |
		localXinvert | localYinvert))
	{	/* is virtual or not global */
		globalLevel = 1;
		grafPort.portFlags = grafPort.portFlags & ~pfGblCoord;
	}
	else
	{	/* is global */
		globalLevel = -1;
		grafPort.portFlags = grafPort.portFlags | pfGblCoord;
	}

	thePort->portFlags = grafPort.portFlags;	/* update user port */

	return;
}

				     	
/* Function mwV2GP is the default virtual to global point
transformation routine. */
void mwV2GP(int *virtX, int *virtY)
{
	long tempXY;
	short GrafErrValue;

	/* convert X */
	tempXY = ((((*virtX - grafPort.portVirt.Xmin) * virtXnumer) +
		virtXround) / virtXdenom) + virtXconst;
	if (tempXY > 32767)
	{	/* overflow */
		*virtX = 32767;
		GrafErrValue = c_Vir2LclP + c_DivOflow;
		nuGrafErr(GrafErrValue);
	}
	else
	{	/* check negative overflow */
		if (tempXY < -32767)
		{	/* overflow */
			*virtX = -32767;
			GrafErrValue = c_Vir2LclP + c_DivOflow;
			nuGrafErr(GrafErrValue);
		}
		else
		{	/* okay */
			*virtX = (int) tempXY;
		}
	}

	/* convert Y */
	tempXY = (((((*virtY - grafPort.portVirt.Ymin) * virtYnumer) +
		virtYround) / virtYdenom) ^ localYinvert) + virtYconst;
	if (tempXY > 32767)
	{	/* overflow */
		*virtY = 32767;
		GrafErrValue = c_Vir2LclP + c_DivOflow;
		nuGrafErr(GrafErrValue);
	}
	else
	{	/* check negative overflow */
		if (tempXY < -32767)
		{	/* overflow */
			*virtY = -32767;
			GrafErrValue = c_Vir2LclP + c_DivOflow;
			nuGrafErr(GrafErrValue);
		}
		else
		{	/* okay */
			*virtY = (int) tempXY;
		}
	}

	return;
}


/* Function mwV2GR is the default virtual to global rectangle
transformation routine. */
void mwV2GR(rect *virRect)
{
	int tempX;
	int tempY;

	/* convert the start point */
	tempX = virRect->Xmin;
	tempY = virRect->Ymin;
	mwV2GP(&tempX, &tempY);
	virRect->Xmin = tempX;
	virRect->Ymin = tempY;

	/* convert the end point */
	tempX = virRect->Xmax;
	tempY = virRect->Ymax;
	mwV2GP(&tempX, &tempY);
	virRect->Xmax = tempX;

	if (grafPort.portFlags & pfUpper)
	{	/* upper origin */
		virRect->Ymax = tempY;
	}
	else
	{	/* lower origin */
		virRect->Ymax = virRect->Ymin;
		virRect->Ymin = tempY;
	}

	return;
}


/* Function mwG2VP is the default global to virtual point
transformation routine */
void mwG2VP(int *virtX, int *virtY)
{
	long tempXY;
	short GrafErrValue;

	/* convert X */
	if (virtXnumer == 0)
	{	/* divide by zero! */
		if (*virtX < 0)
		{
			*virtX = -32767;
		}
		else
		{
			*virtX = 32767;
		}
		GrafErrValue = c_Gbl2VirP + c_DivOflow;
		nuGrafErr(GrafErrValue);
		goto ConvertY;
	}

	tempXY = ((((*virtX - grafPort.portOrgn.X) * virtXdenom) +
		(virtXnumer >> 1)) / virtXnumer) + grafPort.portVirt.Xmin;
	if (tempXY > 32767)
	{	/* overflow */
		*virtX = 32767;
		GrafErrValue = c_Gbl2VirP + c_DivOflow;
		nuGrafErr(GrafErrValue);
	}
	else
	{	/* check negative overflow */
		if (tempXY < -32767)
		{	/* overflow */
			*virtX = -32767;
			GrafErrValue = c_Gbl2VirP + c_DivOflow;
			nuGrafErr(GrafErrValue);
		}
		else
		{	/* okay */
			*virtX = (int) tempXY;
		}
	}

ConvertY:
	/* convert Y */
	if (virtYnumer == 0)
	{	/* divide by zero! */
		if (*virtY < 0)
		{
			*virtY = -32767;
		}
		else
		{
			*virtY = 32767;
		}
		GrafErrValue = c_Gbl2VirP + c_DivOflow;
		nuGrafErr(GrafErrValue);
		return;
	}

	tempXY = *virtY - grafPort.portOrgn.Y;
	if (!(grafPort.portFlags & pfUpper))
	{	/* lower origin */
		tempXY = grafPort.portRect.Ymax - tempXY;
	}

	tempXY = (((tempXY * virtYdenom) + (virtYnumer >> 1)) /
		virtYnumer) + grafPort.portVirt.Ymin;
	if (tempXY > 32767)
	{	/* overflow */
		*virtY = 32767;
		GrafErrValue = c_Gbl2VirP + c_DivOflow;
		nuGrafErr(GrafErrValue);
	}
	else
	{	/* check negative overflow */
		if (tempXY < -32767)
		{	/* overflow */
			*virtY = -32767;
			GrafErrValue = c_Gbl2VirP + c_DivOflow;
			nuGrafErr(GrafErrValue);
		}
		else
		{	/* okay */
			*virtY = (int) tempXY;
		}
	}

	return;
}


/* Function mwG2VR is the default global to virtual rectangle
transformation routine. */
void mwG2VR(rect *virRect)
{
	int tempX;
	int tempY;

	/* convert the start point */
	tempX = virRect->Xmin;
	tempY = virRect->Ymin;
	mwG2VP(&tempX, &tempY);
	virRect->Xmin = tempX;
	virRect->Ymin = tempY;

	/* convert the end point */
	tempX = virRect->Xmax;
	tempY = virRect->Ymax;
	mwG2VP(&tempX, &tempY);
	virRect->Xmax = tempX;

	if (virRect->Ymin <= tempY)
	{	/* okay */
		virRect->Ymax = tempY;
	}
	else
	{	/* min and max swapped */
		virRect->Ymax = virRect->Ymin;
		virRect->Ymin = tempY;
	}

	return;
}

⌨️ 快捷键说明

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