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

📄 view9.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************/
/*                                                                       */
/*         Copyright (c) 1997 - 1999 Accelerated Technology, Inc.        */
/*                                                                       */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the      */
/* subject matter of this material.  All manufacturing, reproduction,    */
/* use, and sales rights pertaining to this subject matter are governed  */
/* by the license agreement.  The recipient of this software implicitly  */
/* accepts the terms of the license.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                            VERSION          */
/*                                                                       */
/*      VIEW9.c                                          1.9             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      All                                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the mwGblPen, mwGblClip, mwVirtCoord,         */
/* mwGblCoord, mwV2GP, mwV2GR, mwG2VP & mwG2VR functions.                */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Robert G. Burrill, Accelerated Technology, Inc.                  */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         BobB           10/6/98     Corrected max values               */
/*         BobB          10/22/99     Corrected the correction           */
/*                                                                       */
/*************************************************************************/

#include "meta_wnd.h"
#include "metconst.h"    /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h"    /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "metmacs3.h"


/* Function mwGblPen calculates the LocX and LocY variables from the current
ports pnLoc variables. */
void mwGblPen(void)
{
	if (globalLevel > 0)
	{	/* convert from user to global */
		U2GP(grafPort.pnLoc.X, grafPort.pnLoc.Y, &LocX, &LocY, 1);
	}
	else
	{
		LocX = grafPort.pnLoc.X;
		LocY = grafPort.pnLoc.Y;
	}

	return;
}


/* Function mwGblClip calculates a clip rectange in global coordinates 
based on the port at ds:sn. It insures that the clip rect is within
the ports bitmap, and (if clipping not disabled) that it is within the
ports boundaries. */
void mwGblClip(metaPort *inpClpPort, rect *outClipR)
{
	short tempXY;
	short tempYmin;

	if (!(inpClpPort->portFlags & pfRecClip))
	{	/* rectangular clipping disabled - set clip to bitmap limits */
		outClipR->Xmin = 0;
		outClipR->Ymin = 0;
/* BobB 10/6/98 - corrected the following lines for max size
		outClipR->Xmax = inpClpPort->portMap->pixWidth;
		outClipR->Ymax = inpClpPort->portMap->pixHeight; */
/* BobB 10/22/99 - corrected the correction
		outClipR->Xmax = inpClpPort->portMap->pixWidth - 1;
		outClipR->Ymax = inpClpPort->portMap->pixHeight - 1; */
		outClipR->Xmax = inpClpPort->portMap->pixWidth;
		outClipR->Ymax = inpClpPort->portMap->pixHeight;
		return;
	}

	/* check clip within port limits */
	if (inpClpPort->portRect.Xmin > inpClpPort->portClip.Xmin)
	{
		outClipR->Xmin = inpClpPort->portRect.Xmin;
	}
	else
	{
		outClipR->Xmin = inpClpPort->portClip.Xmin;
	}

	if (inpClpPort->portRect.Ymin > inpClpPort->portClip.Ymin)
	{
		outClipR->Ymin = inpClpPort->portRect.Ymin;
	}
	else
	{
		outClipR->Ymin = inpClpPort->portClip.Ymin;
	}

	if (inpClpPort->portRect.Xmax < inpClpPort->portClip.Xmax)
	{
		outClipR->Xmax = inpClpPort->portRect.Xmax;
	}
	else
	{
		outClipR->Xmax = inpClpPort->portClip.Xmax;
	}

	if (inpClpPort->portRect.Ymax < inpClpPort->portClip.Ymax)
	{
		outClipR->Ymax = inpClpPort->portRect.Ymax;
	}
	else
	{
		outClipR->Ymax = inpClpPort->portClip.Ymax;
	}

	/* convert clip (always local) to global; can't call Lcl2Gbl,
	that assumes current port */
	tempXY = inpClpPort->portOrgn.X - inpClpPort->portRect.Xmin;
	outClipR->Xmin += tempXY;
	outClipR->Xmax += tempXY;

	if (inpClpPort->portFlags & pfUpper)
	{	/* upper left */
		tempXY = inpClpPort->portOrgn.Y - inpClpPort->portRect.Ymin;
		outClipR->Ymin += tempXY;
		outClipR->Ymax += tempXY;
	}
	else
	{	/* lower left */
		tempXY = inpClpPort->portOrgn.Y + inpClpPort->portRect.Ymax;
		tempYmin = tempXY - outClipR->Ymax;
		outClipR->Ymax = tempXY - outClipR->Ymin;
		outClipR->Ymin = tempYmin;
	}

	/* check for valid rect */
	if (outClipR->Xmin > outClipR->Xmax)
	{	/* swap ends */
		tempXY = outClipR->Xmin;
		outClipR->Xmin = outClipR->Xmax;
		outClipR->Xmax = tempXY;
	}

	if (outClipR->Ymin > outClipR->Ymax)
	{	/* swap ends */
		tempXY = outClipR->Ymin;
		outClipR->Ymin = outClipR->Ymax;
		outClipR->Ymax = tempXY;
	}

	/* check clip within bitmap limits */
	if (outClipR->Xmin < 0)
	{
		outClipR->Xmin = 0;
		if (outClipR->Xmax < 0) outClipR->Xmax = 0;
	}

	if (outClipR->Ymin < 0)
	{
		outClipR->Ymin = 0;
		if (outClipR->Ymax < 0) outClipR->Ymax = 0;
	}

	if (outClipR->Xmax >= inpClpPort->portMap->pixWidth)
	{
/* BobB 9/30/98 - corrected the following line for max size
		outClipR->Xmax = inpClpPort->portMap->pixWidth; */
/* BobB 10/22/99 - corrected the correction
		outClipR->Xmax = inpClpPort->portMap->pixWidth - 1; */
		outClipR->Xmax = inpClpPort->portMap->pixWidth;
		if (outClipR->Xmin >= inpClpPort->portMap->pixWidth)
/* BobB 9/30/98 - corrected the following line for max size
			outClipR->Xmin = inpClpPort->portMap->pixWidth; */
/* BobB 10/22/99 - corrected the correction
			outClipR->Xmin = inpClpPort->portMap->pixWidth - 1; */
			outClipR->Xmin = inpClpPort->portMap->pixWidth;
	}

	if (outClipR->Ymax >= inpClpPort->portMap->pixHeight)
	{
/* BobB 9/30/98 - corrected the following line for max size
		outClipR->Ymax = inpClpPort->portMap->pixHeight; */
/* BobB 10/22/99 - corrected the correction
		outClipR->Ymax = inpClpPort->portMap->pixHeight - 1; */
		outClipR->Ymax = inpClpPort->portMap->pixHeight;
		if (outClipR->Ymin >= inpClpPort->portMap->pixHeight)
/* BobB 9/30/98 - corrected the following line for max size
			outClipR->Ymin = inpClpPort->portMap->pixHeight; */
/* BobB 10/22/99 - corrected the correction
			outClipR->Ymin = inpClpPort->portMap->pixHeight - 1; */
			outClipR->Ymin = inpClpPort->portMap->pixHeight;
	}

	return;
}


/* Function mwVirtCoord precomputes virtual factors for standard virtual
call. */
void mwVirtCoord(metaPort *inpPort)
{
	short grafErrValue;

	virtXnumer = inpPort->portRect.Xmax - inpPort->portRect.Xmin;
	if (virtXnumer == 0)
	{	/* error */
		virtXdenom = 1;
		grafErrValue = c_VirtualR + c_NullRect;
		nuGrafErr(grafErrValue);
	}
	else
	{
		virtXdenom = inpPort->portVirt.Xmax - inpPort->portVirt.Xmin;
		if (virtXdenom == 0)
		{	/* error */
			virtXnumer = 0;
			virtXdenom = 1;
			grafErrValue = c_VirtualR + c_NullRect;
			nuGrafErr(grafErrValue);
		}
		else
		{
			virtXround = virtXdenom >> 1;
		}
	}

	virtYnumer = inpPort->portRect.Ymax - inpPort->portRect.Ymin;
	if (virtYnumer == 0)
	{	/* error */
		virtYdenom = 1;
		grafErrValue = c_VirtualR + c_NullRect;
		nuGrafErr(grafErrValue);
	}
	else
	{
		virtYdenom = inpPort->portVirt.Ymax - inpPort->portVirt.Ymin;
		if (virtYdenom == 0)
		{	/* error */
			virtYnumer = 0;
			virtYdenom = 1;
			grafErrValue = c_VirtualR + c_NullRect;
			nuGrafErr(grafErrValue);
		}
		else
		{
			virtYround = virtYdenom >> 1;
		}
	}

	/* virt does not use port mins */	
	virtXconst = inpPort->portOrgn.X;

	if (inpPort->portFlags & pfUpper)
	{	/* upper left */
		virtYconst = inpPort->portOrgn.Y;
		localYinvert = 0;
	}
	else
	{
		virtYconst = inpPort->portOrgn.Y + inpPort->portRect.Ymax - 
			inpPort->portRect.Ymin;
		localYinvert = -1;
	}

	return;
}


/* Function mwGblCoord computes coordinate conversion constants.
Derivation of constants used for coordinate transformations:

upper left:
   Yg = (Yl  - portYmin) + portoriginY =
   Yg = Yl + -portYmin + portoriginY =
   Yg = Yl + C   where C = portoriginY - portYmin

⌨️ 快捷键说明

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