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

📄 drawview.cpp

📁 希望大家多多交流
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// drawView.cpp : implementation of the CDrawView class
//

#include "stdafx.h"
#include "draw.h"

#include "drawDoc.h"
#include "drawView.h"
#include <math.h>
#include "questiondialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDrawView

IMPLEMENT_DYNCREATE(CDrawView, CScrollView)

BEGIN_MESSAGE_MAP(CDrawView, CScrollView)
	//{{AFX_MSG_MAP(CDrawView)
	ON_COMMAND(ID_BUTTON32771, OnButton32771)
	ON_COMMAND(ID_BUTTON32772, OnButton32772)
	ON_COMMAND(ID_BUTTON32773, OnButton32773)
	ON_COMMAND(ID_BUTTON32774, OnButton32774)
	ON_COMMAND(ID_BUTTON32775, OnButton32775)
	ON_COMMAND(ID_BUTTON32776, OnButton32776)
	ON_COMMAND(ID_BUTTON32777, OnButton32777)
	ON_COMMAND(ID_BUTTON32778, OnButton32778)
	ON_COMMAND(ID_BUTTON32779, OnButton32779)
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_ZOOMUP, OnZoomup)
	ON_COMMAND(ID_VIEW_QUESTION, OnViewQuestion)
	ON_COMMAND(ID_VIEW_SHRINK, OnViewShrink)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDrawView construction/destruction

CDrawView::CDrawView()
{
	// TODO: add construction code here

}

CDrawView::~CDrawView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDrawView drawing

void CDrawView::OnDraw(CDC* pDC)
{	//建立一个透明的画刷并选入CDC中
	LOGBRUSH lpLogBrush;//画刷结构
	lpLogBrush.lbStyle=BS_HOLLOW;//画刷结构属性为透明
	CBrush mybrush;
	mybrush.CreateBrushIndirect(&lpLogBrush);
	pDC->SelectObject(mybrush );
	//画刷选取
	if(haveselectpoint==1){displayselectpoint(selectpoint1,pDC);}//如果己选择了一个点则显示此点
	if(haveselectpoint==2){displayselectpoint(selectpoint1,pDC);displayselectpoint(selectpoint2,pDC);}//如果己选择了两个点则显示此两点
	CDrawDoc* pDoc = GetDocument();	
	POSITION pos = pDoc->mygraph.GetHeadPosition();
	for (int i=0;i < pDoc->mygraph.GetCount();i++)
	{thegraph& pthegraph=pDoc->mygraph.GetNext(pos);     
		switch(pthegraph.type)//根据图形对象类型来画
		{case 1:
			{//如果为一点则画此点(包括临时的点)
			pDC->Ellipse(pthegraph.point1.x-2,pthegraph.point1.y-2,pthegraph.point1.x+2,pthegraph.point1.y+2);
			break;
			}
		 case 2:
			{//如果为直线则画两个端点和一条连线
			pDC->Ellipse(pthegraph.point1.x-2,pthegraph.point1.y-2,pthegraph.point1.x+2,pthegraph.point1.y+2);
			pDC->Ellipse(pthegraph.point2.x-2,pthegraph.point2.y-2,pthegraph.point2.x+2,pthegraph.point2.y+2);
			pDC->MoveTo(pthegraph.point1);
			pDC->LineTo(pthegraph.point2);
			break;
			}			
		 case 3:
			{//如果为圆则画圆心和圆外那一点和圆圈
			pDC->Ellipse(pthegraph.point1.x-2,pthegraph.point1.y-2,pthegraph.point1.x+2,pthegraph.point1.y+2);
			pDC->Ellipse(pthegraph.point2.x-2,pthegraph.point2.y-2,pthegraph.point2.x+2,pthegraph.point2.y+2);
			int x1,x2,y1,y2,r;
			x1=pthegraph.point1.x;
			x2=pthegraph.point2.x;
			y1=pthegraph.point1.y;
			y2=pthegraph.point2.y;
			r=(int)sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
			pDC->Ellipse(pthegraph.point1.x-r,pthegraph.point1.y-r,pthegraph.point1.x+r,pthegraph.point1.y+r);
			break;
			}			
		 default:break;
		}
	}
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}
void CDrawView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();	
	// TODO: calculate the total size of this view
	CDrawDoc* pDoc = GetDocument();
	fitsize=FALSE;
	haveselectpoint=0;//尚未选择点
	zoomnum=pDoc->windowsSize.cx/512;//计算放大的倍数
	SetScrollSizes(MM_TEXT, pDoc->windowsSize);//设置窗口尺寸完毕
	ScrollToPosition(CPoint(pDoc->windowsSize.cx/2-512,pDoc->windowsSize.cy/2-384));//将起始位置设为纸的中间完毕
}
/////////////////////////////////////////////////////////////////////////////
// CDrawView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDrawView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDrawView message handlers

void CDrawView::OnButton32771() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21)pDoc->mygraph.RemoveTail();//去掉临时点
	index=10;
}

void CDrawView::OnButton32772() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=20;
	
}

void CDrawView::OnButton32773() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=30;
}

void CDrawView::OnButton32774() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=40;
}

void CDrawView::OnButton32775() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=50;
}

void CDrawView::OnButton32776() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=60;
}

void CDrawView::OnButton32777() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=70;
}

void CDrawView::OnButton32778() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=80;
}

void CDrawView::OnButton32779() 
{
	// TODO: Add your command handler code here
	CDrawDoc* pDoc = GetDocument();
	if(index==21||index==11)pDoc->mygraph.RemoveTail();//去掉临时点
	index=90;
}

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CDrawDoc* pDoc = GetDocument();
	if(fitsize)//如果是在缩图状态下则必须先恢复一般状态
	{
		fitsize=FALSE;
		RECT rect;
		GetClientRect(&rect);//取客户区域大小放入rect中
		SetScrollSizes(MM_TEXT,pDoc->windowsSize);
		//下面几句将刚才点击的位置设为视图的中心
		POINT viewpoint;
		viewpoint.x=point.x*pDoc->windowsSize.cx/(rect.right-rect.left)-(rect.right-rect.left)/2;
		viewpoint.y=point.y*pDoc->windowsSize.cy/(rect.bottom-rect.top)-(rect.bottom-rect.top)/2;
		ScrollToPosition(viewpoint);
	}
	else
	{//将point的值由设备坐标转换为逻辑坐标
	CClientDC dc(this);
	OnPrepareDC(&dc);
	dc.DPtoLP(&point);
	//转换完毕
	switch(index)
	{
	case 10:{tonearbypoint(point);//转移到己有的邻近点上	
			pDoc->mygraph.AddTail(thegraph(point));
			index=11;
			pDoc->UpdateAllViews(NULL);
			}
			break;
	case 11:{tonearbypoint(point);//转移到己有的邻近点上	
			pDoc->mygraph.GetTail().point2=point;
			pDoc->mygraph.GetTail().type=2;
			index=10;
			pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
			pDoc->UpdateAllViews(NULL);
			}
			break;
	case 20:{tonearbypoint(point);//转移到己有的邻近点上	
			pDoc->mygraph.AddTail(thegraph(point));
			index=21;
			pDoc->UpdateAllViews(NULL);
			}
			break;
	case 21:{tonearbypoint(point);//转移到己有的邻近点上	
			pDoc->mygraph.GetTail().point2=point;
			pDoc->mygraph.GetTail().type=3;
			index=20;
			pDoc->SetModifiedFlag( );//每产生一个对象设置一次文档改动标签
			pDoc->UpdateAllViews(NULL);
			}
			break;
	case 30:{if(!tonearbypoint(point))AfxMessageBox("你只能选择一个己有的点!",MB_ICONERROR);
			else{selectpoint1=point;
				haveselectpoint=1;//设置选中一个点标识

⌨️ 快捷键说明

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