📄 convexhullview.cpp
字号:
// ConvexHullView.cpp : implementation of the CConvexHullView class
//
#include "stdafx.h"
#include "ConvexHull.h"
#include "ConvexHullDoc.h"
#include "ConvexHullView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConvexHullView
IMPLEMENT_DYNCREATE(CConvexHullView, CView)
BEGIN_MESSAGE_MAP(CConvexHullView, CView)
//{{AFX_MSG_MAP(CConvexHullView)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_DISCONHUL, OnDisconhul)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConvexHullView construction/destruction
CConvexHullView::CConvexHullView()
{
// TODO: add construction code here
m_Find=false;
}
CConvexHullView::~CConvexHullView()
{
}
BOOL CConvexHullView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CConvexHullView drawing
void CConvexHullView::OnDraw(CDC* pDC)
{
CConvexHullDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBrush *brush=new CBrush(RGB(255,0,0));
CBrush *oldbrush=pDC->SelectObject(brush);
// TODO: add draw code for native data here
pDC->Ellipse(pDoc->m_Center.x-4,pDoc->m_Center.y-4,pDoc->m_Center.x+4,pDoc->m_Center.y+4);
for(int i=0;i<pDoc->m_PointsOriginal.size();i++)
{
pDC->Ellipse(pDoc->m_PointsOriginal[i].x-3,pDoc->m_PointsOriginal[i].y-3,pDoc->m_PointsOriginal[i].x+3,pDoc->m_PointsOriginal[i].y+3);
}
if(m_Find){
MyPoint *cur=pDoc->m_Link.m_First;
while(cur){
pDC->MoveTo(cur->p);
if(cur->right)
pDC->LineTo(cur->right->p);
cur=cur->right;
}
pDC->MoveTo(pDoc->m_Link.Back()->p);
pDC->LineTo(pDoc->m_Link.m_First->p);
}
pDC->SelectObject(oldbrush);
}
/////////////////////////////////////////////////////////////////////////////
// CConvexHullView diagnostics
#ifdef _DEBUG
void CConvexHullView::AssertValid() const
{
CView::AssertValid();
}
void CConvexHullView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CConvexHullDoc* CConvexHullView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CConvexHullDoc)));
return (CConvexHullDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CConvexHullView message handlers
void CConvexHullView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CConvexHullDoc* pDoc=GetDocument();
MyPoint *NewPoint=new MyPoint;
NewPoint->p=point;
pDoc->m_Link.Append(*NewPoint);
pDoc->m_PointsOriginal.push_back(point);
m_Find=false;
pDoc->SetModifiedFlag(true);//刷新屏幕
pDoc->UpdateAllViews(NULL);
//CView::OnLButtonDown(nFlags, point);
}
void CConvexHullView::OnDisconhul()
{
// TODO: Add your command handler code here
CConvexHullDoc* pDoc=GetDocument();
if(pDoc->m_Link.Length()>=3){
pDoc->PointsSort();
int len;
do{
len=pDoc->m_Link.Length();
pDoc->Search();
}while(len!=pDoc->m_Link.Length());
}
m_Find=true;
pDoc->SetModifiedFlag(true);//刷新屏幕
pDoc->UpdateAllViews(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -