📄 raulview.cpp
字号:
// raulView.cpp : implementation of the CRaulView class
//
#include "stdafx.h"
#include "raul.h"
#include "math.h"
#include "raulDoc.h"
#include "raulView.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRaulView
IMPLEMENT_DYNCREATE(CRaulView, CView)
BEGIN_MESSAGE_MAP(CRaulView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CRaulView)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_MENU_DISPLAY, OnMenuDisplay)
//ON_COMMAND(ID_EDIT_CUT, OnEditCut)
//}}AFX_MSG_MAP
// Standard printing commands
//ON_COMMAND(ID_MENU_REFRESH, OnMenuRefresh)
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()
/////////////////////////////////////////////////////////////////////////////
// CRaulView construction/destruction
CRaulView::CRaulView()
{
// TODO: add construction code here
b=false;i=0;
}
CRaulView::~CRaulView()
{
}
BOOL CRaulView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CRaulView drawing
void CRaulView::OnDraw(CDC* pDC)
{
CRaulDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CRaulView printing
BOOL CRaulView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CRaulView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CRaulView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CRaulView diagnostics
#ifdef _DEBUG
void CRaulView::AssertValid() const
{
CView::AssertValid();
}
void CRaulView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CRaulDoc* CRaulView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRaulDoc)));
return (CRaulDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRaulView message handlers
void CRaulView::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(rect);
h=rect.Height();
w=rect.Width();
dc.MoveTo(w/7,h/4);
dc.LineTo(w*6/7,h/4);
dc.MoveTo(w/7,h*3/4);
dc.LineTo(w*6/7,h*3/4);
dc.MoveTo(w/4,0);
dc.LineTo(w/4,h);
dc.MoveTo(w*3/4,0);
dc.LineTo(w*3/4,h);
z=1.5;
COLORREF color;
CPen pen;
color=RGB(255,0,0);
int p;
p=pen.CreatePen(0,1,color);
dc.SelectObject(pen);
dc.MoveTo(p1);
dc.LineTo(p2.x,p2.y);
// Do not call CView::OnPaint() for painting messages
}
int CRaulView::code(CPoint point)
{
if(point.x>3*w/4) c3=1; else c3=0;
if(point.x<w/4) c4=1; else c4=0;
if(point.y>3*h/4) c1=1; else c1=0;
if(point.y<h/4) c2=1; else c2=0;
return c1*1000+c2*100+c3*10+c4;
}
int CRaulView::compare(CPoint p1, CPoint p2)
{
int a;
a=code(p1)+code(p2);
if(a==0)return 0;
if(a/1000==2 || a%1000/100==2 || a%100/10==2 || a%10==2)return 1;
else return 2;
}
CPoint CRaulView::next(CPoint p1, CPoint p2)
{
CPoint p0;
if(code(p1)==0)return p1;
else{
p0.x=(p1.x+p2.x)/2;
p0.y=(p1.y+p2.y)/2;
if(d(p0,p1)<z)return p0;
else
{
if(compare(p1,p0)==1) next(p0,p2);
else
next(p1,p0);
}
}
}
float CRaulView::d(CPoint p1, CPoint p2)
{
float a=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
return a;
}
void CRaulView::OnLButtonDown(UINT nFlags, CPoint point)
{
CPaintDC dc(this);
i++;
if(i>2) i=i%2;
if(i==1) {p1=point;}
else {p2=point;}
if(i==2)Invalidate(true);
CView::OnLButtonDown(nFlags, point);
}
void CRaulView::OnMenuDisplay()
{
CDC *dc=GetDC();
COLORREF color;
CPen pen;
color=RGB(0,0,255);
int p;
p=pen.CreatePen(0,1,color);
dc->SelectObject(pen);
if(compare(p1,p2)==1) MessageBox("直线完全不可见!");
if(compare(p1,p2)==0){
dc->MoveTo(p1);
dc->LineTo(p2);}
if(compare(p1,p2)==2){
CPoint p3,p4;
p3=next(p1,p2);
p4=next(p2,p1);
dc->MoveTo(p3);
dc->LineTo(p4);}
Invalidate(false);
// TODO: Add your command handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -