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

📄 polygon.cpp

📁 刚上传内容的相关CODEC不能单独上传。于是
💻 CPP
字号:
// Polygon.cpp: implementation of the CPolygon class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MagicScissors.h"
#include "Polygon.h"

#include "EdgePoint.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPolygon::CPolygon()
{
	m_pNext = m_pPrev = NULL;
}

CPolygon::~CPolygon()
{

}

void CPolygon::Paint(CDC* pDC, COLORREF col)
{
	int n,i;

	n = GetLength();

	if( n == 0 ) return;

	CPen pen;
	pen.CreatePen(PS_DOT, 1, col);
	CPen* pPen = pDC->SelectObject( &pen );

	CEdgePoint* pnt;
	pnt = GetPoint(0);
	pDC->MoveTo( pnt->x, pnt->y );
	for( i = 1 ; i < n ; i++ )
	{
		pnt = GetPoint(i);
		pDC->LineTo( pnt->x, pnt->y );
	}
	pnt = GetPoint(0);
	pDC->LineTo( pnt->x, pnt->y );

	pDC->SelectObject( pPen );
}

void CPolygon::Move(int dx, int dy)
{
	CEdgePoint* pEdge = m_pRoot;

	while(pEdge)
	{
		pEdge->x += dx;
		pEdge->y += dy;
		pEdge = pEdge->m_pNext;
	}
}

void CPolygon::MakeRgn()
{
	int n = GetLength();
	if( n == 0 ) return;

	CPoint* point = new CPoint[n];

	CEdgePoint* pPoint = m_pRoot;

	for( int i = 0 ; i < n ; i++ )
	{
		point[i] = *pPoint;
		pPoint = pPoint->m_pNext;
	}

	if( m_Rgn.m_hObject )
		m_Rgn.DeleteObject();
	
	m_Rgn.CreatePolygonRgn( point, n, WINDING );
	delete [] point;

}

BOOL CPolygon::PtInRgn(CPoint pnt)
{
	if( m_Rgn.m_hObject )
		return m_Rgn.PtInRegion(pnt);
	else
		return FALSE;
}

void CPolygon::Set(CEdgeList* pList)
{
	int n = pList->GetLength();

	CPoint pt;
	for( int i = 0 ; i < n ; i += 3 )
	{
		pt = *(pList->GetPoint(i));
		AddPoint(pt);
	}
}

⌨️ 快捷键说明

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