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

📄 line8.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/*         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          */
/*                                                                       */
/*      LINE8.c                                          1.9             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      All                                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the mwOPL function.                           */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Robert G. Burrill, Accelerated Technology, Inc.                  */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*         BobB           5/11/99     Corrected oval line drawing        */
/*                                                                       */
/*************************************************************************/

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


/* Oval poly lines are constructed via regions. Regions defining the line, end
caps, and joins are captured then painted via PaintRegion(). The line portion
is constructed by a polygon whose vertices are computed by finding the points
on a circle defining the round pen at angles perpendicular to the line
eminating from the center of the circle.

Current Restrictions:
 1) lines are forced to round, using the larger of the two pen dimensions
 2) Dashes not supported
 3) capSquare not supported - does capFlat instead	
 4) joinMiter not supported - does joinBevel no matter what miterlimit	
 5) doesn't xor correctly, use region capture to do this */

void mwOPL(short numpoints, point *points)
{
/* BobB 5/13/99 - corrected the following line
	int PtToAngle(); */
	long PtToAngle(rect * R, point * PT);
	void OvalPt(rect *argR, int angle, point *gblPt);
	void PaintOval(rect *argR);
	int halfmin;
	int halfmax;
 	int ptcount;
 	int ptcount1;
	rect bb1;
	rect bb2;
	int capstyle;
	int joinstyle;
	int angle;
	int angleP90;
	int angleM90;
	point lpoly[5];
	point lastpoly[5];
	void FillPolygon(point *pointsparm, unsigned int npointsparm,
		int modeparm, int shape);

	if (numpoints < 2) return;	/* must have at least two points */
	if (grafPort.pnLevel >= 0)	/*	if (grafPort.pnLevel < 0), exit */
	{
		/* pickup cap and join style */
		capstyle = grafPort.pnCap;
		joinstyle = grafPort.pnJoin;

		/* compute pen dimensions, force to round pen */
		if (grafPort.pnSize.Y > grafPort.pnSize.X)
		{
			halfmin = grafPort.pnSize.Y >> 1;
			halfmax = (grafPort.pnSize.Y + 1) >> 1;
		}
		else
		{
			halfmin = grafPort.pnSize.X >> 1;
			halfmax = (grafPort.pnSize.X + 1) >> 1;
		}

/* BobB 5/11/99 - corrected to following to simplify the counter
		for (ptcount=0; ptcount<(numpoints-1); ptcount++) */
		numpoints--;	/* decrement the index value for later */
		for (ptcount=0; ptcount<numpoints; ptcount++)
		{
			/* compute bounding box for this point */
			bb1.Xmin = points[ptcount].X - halfmin;
			bb1.Xmax = points[ptcount].X + halfmax;
			bb1.Ymin = points[ptcount].Y - halfmin;
			bb1.Ymax = points[ptcount].Y + halfmax;

			/* compute bounding box for next point */
			ptcount1 = ptcount + 1;
			bb2.Xmin = points[ptcount1].X - halfmin;
			bb2.Xmax = points[ptcount1].X + halfmax;
			bb2.Ymin = points[ptcount1].Y - halfmin;
			bb2.Ymax = points[ptcount1].Y + halfmax;

			/* compute polygon describing line with flat caps */

			/* compute angle of line eminating from this vertice */
/* BobB 5/13/99 - corrected the following line for return value
			angle = PtToAngle(&bb1, &points[ptcount1]); */
			angle = (int) PtToAngle(&bb1, &points[ptcount1]);
			/* compute angles +- 90 from this angle */
			angleP90 = angle + 900;
			angleM90 = angle - 900;

			/* compute points on oval at those angles - 
			these should be the tangent points */
			OvalPt(&bb1, angleP90, &lpoly[0]);
			OvalPt(&bb1, angleM90, &lpoly[3]);

			/* compute angle of line eminating from next vertice */
/* BobB 5/11/99 - corrected the following line to get the correct point
	and return value
			angle = PtToAngle(&bb1, &points[ptcount]); */
			angle = (int) PtToAngle(&bb2, &points[ptcount]);
			/* compute angles +- 90 from this angle */
			angleP90 = angle + 900;
			angleM90 = angle - 900;

			/* compute points on oval at those angles - 
			these should be the tangent points */
			OvalPt(&bb2, angleP90, &lpoly[2]);
/* BobB 5/11/99 - corrected the following line to get the correct point
			OvalPt(&bb2, angleM90, &lpoly[4]); */
			OvalPt(&bb2, angleM90, &lpoly[1]);

			/* draw the polygon */
			FillPolygon(&lpoly[0], 4, coordModeOrigin, convex);

			/* if this is the first point, cap it, otherwise join it */
			if(ptcount == 0)
			{
				if (capstyle == capRound)
				{
					PaintOval(&bb1);
				}
			}
			else
			{
				switch (joinstyle)
				{
				case joinRound:
					PaintOval(&bb1);
					break;
				case joinMiter:
				case joinBevel:
					/* fill a polygon connecting the last flat cap to the new */
					lastpoly[1].X = lpoly[0].X;
					lastpoly[1].Y = lpoly[0].Y;
 					lastpoly[3].X = lpoly[3].X;
					lastpoly[3].Y = lpoly[3].Y;
					FillPolygon(&lastpoly[0], 4, coordModeOrigin, convex);
					break;
				}
			}

			/* remember the end of this segment as "last" one */
			lastpoly[0].X = lpoly[1].X;
			lastpoly[0].Y = lpoly[1].Y;
			lastpoly[2].X = lpoly[2].X;
			lastpoly[2].Y = lpoly[2].Y;
		}

		/* cap the last point */
		if (capstyle == capRound)
		{
			PaintOval(&bb2);
		}
	}
	
	grafPort.pnLoc.X = points[numpoints].X;	/* update user pen location */
	grafPort.pnLoc.Y = points[numpoints].Y;
	thePort->pnLoc.X = points[numpoints].X;
	thePort->pnLoc.Y = points[numpoints].Y;

	if (globalLevel > 0)
	{
		/* convert from user to global */
		U2GP(points[numpoints].X, points[numpoints].Y, &LocX, &LocY, 1);
	}
	else
	{
		LocX = points[numpoints].X;			/* update global pen location */
		LocY = points[numpoints].Y;
	}
	return;
}

⌨️ 快捷键说明

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