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

📄 byangtiaoview.cpp

📁 b样条插值
💻 CPP
字号:
// byangtiaoView.cpp : implementation of the CByangtiaoView class
//

#include "stdafx.h"
#include "byangtiao.h"

#include "byangtiaoDoc.h"
#include "byangtiaoView.h"
#include "Setdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CByangtiaoView

IMPLEMENT_DYNCREATE(CByangtiaoView, CView)

BEGIN_MESSAGE_MAP(CByangtiaoView, CView)
	//{{AFX_MSG_MAP(CByangtiaoView)
	ON_COMMAND(ID_BYANGTIAO, OnByangtiao)
	ON_WM_LBUTTONDOWN()
	ON_COMMAND(ID_BYANGTIAOCOLOR, OnByangtiaocolor)
	ON_COMMAND(ID_BYANGTIAOZHIXIAN, OnByangtiaozhixian)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CByangtiaoView construction/destruction

CByangtiaoView::CByangtiaoView()
{
	// TODO: add construction code here
m_fixpoint=0;
m_totalpoint=5;
m_point=new CPoint[m_totalpoint];
for(int i=0;i<m_totalpoint;i++)
{
m_point[i]=(0,0);

}

m_colorline.rgbResult=RGB(0,255,0);
m_colorcurve.rgbResult=RGB(0,0,0);



}

CByangtiaoView::~CByangtiaoView()
{
	delete [] m_point;
	m_point=NULL;	
}

BOOL CByangtiaoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CByangtiaoView drawing

void CByangtiaoView::OnDraw(CDC* pDC)
{
	CByangtiaoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CString str;
str.Format("%s%d%s","左击取",m_totalpoint,"点");
	pDC->TextOut(100,50,str);
	CBrush brush;
	brush.CreateSolidBrush(RGB(255, 0, 125));
	for(int i=0;i<m_totalpoint;i++)
	{
		int a=3;
		pDC->SelectObject(&brush);
		if((m_point[i].x!=0)&&(m_point[i].y!=0))
			pDC->Ellipse(m_point[i].x-a,m_point[i].y-a,m_point[i].x+a,m_point[i].y+a);
	}
if(m_fixpoint==m_totalpoint)
	{
		int x,y;
		CPen * pOldPen;
		CPen pen1(1,1,m_colorline.rgbResult);
		pOldPen=pDC->SelectObject(&pen1);
		pDC->MoveTo(m_point[0]);
		for(i=1;i<m_totalpoint;i++)
			pDC->LineTo(m_point[i]);
		CPen pen2(0,1,m_colorcurve.rgbResult);
		pDC->SelectObject(&pen2);
		for(i=0;i<m_totalpoint-2;i++)
		{
			x=0.5*(m_point[i+0].x+m_point[i+1].x);
			y=0.5*(m_point[i+0].y+m_point[i+1].y);
			pDC->MoveTo(x,y);
			for(float t=0;t<1;t+=0.01)
			{
				x=0.5*(1-t)*(1-t)*m_point[i+0].x+0.5*((-2)*t*t+2*t+1)*m_point[i+1].x+0.5*t*t*m_point[i+2].x;
				y=0.5*(1-t)*(1-t)*m_point[i+0].y+0.5*((-2)*t*t+2*t+1)*m_point[i+1].y+0.5*t*t*m_point[i+2].y;
				pDC->LineTo(x,y);
			}
		}
		pDC->SelectObject(pOldPen);
	}

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CByangtiaoView printing

BOOL CByangtiaoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CByangtiaoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CByangtiaoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CByangtiaoView diagnostics

#ifdef _DEBUG
void CByangtiaoView::AssertValid() const
{
	CView::AssertValid();
}

void CByangtiaoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CByangtiaoDoc* CByangtiaoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CByangtiaoDoc)));
	return (CByangtiaoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CByangtiaoView message handlers

void CByangtiaoView::OnByangtiao() 
{
	// TODO: Add your command handler code here
	CSetdlg dlg;
	
//dlg.DoModal();
dlg.m_totalpoint=m_totalpoint;
	if(dlg.DoModal())
	{
		m_totalpoint=dlg.m_totalpoint;
	}
	delete [] m_point;
	m_point=new CPoint[m_totalpoint];
	Intital();
	Invalidate(true);

}

void CByangtiaoView::Intital()
{
m_fixpoint=0;
	for(int i=0;i<m_totalpoint;i++)
	{
		m_point[i]=(0,0);
	}
}

void CByangtiaoView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_fixpoint<m_totalpoint)
	{
		
		m_point[m_fixpoint]=point;
		m_fixpoint++;
	}
	else if(m_fixpoint==m_totalpoint)
	{
		for(int i=0;i<m_totalpoint;i++)
			m_point[i]=(0,0);
		m_fixpoint=0;
		m_point[m_fixpoint]=point;
		m_fixpoint=1;
	}
	Invalidate(true);
	CView::OnLButtonDown(nFlags, point);
}

void CByangtiaoView::OnByangtiaocolor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg;
	dlg.m_cc.rgbResult=m_colorcurve.rgbResult;
	if(dlg.DoModal())
	{
		CHOOSECOLOR a=dlg.m_cc;
		m_colorcurve.rgbResult=a.rgbResult;
	}
	Invalidate(true);
}

void CByangtiaoView::OnByangtiaozhixian() 
{
	// TODO: Add your command handler code here
		CColorDialog dlg;
	dlg.m_cc.rgbResult=m_colorline.rgbResult;
	if(dlg.DoModal())
	{
		CHOOSECOLOR a=dlg.m_cc;
		m_colorline.rgbResult=a.rgbResult;
	}
	Invalidate(true);
}

⌨️ 快捷键说明

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