XDAView.cpp
资源名称:XuXian.rar [点击查看]
上传用户:toomm12
上传日期:2022-04-29
资源大小:1871k
文件大小:4k
源码类别:
2D图形编程
开发平台:
Visual C++
- // XDAView.cpp : implementation of the CXDAView class
- //
- #include "stdafx.h"
- #include "XDA.h"
- #include "XDADoc.h"
- #include "XDAView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CXDAView
- IMPLEMENT_DYNCREATE(CXDAView, CView)
- BEGIN_MESSAGE_MAP(CXDAView, CView)
- //{{AFX_MSG_MAP(CXDAView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CXDAView construction/destruction
- CXDAView::CXDAView()
- {
- // TODO: add construction code here
- }
- CXDAView::~CXDAView()
- {
- }
- BOOL CXDAView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CXDAView drawing
- void CXDAView::OnDraw(CDC* pDC)
- {
- CXDADoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- int dx;
- int dy;
- int x;
- int y;
- int p;
- int const1;
- int const2;
- int inc;
- int tmp;
- int i;
- int k;
- int t;
- dx=pDoc->x2-pDoc->x1;
- dy=pDoc->y2-pDoc->y1;
- if(dx*dy>=0)
- inc=1;
- else inc=-1;
- if(abs(dx)>abs(dy)){
- if(dx<0){
- tmp=pDoc->x1;
- pDoc->x1=pDoc->x2;
- pDoc->x2=tmp;
- tmp=pDoc->y1;
- pDoc->y1=pDoc->y2;
- pDoc->y2=tmp;
- dx=-dx;
- dy=-dy;
- }
- p=2*dy-dx;
- const1=2*dy;
- const2=2*(dy-dx);
- x=pDoc->x1;
- y=pDoc->y1;
- pDC->SetPixel(x,y,pDoc->c);
- while(x<pDoc->x2){
- x++;
- if(p<0)
- p+=const1;
- else{
- y+=inc;
- p+=const2;
- }k=y+5;
- if(x%10!=0)
- for(t=y;t<k;t++)
- pDC->SetPixel(x,t,pDoc->c);
- }
- }
- else{
- if(dy<0){
- tmp=pDoc->x1;
- pDoc->x1=pDoc->x2;
- pDoc->x2=tmp;
- tmp=pDoc->y1;
- pDoc->y1=pDoc->y2;
- pDoc->y2=tmp;
- dx=-dx;
- dy=-dy;
- }
- p=2*dx-dy;
- const1=2*dx;
- const2=2*(dx-dy);
- x=pDoc->x1;
- y=pDoc->y1;
- pDC->SetPixel(x,y,pDoc->c);
- while(y<pDoc->y2){
- y++;
- if(p<0)
- p+=const1;
- else{
- x+=inc;
- p+=const2;
- }k=y+5;
- if(x%10!=0)
- for(t=y;t<k;t++)
- pDC->SetPixel(x,t,pDoc->c);
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CXDAView printing
- BOOL CXDAView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CXDAView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CXDAView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CXDAView diagnostics
- #ifdef _DEBUG
- void CXDAView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CXDAView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CXDADoc* CXDAView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXDADoc)));
- return (CXDADoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CXDAView message handlers