upsidedown

SEM6 CG: Midpt circle

Feb 13th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.04 KB | None | 0 0
  1.  
  2. // midptcircleView.cpp : implementation of the CmidptcircleView class
  3. //
  4.  
  5. #include "stdafx.h"
  6. // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
  7. // and search filter handlers and allows sharing of document code with that project.
  8. #ifndef SHARED_HANDLERS
  9. #include "midptcircle.h"
  10. #endif
  11.  
  12. #include "midptcircleDoc.h"
  13. #include "midptcircleView.h"
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #endif
  18.  
  19.  
  20. // CmidptcircleView
  21.  
  22. IMPLEMENT_DYNCREATE(CmidptcircleView, CView)
  23.  
  24. BEGIN_MESSAGE_MAP(CmidptcircleView, CView)
  25.     ON_WM_CONTEXTMENU()
  26.     ON_WM_RBUTTONUP()
  27. END_MESSAGE_MAP()
  28.  
  29. // CmidptcircleView construction/destruction
  30.  
  31. CmidptcircleView::CmidptcircleView()
  32. {
  33.     // TODO: add construction code here
  34.  
  35. }
  36.  
  37. CmidptcircleView::~CmidptcircleView()
  38. {
  39. }
  40.  
  41. BOOL CmidptcircleView::PreCreateWindow(CREATESTRUCT& cs)
  42. {
  43.     // TODO: Modify the Window class or styles here by modifying
  44.     //  the CREATESTRUCT cs
  45.  
  46.     return CView::PreCreateWindow(cs);
  47. }
  48.  
  49. // CmidptcircleView drawing
  50. void plot(CDC* PDC,int xc,int yc,int x,int y, COLORREF color)
  51. {
  52.     PDC->SetPixel(xc+x,yc+y,color);
  53.     PDC->SetPixel(xc+x,yc-y,color);
  54.     PDC->SetPixel(xc-x,yc+y,color);
  55.     PDC->SetPixel(xc-x,yc-y,color);
  56.  
  57.     PDC->SetPixel(xc+y,yc+x,color);
  58.     PDC->SetPixel(xc-y,yc+x,color);
  59.     PDC->SetPixel(xc+y,yc-x,color);
  60.     PDC->SetPixel(xc-y,yc-x,color);
  61.    
  62. }
  63.  
  64.  
  65. void drawcircle(CDC* pDC,int xc, int yc, int r, COLORREF color)
  66. {
  67.  
  68.     /*
  69.  
  70.     Set X = 0 and Y = R
  71. 2. Set P = 1 – R
  72. 3. Repeat While (X < Y)
  73. 4. Call Draw Circle(Xc, Yc, X, Y)
  74. 5. Set X = X + 1
  75. 6. If (P < 0) Then
  76. 7. P = P + 2X + 1
  77. 8. Else
  78. 9. Set Y = Y – 1
  79. 10. P = P + 2(X – Y) + 1
  80. [End of If]
  81. 11. Call Draw Circle(Xc, Yc, X, Y)
  82. [End of While]
  83. 12. Exit
  84.     */
  85.  
  86.  
  87.     int x=0,y=r;
  88.     int p=1-r;
  89.     while(x<y)
  90.     {
  91.         plot(pDC,xc,yc,x,y,color);
  92.         x++;
  93.         if(p<0)
  94.         {
  95.             p+=2*x+1;
  96.         }
  97.         else
  98.         {
  99.             y--;
  100.             p+=2*(x-y)+1;
  101.         }
  102.         plot(pDC,xc,yc,x,y,color);
  103.     }
  104.  
  105.  
  106.  
  107. }
  108.  
  109.  
  110.  
  111. void CmidptcircleView::OnDraw(CDC* pDC)
  112. {
  113.     CmidptcircleDoc* pDoc = GetDocument();
  114.     ASSERT_VALID(pDoc);
  115.     if (!pDoc)
  116.         return;
  117.  
  118.     //Draws the audi logo
  119.  
  120.     drawcircle(pDC,100,100,50,RGB(128,128,128));
  121.     drawcircle(pDC,100,100,48,RGB(128,128,128));
  122.     drawcircle(pDC,100,100,46,RGB(128,128,128));
  123.     drawcircle(pDC,100,100,52,RGB(128,128,128));
  124.     drawcircle(pDC,100,100,54,RGB(128,128,128));
  125.     drawcircle(pDC,100,100,56,RGB(128,128,128));
  126.  
  127.  
  128.  
  129.     drawcircle(pDC,156+20,100,50,RGB(128,128,128));
  130.     drawcircle(pDC,156+20,100,48,RGB(128,128,128));
  131.     drawcircle(pDC,156+20,100,46,RGB(128,128,128));
  132.     drawcircle(pDC,156+20,100,52,RGB(128,128,128));
  133.     drawcircle(pDC,156+20,100,54,RGB(128,128,128));
  134.     drawcircle(pDC,156+20,100,56,RGB(128,128,128));
  135.  
  136.     drawcircle(pDC,212+40,100,50,RGB(128,128,128));
  137.     drawcircle(pDC,212+40,100,48,RGB(128,128,128));
  138.     drawcircle(pDC,212+40,100,46,RGB(128,128,128));
  139.     drawcircle(pDC,212+40,100,52,RGB(128,128,128));
  140.     drawcircle(pDC,212+40,100,54,RGB(128,128,128));
  141.     drawcircle(pDC,212+40,100,56,RGB(128,128,128));
  142.  
  143.     drawcircle(pDC,268+60,100,50,RGB(128,128,128));
  144.     drawcircle(pDC,268+60,100,48,RGB(128,128,128));
  145.     drawcircle(pDC,268+60,100,46,RGB(128,128,128));
  146.     drawcircle(pDC,268+60,100,52,RGB(128,128,128));
  147.     drawcircle(pDC,268+60,100,54,RGB(128,128,128));
  148.     drawcircle(pDC,268+60,100,56,RGB(128,128,128));
  149.    
  150.     // TODO: add draw code for native data here
  151. }
  152.  
  153. void CmidptcircleView::OnRButtonUp(UINT /* nFlags */, CPoint point)
  154. {
  155.     ClientToScreen(&point);
  156.     OnContextMenu(this, point);
  157. }
  158.  
  159. void CmidptcircleView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
  160. {
  161. #ifndef SHARED_HANDLERS
  162.     theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
  163. #endif
  164. }
  165.  
  166.  
  167. // CmidptcircleView diagnostics
  168.  
  169. #ifdef _DEBUG
  170. void CmidptcircleView::AssertValid() const
  171. {
  172.     CView::AssertValid();
  173. }
  174.  
  175. void CmidptcircleView::Dump(CDumpContext& dc) const
  176. {
  177.     CView::Dump(dc);
  178. }
  179.  
  180. CmidptcircleDoc* CmidptcircleView::GetDocument() const // non-debug version is inline
  181. {
  182.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CmidptcircleDoc)));
  183.     return (CmidptcircleDoc*)m_pDocument;
  184. }
  185. #endif //_DEBUG
Advertisement
Add Comment
Please, Sign In to add comment