www.pudn.com > ZhuYouyong.rar > ZhuYouyongView.cpp


// ZhuYouyongView.cpp : implementation of the CZhuYouyongView class 
// 
 
#include "stdafx.h" 
#include "ZhuYouyong.h" 
 
#include "Graph.h" 
#include "math.h" 
 
#include "ZhuYouyongDoc.h" 
#include "ZhuYouyongView.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CZhuYouyongView 
 
IMPLEMENT_DYNCREATE(CZhuYouyongView, CView) 
 
BEGIN_MESSAGE_MAP(CZhuYouyongView, CView) 
	//{{AFX_MSG_MAP(CZhuYouyongView) 
	ON_WM_LBUTTONDOWN() 
	ON_WM_LBUTTONUP() 
	ON_WM_MOUSEMOVE() 
	ON_WM_RBUTTONDOWN() 
	ON_WM_RBUTTONUP() 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CZhuYouyongView construction/destruction 
 
CZhuYouyongView::CZhuYouyongView() 
{ 
	// TODO: add construction code here 
    m_drag=0; 
	m_hcursor=AfxGetApp()->LoadStandardCursor(IDC_CROSS); 
    nnnn=0; //spline 
 
	cnt=1;      //fill 
	for(int i=0;iIsKindOf(RUNTIME_CLASS(CZhuYouyongDoc))); 
	return (CZhuYouyongDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CZhuYouyongView message handlers 
 
void CZhuYouyongView::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CGraph dc(this);             //距离 
	OnPrepareDC(&dc); 
	dc.DPtoLP(&point); 
	m_prev=point; 
	m_origin=point; 
    SetCapture(); 
	m_drag=1; 
	RECT rect; 
	GetClientRect(&rect);          //得到当前窗口的一个数据 
	ClientToScreen(&rect); 
	ClipCursor(&rect); 
//dc.TextOut(m_origin.x,m_origin.y,"I really want to fuck you more!"); 
//dc.DDAline(1020,645,m_origin.x,m_origin.y); 
 
CZhuYouyongDoc *pDoc=GetDocument(); 
switch(pDoc->CurrentDrawTool) 
{ 
  case ID_DRAW_nono: 
                     dc.SetROP2(R2_NOT); 
                     dc.huatu(m_origin); 
                     nono=1; 
                     break; 
  case ID_DRAW_temporary: 
	  dc.SetROP2(R2_NOT); 
	                 dc.draw3dline(m_origin); 
					 temporary=1; 
	                  break; 
 
} 
 
	CView::OnLButtonDown(nFlags, point); 
} 
 
void CZhuYouyongView::OnLButtonUp(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CGraph dc(this);             //距离 
	OnPrepareDC(&dc); 
	dc.DPtoLP(&point); 
	//if(GetCapture()==this) 
	ReleaseCapture(); 
	ClipCursor(NULL); 
    m_drag=0; 
 
//***********************************//立体图形 
 Point3D n2,n5,n8; 
 CPoint c1,c2,c3,e1,e2,e3; 
 double r,l,h,o,z; 
 z=350; 
 n2.x=0;n2.y=0;n2.z=zuobiao;n5.x=zuobiao;n5.y=0;n5.z=0;n8.x=0;n8.y=zuobiao;n8.z=0; 
 r=sqrt(point.x*point.x+point.y*point.y+z*z); 
 l=200;h=point.x*360/1020;o=point.y*360/645; 
 c1=dc.PTrans(n2,l,r,h,o);c2=dc.PTrans(n5,l,r,h,o);c3=dc.PTrans(n8,l,r,h,o); 
 e1=dc.clip3dline(n2,n2,point);e2=dc.clip3dline(n5,n5,point);e3=dc.clip3dline(n8,n8,point); 
//**************************************// 
 
 
	if(mmmm==1) 
	{ 
		good=m_origin; 
		nnnn++; 
	} 
 
	if(fill==1) 
	{ 
		if(cnt==1) 
			shuzhu[0]=m_origin; 
		cnt++; 
		if(cnt<=15) 
		{ 
			shuzhu[cnt-1]=point; 
			oo=point; 
		} 
	} 
 
	if(nono==1)    //立体图形 
	{ 
		dc.TextOut(c1.x+400+15,c1.y+200,"z"); 
		dc.TextOut(c2.x+400+15,c2.y+200,"x"); 
		dc.TextOut(c3.x+400+15,c3.y+200,"y"); 
		nono=0; 
	} 
 
	if(temporary==1)    //立体图形 
	{ 
		dc.TextOut(e1.x+10,e1.y,"z"); 
		dc.TextOut(e2.x+10,e2.y,"x"); 
		dc.TextOut(e3.x+10,e3.y,"y"); 
		temporary=0; 
	} 
 
	CView::OnLButtonUp(nFlags, point); 
} 
 
void CZhuYouyongView::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CGraph dc(this);             //距离 
	OnPrepareDC(&dc); 
	dc.DPtoLP(&point); 
	SetCursor(m_hcursor);            //十字光标 
 
	CZhuYouyongDoc *pDoc=GetDocument(); 
    int go=(int)(chad/sqrt(2));  
	if(m_drag) 
	{ 
		switch(pDoc->CurrentDrawTool) 
		{ 
         
		case ID_DRAW_oval:dc.SetROP2(R2_NOT); 
			              dc.oval(m_origin.x,m_origin.y,m_prev.x,m_prev.y); 
	                      dc.oval(m_origin.x,m_origin.y,point.x,point.y); 
						  m_prev=point; 
						  nnnn=0;mmmm=0;   //曲线重新开始! 
						  fill=0; 
						  break; 
        case ID_DRAW_spline:mmmm=1; 
							if(nnnn>0) 
							{dc.SetROP2(R2_NOT); 
							 dc.spline(good.x,good.y,m_origin.x,m_origin.y,m_prev.x,m_prev.y); 
							 dc.spline(good.x,good.y,m_origin.x,m_origin.y,point.x,point.y); 
							 m_prev=point; 
							} 
                           fill=0; 
							break; 
		 
		case ID_DRAW_fill: 
			              nnnn=0;mmmm=0;   //曲线重新开始! 
						   
						  fill=1; 
						  if(cnt==1) 
						  { 
							  dc.SetROP2(R2_NOT); 
							  dc.DDAline(m_origin.x,m_origin.y,m_prev.x,m_prev.y); 
							  dc.DDAline(m_origin.x,m_origin.y,point.x,point.y); 
							  m_prev=point; 
						  } 
						  else 
						  { 
							  dc.SetROP2(R2_NOT); 
							  dc.DDAline(oo.x,oo.y,m_prev.x,m_prev.y); 
							  dc.DDAline(oo.x,oo.y,point.x,point.y); 
							  m_prev=point; 
						  } 
 
			              break; 
 
		case ID_DRAW_vcline:dc.SetROP2(R2_NOT);   //R2_NOT 象素与屏幕颜色相反 
			                dc.MoveTo(m_origin); 
		                    dc.LineTo(m_prev); 
		                    dc.MoveTo(m_origin); 
		                    dc.LineTo(point); 
						    m_prev=point; 
							nnnn=0;mmmm=0;//曲线重新开始! 
							fill=0;			 
							break; 
		case ID_DRAW_ddaline:dc.SetROP2(R2_NOT); //异或画线,将下面的一条直线擦掉。 
			                 dc.DDAline(m_origin.x,m_origin.y,m_prev.x,m_prev.y); 
                             dc.DDAline(m_origin.x,m_origin.y,point.x,point.y); 
			                 m_prev=point;    
							 nnnn=0;mmmm=0; //曲线重新开始! 
							 fill=0; 
							 break; 
		case ID_DRAW_bresenhamline:dc.SetROP2(R2_NOT); 
		                           dc.bresenhamline(m_origin.x,m_origin.y,m_prev.x,m_prev.y); 
			                       dc.bresenhamline(m_origin.x,m_origin.y,point.x,point.y); 
			                       m_prev=point; 
								   nnnn=0;mmmm=0;   //曲线重新开始! 
			                       fill=0; 
								   break; 
		case ID_DRAW_bresenhamcircle:dc.SetROP2(R2_NOT); 
			                         dc.bresenham_circle(m_origin.x,m_origin.y,m_prev.x,m_prev.y); 
									 dc.bresenham_circle(m_origin.x,m_origin.y,point.x,point.y); 
									 m_prev=point; 
									 nnnn=0;mmmm=0;      //曲线重新开始! 
		                             fill=0; 
									 break; 
		case ID_DRAW_nono: 
			      dc.SetROP2(R2_NOT); 
				  dc.huatu(m_origin); 
				  dc.huatu(point); 
                  m_origin=point; 
				  nnnn=0;mmmm=0;      //曲线重新开始! 
		          fill=0; 
                  break; 
		case ID_DRAW_temporary: 
	                 dc.SetROP2(R2_NOT); 
					 dc.draw3dline(m_origin); 
					 dc.draw3dline(point); 
                     m_origin=point; 
				     nnnn=0;mmmm=0;      //曲线重新开始! 
		             fill=0; 
	                 break; 
		} 
	} 
 
	CView::OnMouseMove(nFlags, point); 
} 
 
 
 
 
void CZhuYouyongView::OnRButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	nnnn=0; 
 
	CView::OnRButtonDown(nFlags, point); 
} 
 
void CZhuYouyongView::OnRButtonUp(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	CGraph dc(this); 
    if(fill==1) 
	{ 
		dc.areafill(cnt,shuzhu); 
		cnt=1; 
		for(int i=0;i