www.pudn.com > fbh_bezier.rar > bezierView.cpp
// bezierView.cpp : implementation of the CBezierView class
//
#include "stdafx.h"
#include "bezier.h"
#include "bezierDoc.h"
#include "bezierView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBezierView
IMPLEMENT_DYNCREATE(CBezierView, CView)
BEGIN_MESSAGE_MAP(CBezierView, CView)
//{{AFX_MSG_MAP(CBezierView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBezierView construction/destruction
CBezierView::CBezierView()
{
// TODO: add construction code here
}
CBezierView::~CBezierView()
{
}
BOOL CBezierView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBezierView drawing
void CBezierView::OnDraw(CDC* pDC)
{
CBezierDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPoint controlPt[7];
controlPt[0].x = 0; controlPt[0].y = 0;
controlPt[1].x = 100; controlPt[1].y = 100;
controlPt[2].x = 200; controlPt[2].y = 300;
controlPt[3].x = 300; controlPt[3].y = 500;
controlPt[4].x = 400; controlPt[4].y = 300;
controlPt[5].x = 500; controlPt[5].y = 200;
controlPt[6].x = 600; controlPt[6].y = 0;
Decst(controlPt, 7);
Draw(controlPt, 7);
}
/////////////////////////////////////////////////////////////////////////////
// CBezierView diagnostics
#ifdef _DEBUG
void CBezierView::AssertValid() const
{
CView::AssertValid();
}
void CBezierView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBezierDoc* CBezierView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBezierDoc)));
return (CBezierDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBezierView message handlers
void CBezierView::Draw(CPoint point[], int n)
{
CDC *pDC = GetDC();
/*::GetClientRect(pWnd->m_hWnd, m_rect);*/
pDC->SelectStockObject(NULL_BRUSH);
pDC->Polyline(point, n);
ReleaseDC(pDC);
}
void CBezierView::Decst(CPoint point[], int n)
{
CPoint curvePoint[101];
// 控制顶点的两个端点作为BEZIER曲线的端点
curvePoint[0].x = point[0].x;
curvePoint[0].y = point[0].y;
curvePoint[100].x = point[n-1].x;
curvePoint[100].y = point[n-1].y;
// 动态生成一个和控制顶点个数一样大的点数组,用于后面的操作
CPoint *tempPt = new CPoint[n];
int temp = 1;
// 不同比例求得不同的BEZIER曲线上的点
for(int radio=1; radio<100; radio++)
{
int m = n;
// 将控制顶点元素全部赋值给动态生成的点数组
for(int k=0; k