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

📄 croad.cpp

📁 VC技术内幕30章以后的 书很不错的 供大家下载
💻 CPP
字号:
// CRoad.cpp: implementation of the CRoad class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "Map.h"
#include "CRoad.h"
#include "math.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CRoad, CObject)

CRoad::CRoad()
{

}

CRoad::~CRoad()
{

}

void CRoad::DrawPLines(CDC *&pDC, POINT *&pPt, int &nPoints, int &PenStyle, int &PenWidth, COLORREF &ColorIndex)
{
	int i, len;
	int num, n, m, style;
	double a, b, c;
	int dx, dy;
	CPen pen1, pen2, *pOldpen;
	BOOL bSpace = FALSE;
	LOGBRUSH br;
	POINT pt;

	int t;
	if(PenStyle==1)
		t=1;
	else if(PenStyle>1 && PenStyle<=118 && PenStyle != 63 && PenStyle != 73 && PenStyle != 74)
		t=2;
	else
		t=PenStyle;

	if(nPoints < 2)
		return;

	switch(t)
	{
	case 1:
		break;
	case 2:
//		if(PenWidth < 5)
			PenWidth = 5;
		len = 4 * PenWidth;
		style = PS_GEOMETRIC|PS_ENDCAP_FLAT | PS_JOIN_ROUND;//PS_USERSTYLE | PS_ENDCAP_FLAT;
		br.lbColor = ColorIndex;
		br.lbStyle = BS_SOLID;
		br.lbHatch = HS_DIAGCROSS;
		if(!pen1.CreatePen(style, PenWidth, &br))
			return;
//		br.lbColor = RGB( 255, 255 , 255 );// - ColorIndex;//RGB( 0, 0, 0 );//RGB(255, 255, 255);//
		if(!pen2.CreatePen(style, 3, &br))
		{
			pen1.DeleteObject();
			return;
		}
		break;
	case 63://中空线
		break;
	case 73://铁路
//		if(PenWidth < 5)
			PenWidth = 5;
		len = 4 * PenWidth;
		style = PS_GEOMETRIC|PS_ENDCAP_FLAT | PS_JOIN_ROUND;//PS_USERSTYLE | PS_ENDCAP_FLAT;
		br.lbColor = ColorIndex;
		br.lbStyle = BS_SOLID;
		br.lbHatch = HS_DIAGCROSS;
		if(!pen1.CreatePen(style, PenWidth, &br))
			return;
		br.lbColor = RGB( 255, 255 , 255 );// - ColorIndex;//RGB( 0, 0, 0 );//RGB(255, 255, 255);//
		if(!pen2.CreatePen(style, 3, &br))
		{
			pen1.DeleteObject();
			return;
		}
		break;
	case 74://铁路
//		if(PenWidth < 5)
			PenWidth = 5;
		len = 4 * PenWidth;
		style = PS_GEOMETRIC|PS_ENDCAP_FLAT | PS_JOIN_ROUND;//PS_USERSTYLE | PS_ENDCAP_FLAT;
		br.lbColor = RGB(0, 0, 0);//ColorIndex;
		br.lbStyle = BS_SOLID;
		br.lbHatch = HS_DIAGCROSS;
		if(!pen1.CreatePen(style, PenWidth, &br))
			return;
		br.lbColor = ColorIndex;//RGB( 0, 0, 0 );//RGB(255, 255, 255);//
		if(!pen2.CreatePen(style, 3, &br))
		{
			pen1.DeleteObject();
			return;
		}
		break;
	case 202://铁路
//		if(PenWidth < 5)
			PenWidth = 7;
		len = 4 * PenWidth;
		style = PS_GEOMETRIC|PS_ENDCAP_FLAT | PS_JOIN_ROUND;//PS_USERSTYLE | PS_ENDCAP_FLAT;
		br.lbColor = RGB(0, 0, 0);//ColorIndex;
		br.lbStyle = BS_SOLID;
		br.lbHatch = HS_DIAGCROSS;
		if(!pen1.CreatePen(style, PenWidth, &br))
			return;
		br.lbColor = ColorIndex;//RGB( 0, 0, 0 );//RGB(255, 255, 255);//
		if(!pen2.CreatePen(style, 3/*PenWidth - 8*/, &br))
		{
			pen1.DeleteObject();
			return;
		}
		break;
	}

	switch(t)
	{
	case 1:
		break;
	case 2:
		break;
	case 63://中空线
		if(PenWidth < 3)
			PenWidth = 3;
		style = PS_GEOMETRIC|PS_ENDCAP_ROUND | PS_JOIN_ROUND;//PS_USERSTYLE | PS_ENDCAP_FLAT;
		br.lbColor = ColorIndex;
		br.lbStyle = BS_SOLID;
		br.lbHatch = HS_DIAGCROSS;
		if(!pen1.CreatePen(style, PenWidth, &br))
			return;
		pOldpen = pDC->SelectObject( &pen1 );

		pDC->Polyline(pPt, nPoints);

		n = PenWidth - 2;
		if( n > 0 )
		{
			br.lbColor = RGB( 255, 255, 255 );
			pen1.DeleteObject();
			if(!pen1.CreatePen(style, n, &br))
			{
				pDC->SelectObject(pOldpen);
				return;
			}
			pDC->SelectObject( &pen1 );

			pDC->Polyline(pPt, nPoints);
		}
		pDC->SelectObject(pOldpen);
		pen1.DeleteObject();
		break;

	case 73: //铁路
	case 74:
	case 202:
		pOldpen = pDC->SelectObject( &pen1 );
		pDC->Polyline( pPt, nPoints );
		pDC->SelectObject( &pen2 );

		n = len;
		for(i = 1; i < nPoints; i++)
		{
			num = 0;
			a = pPt[i].y - pPt[i - 1].y;
			b = pPt[i].x - pPt[i - 1].x;
			c = sqrt(a * a + b * b);
			m = (int)c;
			if( bSpace )
			{
				pt = pPt[ i - 1 ];
				pDC->MoveTo( pPt[ i - 1 ] );
				num = n;
			}
			else
			{
				if( m >= n )//线段长度够画实心部份
				{
					dx = (int)(b * n / c);
					dy = (int)(a * n / c);
					pt.x = pPt[ i - 1 ].x + dx;
					pt.y = pPt[ i - 1 ].y + dy;
					pDC->MoveTo( pt );
					num = n + len;
					m -= n;
					n = len;
				}
				else
				{
					n -= (int)m;
					continue;
				}
			}

			while( 1 )
			{
				if( m >= n )//线段长度够画空心部份
				{
					dx = (int)(b * num / c);
					dy = (int)(a * num / c);
					pt.x = pPt[ i - 1 ].x + dx;
					pt.y = pPt[ i - 1 ].y + dy;
					pDC->LineTo( pt );
					
					//接着是实心部份
					m -= n;
					n = len;
					num += n;
					if( m >= n )
					{
						//又接着是空心部份
						m -= n;
						dx = (int)(b * num / c);
						dy = (int)(a * num / c);
						pt.x = pPt[ i - 1].x + dx;
						pt.y = pPt[ i - 1].y + dy;
						pDC->MoveTo( pt );
						num += n;
					}
					else
					{
						bSpace = FALSE;
						n -= m;
						break;
					}

				}
				else
				{
					bSpace = TRUE;
					pDC->LineTo( pPt[ i ] );
					n -= m;
					break;
				}
			}
		}

		pDC->SelectObject(pOldpen);
		pen1.DeleteObject();
		pen2.DeleteObject();
		break;
	default:
		pDC->Polyline(pPt, nPoints);
		break;
	}
}

⌨️ 快捷键说明

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