XDAView.cpp
上传用户:toomm12
上传日期:2022-04-29
资源大小:1871k
文件大小:4k
源码类别:

2D图形编程

开发平台:

Visual C++

  1. // XDAView.cpp : implementation of the CXDAView class
  2. //
  3. #include "stdafx.h"
  4. #include "XDA.h"
  5. #include "XDADoc.h"
  6. #include "XDAView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CXDAView
  14. IMPLEMENT_DYNCREATE(CXDAView, CView)
  15. BEGIN_MESSAGE_MAP(CXDAView, CView)
  16. //{{AFX_MSG_MAP(CXDAView)
  17. // NOTE - the ClassWizard will add and remove mapping macros here.
  18. //    DO NOT EDIT what you see in these blocks of generated code!
  19. //}}AFX_MSG_MAP
  20. // Standard printing commands
  21. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CXDAView construction/destruction
  27. CXDAView::CXDAView()
  28. {
  29. // TODO: add construction code here
  30. }
  31. CXDAView::~CXDAView()
  32. {
  33. }
  34. BOOL CXDAView::PreCreateWindow(CREATESTRUCT& cs)
  35. {
  36. // TODO: Modify the Window class or styles here by modifying
  37. //  the CREATESTRUCT cs
  38. return CView::PreCreateWindow(cs);
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CXDAView drawing
  42. void CXDAView::OnDraw(CDC* pDC)
  43. {
  44. CXDADoc* pDoc = GetDocument();
  45. ASSERT_VALID(pDoc);
  46. // TODO: add draw code for native data here
  47. int dx;
  48. int dy;
  49. int x;
  50. int y;
  51. int p;
  52. int const1;
  53. int const2;
  54. int inc;
  55. int tmp;
  56. int i;
  57. int k;
  58. int t;
  59. dx=pDoc->x2-pDoc->x1;
  60. dy=pDoc->y2-pDoc->y1;
  61. if(dx*dy>=0)
  62. inc=1;
  63. else inc=-1;
  64. if(abs(dx)>abs(dy)){
  65. if(dx<0){
  66. tmp=pDoc->x1;
  67. pDoc->x1=pDoc->x2;
  68. pDoc->x2=tmp;
  69. tmp=pDoc->y1;
  70. pDoc->y1=pDoc->y2;
  71. pDoc->y2=tmp;
  72. dx=-dx;
  73. dy=-dy;
  74. }
  75. p=2*dy-dx;
  76. const1=2*dy;
  77. const2=2*(dy-dx);
  78. x=pDoc->x1;
  79. y=pDoc->y1;
  80. pDC->SetPixel(x,y,pDoc->c);
  81. while(x<pDoc->x2){
  82. x++;
  83. if(p<0)
  84. p+=const1;
  85. else{
  86. y+=inc;
  87. p+=const2;
  88. }k=y+5;
  89. if(x%10!=0)
  90. for(t=y;t<k;t++)
  91. pDC->SetPixel(x,t,pDoc->c);
  92. }
  93. }
  94. else{
  95. if(dy<0){
  96. tmp=pDoc->x1;
  97. pDoc->x1=pDoc->x2;
  98. pDoc->x2=tmp;
  99. tmp=pDoc->y1;
  100. pDoc->y1=pDoc->y2;
  101. pDoc->y2=tmp;
  102. dx=-dx;
  103. dy=-dy;
  104. }
  105. p=2*dx-dy;
  106. const1=2*dx;
  107. const2=2*(dx-dy);
  108. x=pDoc->x1;
  109.         y=pDoc->y1;
  110. pDC->SetPixel(x,y,pDoc->c);
  111. while(y<pDoc->y2){
  112. y++;
  113. if(p<0)
  114. p+=const1;
  115. else{
  116. x+=inc;
  117. p+=const2;
  118. }k=y+5;
  119. if(x%10!=0)
  120. for(t=y;t<k;t++)
  121. pDC->SetPixel(x,t,pDoc->c);
  122. }
  123. }
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CXDAView printing
  127. BOOL CXDAView::OnPreparePrinting(CPrintInfo* pInfo)
  128. {
  129. // default preparation
  130. return DoPreparePrinting(pInfo);
  131. }
  132. void CXDAView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  133. {
  134. // TODO: add extra initialization before printing
  135. }
  136. void CXDAView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  137. {
  138. // TODO: add cleanup after printing
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CXDAView diagnostics
  142. #ifdef _DEBUG
  143. void CXDAView::AssertValid() const
  144. {
  145. CView::AssertValid();
  146. }
  147. void CXDAView::Dump(CDumpContext& dc) const
  148. {
  149. CView::Dump(dc);
  150. }
  151. CXDADoc* CXDAView::GetDocument() // non-debug version is inline
  152. {
  153. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXDADoc)));
  154. return (CXDADoc*)m_pDocument;
  155. }
  156. #endif //_DEBUG
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CXDAView message handlers