Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // reflectionView.cpp : implementation of the CreflectionView class
- //
- #include "stdafx.h"
- // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
- // and search filter handlers and allows sharing of document code with that project.
- #ifndef SHARED_HANDLERS
- #include "reflection.h"
- #endif
- #include "reflectionDoc.h"
- #include "reflectionView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CreflectionView
- IMPLEMENT_DYNCREATE(CreflectionView, CView)
- BEGIN_MESSAGE_MAP(CreflectionView, CView)
- ON_WM_CONTEXTMENU()
- ON_WM_RBUTTONUP()
- END_MESSAGE_MAP()
- // CreflectionView construction/destruction
- CreflectionView::CreflectionView()
- {
- // TODO: add construction code here
- }
- CreflectionView::~CreflectionView()
- {
- }
- BOOL CreflectionView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- // CreflectionView drawing
- POINT reflect(POINT p, int type)
- {
- POINT a;
- switch(type)
- {
- case 1: //about x axis
- a.x=p.x;
- a.y=-p.y;
- break;
- case 2: //about y axis
- a.x=-p.x;
- a.y=p.y;
- break;
- case 3: //about xy axis
- a.x=-p.x;
- a.y=-p.y;
- break;
- }
- return a;
- }
- POINT translate(POINT x,POINT origin)
- {
- x.x-=origin.x;
- x.y-=origin.y;
- return x;
- }
- POINT translate_back(POINT x,POINT origin)
- {
- x.x+=origin.x;
- x.y+=origin.y;
- return x;
- }
- void CreflectionView::OnDraw(CDC* x)
- {
- CreflectionDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if (!pDoc)
- return;
- //draw line, origin at 500,250
- POINT origin;
- origin.x=500;
- origin.y=250;
- x->MoveTo(500,0);
- x->LineTo(500,1000);
- x->MoveTo(0,250);
- x->LineTo(1000,250);
- //draw triangle
- POINT a,b,c;
- a.x=250;
- a.y=75;
- b.x=250;
- b.y=200;
- c.x=400;
- c.y=200;
- x->MoveTo(a);
- x->LineTo(b);
- x->LineTo(c);
- x->LineTo(a);
- a=translate(a,origin);
- b=translate(b,origin);
- c=translate(c,origin);
- POINT a1,b1,c1,a2,b2,c2,a3,b3,c3;
- //reflect and draw about x axis
- a1=reflect(a,1);
- b1=reflect(b,1);
- c1=reflect(c,1);
- a1=translate_back(a1,origin);
- b1=translate_back(b1,origin);
- c1=translate_back(c1,origin);
- x->MoveTo(a1);
- x->LineTo(b1);
- x->LineTo(c1);
- x->LineTo(a1);
- //reflect and draw about y axis
- a2=reflect(a,2);
- b2=reflect(b,2);
- c2=reflect(c,2);
- a2=translate_back(a2,origin);
- b2=translate_back(b2,origin);
- c2=translate_back(c2,origin);
- x->MoveTo(a2);
- x->LineTo(b2);
- x->LineTo(c2);
- x->LineTo(a2);
- //reflect and draw about xy axis
- a3=reflect(a,3);
- b3=reflect(b,3);
- c3=reflect(c,3);
- a3=translate_back(a3,origin);
- b3=translate_back(b3,origin);
- c3=translate_back(c3,origin);
- x->MoveTo(a3);
- x->LineTo(b3);
- x->LineTo(c3);
- x->LineTo(a3);
- // TODO: add draw code for native data here
- }
- void CreflectionView::OnRButtonUp(UINT /* nFlags */, CPoint point)
- {
- ClientToScreen(&point);
- OnContextMenu(this, point);
- }
- void CreflectionView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
- {
- #ifndef SHARED_HANDLERS
- theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
- #endif
- }
- // CreflectionView diagnostics
- #ifdef _DEBUG
- void CreflectionView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CreflectionView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CreflectionDoc* CreflectionView::GetDocument() const // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CreflectionDoc)));
- return (CreflectionDoc*)m_pDocument;
- }
- #endif //_DEBUG
Advertisement
Add Comment
Please, Sign In to add comment