📄 ly16paintview.cpp
字号:
// LY16paintView.cpp : implementation of the CLY16paintView class
//
#include "stdafx.h"
#include "LY16paint.h"
#include "LY16Line.h"
#include "LY16paintDoc.h"
#include "LY16paintView.h"
#include "Mainfrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLY16paintView
IMPLEMENT_DYNCREATE(CLY16paintView, CView)
BEGIN_MESSAGE_MAP(CLY16paintView, CView)
//{{AFX_MSG_MAP(CLY16paintView)
ON_COMMAND(ID_BUTTON_PEN, OnButtonPen)
ON_UPDATE_COMMAND_UI(ID_BUTTON_PEN, OnUpdateButtonPen)
ON_COMMAND(ID_BUTTON_AIRBRUSH, OnButtonAirbrush)
ON_UPDATE_COMMAND_UI(ID_BUTTON_AIRBRUSH, OnUpdateButtonAirbrush)
ON_COMMAND(ID_BUTTON_BRUSH, OnButtonBrush)
ON_UPDATE_COMMAND_UI(ID_BUTTON_BRUSH, OnUpdateButtonBrush)
ON_COMMAND(ID_BUTTON_CURVE, OnButtonCurve)
ON_UPDATE_COMMAND_UI(ID_BUTTON_CURVE, OnUpdateButtonCurve)
ON_COMMAND(ID_BUTTON_ELLIPSE, OnButtonEllipse)
ON_UPDATE_COMMAND_UI(ID_BUTTON_ELLIPSE, OnUpdateButtonEllipse)
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_IRREG_SEL, OnButtonIrregSel)
ON_UPDATE_COMMAND_UI(ID_BUTTON_IRREG_SEL, OnUpdateButtonIrregSel)
ON_COMMAND(ID_BUTTON_LINE, OnButtonLine)
ON_UPDATE_COMMAND_UI(ID_BUTTON_LINE, OnUpdateButtonLine)
ON_COMMAND(ID_BUTTON_MAGNIFY, OnButtonMagnify)
ON_UPDATE_COMMAND_UI(ID_BUTTON_MAGNIFY, OnUpdateButtonMagnify)
ON_COMMAND(ID_BUTTON_POLYGON, OnButtonPolygon)
ON_UPDATE_COMMAND_UI(ID_BUTTON_POLYGON, OnUpdateButtonPolygon)
ON_COMMAND(ID_BUTTON_RECT, OnButtonRect)
ON_UPDATE_COMMAND_UI(ID_BUTTON_RECT, OnUpdateButtonRect)
ON_COMMAND(ID_BUTTON_RECT_SEL, OnButtonRectSel)
ON_UPDATE_COMMAND_UI(ID_BUTTON_RECT_SEL, OnUpdateButtonRectSel)
ON_COMMAND(ID_BUTTON_ROUND_RECT, OnButtonRoundRect)
ON_UPDATE_COMMAND_UI(ID_BUTTON_ROUND_RECT, OnUpdateButtonRoundRect)
ON_COMMAND(ID_BUTTON_SELCOLOR, OnButtonSelcolor)
ON_UPDATE_COMMAND_UI(ID_BUTTON_SELCOLOR, OnUpdateButtonSelcolor)
ON_COMMAND(ID_BUTTON_TEXT, OnButtonText)
ON_UPDATE_COMMAND_UI(ID_BUTTON_TEXT, OnUpdateButtonText)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CLY16paintView construction/destruction
CLY16paintView::CLY16paintView()
{
// TODO: add construction code here
m_pointcheck=0;
}
CLY16paintView::~CLY16paintView()
{
}
BOOL CLY16paintView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CLY16paintView drawing
void CLY16paintView::OnDraw(CDC* pDC)
{
CLY16paintDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CPen pen(PS_SOLID,GetPenWidth(),GetPaintColor());
CPen* pOldPen=pDC->SelectObject(&pen);
// CRect rect;
// GetClientRect(rect);
CBrush brush(GetCanvasColor());
CBrush* pOldBrush=pDC->SelectObject(&brush);
switch(m_emPaintType)
{
case LINE:
pDC->MoveTo(downPoint);
pDC->LineTo(upPoint);
pDC->SelectObject(pOldPen);
break;
case RECT:
switch(GetRectType())
{
case 0:
pDC->SelectStockObject( HOLLOW_BRUSH );
pDC->Rectangle(downPoint.x,downPoint.y,upPoint.x,upPoint.y);
break;
case 1:
{
pDC->Rectangle(downPoint.x,downPoint.y,upPoint.x,upPoint.y);
}
break;
case 2:
{
pDC->SelectStockObject( NULL_PEN );
pDC->Rectangle(downPoint.x,downPoint.y,upPoint.x,upPoint.y);
}
break;
}
break;
case ELLIPSE:
switch(GetRectType())
{
case 0:
pDC->SelectStockObject( HOLLOW_BRUSH );
pDC->Ellipse(downPoint.x,downPoint.y,upPoint.x,upPoint.y);
break;
case 1:
{
pDC->Ellipse(downPoint.x,downPoint.y,upPoint.x,upPoint.y);
}
break;
case 2:
{
pDC->SelectStockObject( NULL_PEN );
pDC->Ellipse(downPoint.x,downPoint.y,upPoint.x,upPoint.y);
}
break;
}
//pDC->Ellipse(downPoint.x,downPoint.y,upPoint.x,upPoint.y);RoundRect
break;
case ROUND_RECT:
switch(GetRectType())
{
case 0:
pDC->SelectStockObject( HOLLOW_BRUSH );
pDC->RoundRect(downPoint.x,downPoint.y,upPoint.x,upPoint.y,(upPoint.x-downPoint.x)*1/4,(upPoint.y-downPoint.y)*1/4);
break;
case 1:
{
pDC->RoundRect(downPoint.x,downPoint.y,upPoint.x,upPoint.y,(upPoint.x-downPoint.x)*1/4,(upPoint.y-downPoint.y)*1/4);
}
break;
case 2:
{
pDC->SelectStockObject( NULL_PEN );
pDC->RoundRect(downPoint.x,downPoint.y,upPoint.x,upPoint.y,(upPoint.x-downPoint.x)*1/4,(upPoint.y-downPoint.y)*1/4);
}
break;
}
//pDC->RoundRect(downPoint.x,downPoint.y,upPoint.x,upPoint.y,(upPoint.x-downPoint.x)*1/4,(upPoint.y-downPoint.y)*1/4);
break;
}
}
////////////////////////////////////////////////////////////////////////////
// CLY16paintView printing
BOOL CLY16paintView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLY16paintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLY16paintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CLY16paintView diagnostics
#ifdef _DEBUG
void CLY16paintView::AssertValid() const
{
CView::AssertValid();
}
void CLY16paintView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CLY16paintDoc* CLY16paintView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLY16paintDoc)));
return (CLY16paintDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLY16paintView message handlers
void CLY16paintView::SetSelBox(int type)
{
((CMainFrame*)AfxGetMainWnd())->m_wndToolBar.SetSelType((SELTYPE)type);
}
void CLY16paintView::OnButtonPen()
{
// TODO: Add your command handler code here
m_emPaintType = PEN;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonPen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==PEN);
}
void CLY16paintView::XorLine(CPoint pt1, CPoint pt2)
{
CDC *pDC = GetDC();
CPen pen;
pen.CreateStockObject(WHITE_PEN);
CPen* pOldPen = (CPen*)pDC->SelectObject(&pen);
pDC->SetROP2(R2_XORPEN);
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
pDC->SelectObject(pOldPen);
ReleaseDC(pDC);
}
void CLY16paintView::UpdateImage()
{
m_pdcMem->SelectObject(m_pbmBackground);
Invalidate();
}
void CLY16paintView::OnButtonAirbrush()
{
// TODO: Add your command handler code here
m_emPaintType = AIRBRUSH;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonAirbrush(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==AIRBRUSH);
}
void CLY16paintView::OnButtonBrush()
{
// TODO: Add your command handler code here
m_emPaintType = BRUSH;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonBrush(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==BRUSH);
}
void CLY16paintView::OnButtonCurve()
{
// TODO: Add your command handler code here
m_emPaintType = CURVE;
SetSelBox(SEL_PENWIDTH);
}
void CLY16paintView::OnUpdateButtonCurve(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==CURVE);
}
void CLY16paintView::OnButtonEllipse()
{
// TODO: Add your command handler code here
m_emPaintType = ELLIPSE;
SetSelBox(SEL_RECTTYPE);
}
void CLY16paintView::OnUpdateButtonEllipse(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==ELLIPSE);
}
void CLY16paintView::OnButtonEraser()
{
// TODO: Add your command handler code here
m_emPaintType = ERASER;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonEraser(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==ERASER);
}
void CLY16paintView::OnButtonFill()
{
// TODO: Add your command handler code here
m_emPaintType = FILL;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonFill(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==FILL);
}
void CLY16paintView::OnButtonIrregSel()
{
// TODO: Add your command handler code here
m_emPaintType = IRREG_SEL;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonIrregSel(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==IRREG_SEL);
}
void CLY16paintView::OnButtonLine()
{
// TODO: Add your command handler code here
m_emPaintType = LINE;
SetSelBox(SEL_PENWIDTH);
}
void CLY16paintView::OnUpdateButtonLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==LINE);
}
void CLY16paintView::OnButtonMagnify()
{
// TODO: Add your command handler code here
m_emPaintType = MAGNIFY;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonMagnify(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==MAGNIFY);
}
void CLY16paintView::OnButtonPolygon()
{
// TODO: Add your command handler code here
m_emPaintType = POLYGON;
SetSelBox(SEL_RECTTYPE);
}
void CLY16paintView::OnUpdateButtonPolygon(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==POLYGON);
}
void CLY16paintView::OnButtonRect()
{
// TODO: Add your command handler code here
m_emPaintType = RECT;
SetSelBox(SEL_RECTTYPE);
}
void CLY16paintView::OnUpdateButtonRect(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==RECT);
}
void CLY16paintView::OnButtonRectSel()
{
// TODO: Add your command handler code here
m_emPaintType = RECT_SEL;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonRectSel(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==RECT_SEL);
}
void CLY16paintView::OnButtonRoundRect()
{
// TODO: Add your command handler code here
m_emPaintType = ROUND_RECT;
SetSelBox(SEL_RECTTYPE);
}
void CLY16paintView::OnUpdateButtonRoundRect(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==ROUND_RECT);
}
void CLY16paintView::OnButtonSelcolor()
{
// TODO: Add your command handler code here
m_emPaintType = SEL_COLOR;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonSelcolor(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==SEL_COLOR);
}
void CLY16paintView::OnButtonText()
{
// TODO: Add your command handler code here
m_emPaintType = TEXT;
SetSelBox(SEL_NONE);
}
void CLY16paintView::OnUpdateButtonText(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_emPaintType==TEXT);
}
void CLY16paintView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
downPoint=point;
m_pointcheck=1;
CView::OnLButtonDown(nFlags, point);
}
void CLY16paintView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
upPoint=point;
m_pointcheck=0;
//Invalidate();
CView::OnLButtonUp(nFlags, point);
}
int CLY16paintView::GetPenWidth() const
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if ( pFrame )
return pFrame->GetPenWidth();
else
return 1;
}
COLORREF CLY16paintView::GetPaintColor() const
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if ( pFrame )
return pFrame->m_clrPaint;
else
return RGB(0,0,0);
}
COLORREF CLY16paintView::GetCanvasColor() const
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if ( pFrame )
return pFrame->m_clrCanvas;
else
return RGB(255,255,255);
}
void CLY16paintView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pointcheck)
{upPoint=point;
Invalidate();
}
CView::OnMouseMove(nFlags, point);
}
int CLY16paintView::GetRectType() const
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
if ( pFrame )
return pFrame->GetRectType();
else
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -