📄 pictureview.cpp
字号:
// PictureView.cpp : implementation of the CPictureView class
//
#include "stdafx.h"
#include "Picture.h"
#include "PictureDoc.h"
#include "PictureView.h"
#include "ROTATE.h"
#include <math.h>
#include "Zoom.h"
#include "Tran.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPictureView
IMPLEMENT_DYNCREATE(CPictureView, CView)
BEGIN_MESSAGE_MAP(CPictureView, CView)
//{{AFX_MSG_MAP(CPictureView)
ON_UPDATE_COMMAND_UI(ID_CIRCLE, OnUpdateCircle)
ON_UPDATE_COMMAND_UI(ID_LINE, OnUpdateLine)
ON_COMMAND(ID_LINE, OnLine)
ON_COMMAND(ID_CIRCLE, OnCircle)
ON_COMMAND(ID_RECTANGLE, OnRectangle)
ON_UPDATE_COMMAND_UI(ID_RECTANGLE, OnUpdateRectangle)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND(ID_ROTATE, OnRotate)
ON_UPDATE_COMMAND_UI(ID_ROTATE, OnUpdateRotate)
ON_COMMAND(ID_ZOOM, OnZoom)
ON_COMMAND(ID_TRANSLATE, OnTranslate)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CPictureView construction/destruction
CPictureView::CPictureView()
{
// TODO: add construction code here
bTriangle=false;
bCircle=false;
bLine=false;
bFirst=false;
bFirst=false;
bSecond=false;
bThird=false;
bFinish=false;
bValid=false;
x=0;
y=0;
x1=0;
y1=0;
x2=0;
y2=0;
}
CPictureView::~CPictureView()
{
}
BOOL CPictureView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CPictureView drawing
void CPictureView::OnDraw(CDC* pDC)
{
CPictureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(bTriangle)
{
pDC->MoveTo(x,y);
if(bSecond)
{
pDC->LineTo(x1,y1);
}
if(bThird)
{
pDC->LineTo(x1,y1);
pDC->LineTo(x2,y2);
}
if(bFinish)
{
pDC->LineTo(x1,y1);
pDC->LineTo(x2,y2);
pDC->LineTo(x,y);
}
}
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CPictureView printing
BOOL CPictureView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPictureView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPictureView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPictureView diagnostics
#ifdef _DEBUG
void CPictureView::AssertValid() const
{
CView::AssertValid();
}
void CPictureView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CPictureDoc* CPictureView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPictureDoc)));
return (CPictureDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPictureView message handlers
void CPictureView::OnUpdateCircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bCircle)
{
pCmdUI->SetRadio();
}
else
{
pCmdUI->SetRadio(false);
}
pCmdUI->Enable();
}
void CPictureView::OnUpdateLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(bLine)
{
pCmdUI->SetRadio();
}
else
{
pCmdUI->SetRadio(false);
}
pCmdUI->Enable();
}
void CPictureView::OnLine()
{
// TODO: Add your command handler code here
bTriangle=false;
bCircle=false;
bLine=true;
// bFirst=true;
}
void CPictureView::OnCircle()
{
// TODO: Add your command handler code here
bTriangle=false;
bCircle=true;
bLine=false;
// bFirst=true;
}
void CPictureView::OnRectangle()
{
// TODO: Add your command handler code here
bTriangle=true;
bCircle=false;
bLine=false;
bFirst=true;
// bFirst=true;
}
void CPictureView::OnUpdateRectangle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
if(bTriangle)
{
pCmdUI->SetRadio();
}
else
{
pCmdUI->SetRadio(false);
}
}
void CPictureView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//bFirst=true;
if(bFirst)
{
x=point.x;
y=point.y;
x1=point.x;//消除到(0,0)的直线
y1=point.y;
bSecond=true;
bFirst=false;
Invalidate(true);
return;
}
if(bSecond)
{
x1=point.x;
y1=point.y;
x2=point.x;//消除到(0,0)的直线
y2=point.y;
bSecond=false;
bThird=true;
Invalidate(true);
return;
}
if(bThird)
{
x2=point.x;
y2=point.y;
bThird=false;
bThird=false;
bFinish=true;
Invalidate(true);
}
CView::OnLButtonDown(nFlags, point);
}
void CPictureView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// bFirst=false;
// x1=point.x;
// y1=point.y;
CView::OnLButtonUp(nFlags, point);
}
void CPictureView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(bSecond)
{ x1=point.x;
y1=point.y;
}
if(bThird)
{ x2=point.x;
y2=point.y;
bFinish=true;
}
// this->InvalidateRect(&CRect(x-2,y-2,point.x+5,point.y+5),true);
Invalidate(true);
CView::OnMouseMove(nFlags, point);
}
void CPictureView::OnRotate()
{
// TODO: Add your command handler code here
CROTATE angle;
int result=angle.DoModal();
if(result==IDOK)
{
int c=angle.m_angle;
if(bTriangle)
{
Rotate(x,y,c);
Rotate(x1,y1,c);
Rotate(x2,y2,c);
Invalidate(true);
}
}
}
void CPictureView::OnUpdateRotate(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
}
void CPictureView::Rotate(int& x,int& y, int angle)
{
int x1=x;
int y1=y;
double a=3.1415926/180;
int c=cos(a*360)+0.5;
x=(int)(x1*cos(angle*a)-y1*sin(angle*a)+0.5);
y=(int)(x1*sin(angle*a)+y1*cos(angle*a)+0.5);
}
void CPictureView::OnZoom()
{
// TODO: Add your command handler code here
CZoom zoom;
int result=zoom.DoModal();
if(result==IDOK)
{
double zx=zoom.m_x;
double zy=zoom.m_y;
if(bTriangle)
{
Zoom(x,y,zx,zy);
Zoom(x1,y1,zx,zy);
Zoom(x2,y2,zx,zy);
Invalidate(true);
}
}
}
void CPictureView::OnTranslate()
{
// TODO: Add your command handler code here
CTran tran;
int result=tran.DoModal();
if(result==IDOK)
{
int tx=tran.m_x;
int ty=tran.m_y;
if(bTriangle)
{
Tran(x,y,tx,ty);
Tran(x1,y1,tx,ty);
Tran(x2,y2,tx,ty);
Invalidate(true);
}
}
}
void CPictureView::Zoom(int &x, int &y, double zx, double zy)
{
x=x*zx+0.5;
y=y*zy+0.5;
}
void CPictureView::Tran(int &x, int &y, int tx, int ty)
{
x+=tx;
y+=ty;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -