📄 zcr14paintview.cpp
字号:
// ZCR14PaintView.cpp : implementation of the CZCR14PaintView class
//
#include "stdafx.h"
#include "ZCR14Paint.h"
#include "ZCR14Shape.h"
#include "ZCR14List.h"
#include "ZCR14PaintDoc.h"
#include "ZCR14PaintView.h"
#include "OptionZone.h"
#include "MainFrm.h"
#include "MyToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintView
IMPLEMENT_DYNCREATE(CZCR14PaintView, CView)
BEGIN_MESSAGE_MAP(CZCR14PaintView, CView)
//{{AFX_MSG_MAP(CZCR14PaintView)
ON_UPDATE_COMMAND_UI(ID_BUTTON_LINE, OnUpdateButtonLine)
ON_COMMAND(ID_BUTTON_LINE, OnButtonLine)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_UPDATE_COMMAND_UI(ID_BUTTON_RECT, OnUpdateButtonRect)
ON_COMMAND(ID_BUTTON_RECT, OnButtonRect)
ON_UPDATE_COMMAND_UI(ID_BUTTON_ELLIPSE, OnUpdateButtonEllipse)
ON_COMMAND(ID_BUTTON_ELLIPSE, OnButtonEllipse)
ON_COMMAND(ID_BUTTON_ROUND_RECT, OnButtonRoundRect)
ON_UPDATE_COMMAND_UI(ID_BUTTON_ROUND_RECT, OnUpdateButtonRoundRect)
ON_COMMAND(ID_BUTTON_POLYGON, OnButtonPolygon)
ON_UPDATE_COMMAND_UI(ID_BUTTON_POLYGON, OnUpdateButtonPolygon)
ON_COMMAND(ID_BUTTON_CURVE, OnButtonCurve)
ON_UPDATE_COMMAND_UI(ID_BUTTON_CURVE, OnUpdateButtonCurve)
ON_COMMAND(ID_BUTTON_TEXT, OnButtonText)
ON_UPDATE_COMMAND_UI(ID_BUTTON_TEXT, OnUpdateButtonText)
ON_COMMAND(ID_BUTTON_IRREG_SEL, OnButtonIrregSel)
ON_UPDATE_COMMAND_UI(ID_BUTTON_IRREG_SEL, OnUpdateButtonIrregSel)
ON_COMMAND(ID_BUTTON_RECT_SEL, OnButtonRectSel)
ON_UPDATE_COMMAND_UI(ID_BUTTON_RECT_SEL, OnUpdateButtonRectSel)
ON_COMMAND(ID_BUTTON_ERASER, OnButtonEraser)
ON_UPDATE_COMMAND_UI(ID_BUTTON_ERASER, OnUpdateButtonEraser)
ON_COMMAND(ID_BUTTON_FILL, OnButtonFill)
ON_UPDATE_COMMAND_UI(ID_BUTTON_FILL, OnUpdateButtonFill)
ON_COMMAND(ID_BUTTON_SELCOLOR, OnButtonSelcolor)
ON_UPDATE_COMMAND_UI(ID_BUTTON_SELCOLOR, OnUpdateButtonSelcolor)
ON_COMMAND(ID_BUTTON_MAGNIFY, OnButtonMagnify)
ON_UPDATE_COMMAND_UI(ID_BUTTON_MAGNIFY, OnUpdateButtonMagnify)
ON_COMMAND(ID_BUTTON_PEN, OnButtonPen)
ON_UPDATE_COMMAND_UI(ID_BUTTON_PEN, OnUpdateButtonPen)
ON_COMMAND(ID_BUTTON_BRUSH, OnButtonBrush)
ON_UPDATE_COMMAND_UI(ID_BUTTON_BRUSH, OnUpdateButtonBrush)
ON_COMMAND(ID_BUTTON_AIRBRUSH, OnButtonAirbrush)
ON_UPDATE_COMMAND_UI(ID_BUTTON_AIRBRUSH, OnUpdateButtonAirbrush)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintView construction/destruction
CZCR14PaintView::CZCR14PaintView()
{
// TODO: add construction code here
m_emPaintType = IRREG_SEL;
m_bDrawing = FALSE;
m_bFirstDraw = FALSE;
}
CZCR14PaintView::~CZCR14PaintView()
{
CZCR14PaintDoc* pDoc = GetDocument();
POSITION pos = pDoc->m_lstShape.GetHeadPosition();
while(pos)
{
pShape=(CZCR14Shape*)pDoc->m_lstShape.GetNext(pos);
delete pShape;
}
}
BOOL CZCR14PaintView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintView drawing
void CZCR14PaintView::OnDraw(CDC* pDC)
{
CZCR14PaintDoc* pDoc = GetDocument();//将View与DOC联系起来
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//CBrush* pOldBrush=pDC->SelectObject(&brush);
/* switch(m_emPaintType)
{
case LINE:
{
CPen pen(PS_SOLID,GetPenWith(), GetPainColor());
CPen* pOldPen=pDC->SelectObject(&pen);
pDC->MoveTo(m_ptStart.x,m_ptStart.y);
pDC->LineTo(m_ptEnd.x,m_ptEnd.y);
}
break;
case RECT:
switch (GetRectType())
{
case 0:
{
CPen pen(PS_SOLID,GetPenWith(), GetPainColor());
CPen* pOldPen=pDC->SelectObject(&pen);
pDC->Rectangle(m_ptStart.x,m_ptStart.y,m_ptEnd.x,m_ptEnd.y);
}
break;
case 1:
{
CPen pen(PS_SOLID,GetPenWith(), GetPainColor());
CPen* pOldPen=pDC->SelectObject(&pen);
CBrush brush;
brush.CreateSolidBrush(GetCanvasColor());
CBrush* pOldbrush=pDC->SelectObject(&brush);
pDC->Rectangle(m_ptStart.x,m_ptStart.y,m_ptEnd.x,m_ptEnd.y);
}
break;
case 2:
{
CPen pen(PS_SOLID,GetPenWith(), GetCanvasColor());
CPen* pOldPen=pDC->SelectObject(&pen);
CBrush brush;
brush.CreateSolidBrush(GetCanvasColor());
CBrush* pOldbrush=pDC->SelectObject(&brush);
pDC->Rectangle(m_ptStart.x,m_ptStart.y,m_ptEnd.x,m_ptEnd.y);
}
}
break;
case ROUND_RECT:
//pDC->Ellipse(m_ptStart.x,m_ptStart.y,m_ptStart.x+,m_ptStart.y+m_ptEnd.y);
break;
}
*/
POSITION pos=pDoc->m_lstShape.GetHeadPosition();
//m_lstShape.GetHeadPosition();
while(pos)
{
pShape=(CZCR14Shape*)pDoc->m_lstShape.GetNext(pos);
pShape->Draw(pDC);
}
}
/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintView printing
BOOL CZCR14PaintView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZCR14PaintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZCR14PaintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintView diagnostics
#ifdef _DEBUG
void CZCR14PaintView::AssertValid() const
{
CView::AssertValid();
}
void CZCR14PaintView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZCR14PaintDoc* CZCR14PaintView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZCR14PaintDoc)));
return (CZCR14PaintDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintView message handlers
void CZCR14PaintView::OnUpdateButtonLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==LINE);
}
void CZCR14PaintView::OnButtonLine()
{
// TODO: Add your command handler code here
m_emPaintType = LINE;
SetSelBox(SEL_PENWIDTH);
}
void CZCR14PaintView::SetSelBox(int type)
{
((CMainFrame*)AfxGetMainWnd())->m_wndToolBar.SetSelType((SELTYPE)type);
}
void CZCR14PaintView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//CDC* pDC = GetDC();
m_ptStart = point;
//m_ptEnd=point;
// m_bPaintFlag=TRUE;
switch(m_emPaintType)
{
case LINE:
{
pLine=new CZCR14Line;
break;
}
case RECT:
{
pRect=new CZCR14Rect;
break;
}
case ELLIPSE:
{
pEllipse=new CZCR14Ellipse;
break;
}
}
m_bDrawing = TRUE;
//ReleaseDC(pDC);
CView::OnLButtonDown(nFlags, point);
}
void CZCR14PaintView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CZCR14PaintDoc* pDoc = GetDocument();
switch(m_emPaintType)
{
case LINE:
{
pDoc->m_lstShape.AddTail(pLine);
break;
}
case RECT:
{
pDoc->m_lstShape.AddTail(pRect);
break;
}
case ELLIPSE:
{
pDoc->m_lstShape.AddTail(pEllipse);
break;
}
}
Invalidate();
m_bDrawing=FALSE;
//m_ptEnd=point;
//m_ptEnd=point;
//m_bPaintFlag=FALSE;
//Invalidate();
CView::OnLButtonUp(nFlags, point);
}
void CZCR14PaintView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
CString strCoord;
strCoord.Format(" %d, %d", point.x, point.y);
pFrame->m_wndStatusBar.SetPaneText(1, strCoord, TRUE);
if(m_bDrawing)
//{
CDC* pDC = GetDC();
//switch (m_emPaintType)
//{
// case RECT:
// if ( !m_bFirstDraw )
// Rectangle(pDC,m_ptStart,m_ptEnd);
//else
// m_bFirstDraw = FALSE;
// Rectangle(pDC,m_ptStart,point);
//m_ptEnd = point;
//b/reak;
//}
// ReleaseDC(pDC);
// }
m_ptEnd=point;
*/
CDC* pDC = GetDC();
CZCR14PaintDoc* pDoc = GetDocument();
if(m_bDrawing==TRUE)
{
m_ptEnd=point;
int old=pDC->SetROP2(R2_NOTXORPEN);
switch(m_emPaintType)
{
case LINE:
{
pLine->Draw(pDC);
pLine->SetPenWidthColor(GetPenWith(),GetPainColor());
pLine->SetPoint(m_ptStart,m_ptEnd);
pLine->Draw(pDC);
//pDoc->m_lstShape.AddTail(pLine);
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -