DrawEllipse.cpp
资源名称:DrawSys.zip [点击查看]
上传用户:mosfetic
上传日期:2022-06-16
资源大小:4612k
文件大小:4k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // DrawEllipse.cpp: implementation of the CDrawEllipse class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "DrawSys.h"
- #include "DrawEllipse.h"
- #include "ViewProperty.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- IMPLEMENT_SERIAL(CDrawEllipse, CObject, 1)
- CDrawEllipse::CDrawEllipse()
- {
- m_ptFirst.x = m_ptFirst.y = 0;
- m_ptSecond.x = m_ptSecond.y = 0;
- m_ptTemp.x = m_ptTemp.y = 0;
- m_bStart = FALSE;
- }
- CDrawEllipse::~CDrawEllipse()
- {
- }
- void CDrawEllipse::Draw(CDC* pDC)
- {
- CRect rcDraw;
- CBrush* pBrush = NULL;
- CBrush* pOldBrush = NULL;
- pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
- pOldBrush = pDC->SelectObject(pBrush);
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptSecond.x;
- rcDraw.bottom = m_ptSecond.y;
- pDC->Ellipse(&rcDraw);
- pDC->SelectObject(pOldBrush);
- }
- void CDrawEllipse::OnMouseMove(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- CRect rcDraw;
- CBrush* pBrush = NULL;
- CBrush* pOldBrush = NULL;
- if(m_bStart)
- {
- if(pDC)
- {
- pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
- pOldBrush = pDC->SelectObject(pBrush);
- iDrawMode = pDC->SetROP2(R2_NOTXORPEN);
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Ellipse(&rcDraw);
- m_ptTemp = point;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Ellipse(&rcDraw);
- pDC->SetROP2(iDrawMode);
- pDC->SelectObject(pOldBrush);
- }
- }
- }
- void CDrawEllipse::OnLButtonDown(CDC* pDC, UINT nFlags, CPoint point)
- {
- m_ptFirst = point;
- m_ptTemp = point;
- m_bStart = TRUE;
- }
- BOOL CDrawEllipse::OnLButtonUp(CDC* pDC, UINT nFlags, CPoint point)
- {
- int iDrawMode = 0;
- CRect rcDraw;
- CBrush* pBrush = NULL;
- CBrush* pOldBrush = NULL;
- if(m_bStart)
- {
- if(pDC)
- {
- pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
- pOldBrush = pDC->SelectObject(pBrush);
- iDrawMode = pDC->SetROP2(R2_NOTXORPEN);
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptTemp.x;
- rcDraw.bottom = m_ptTemp.y;
- pDC->Ellipse(&rcDraw);
- m_ptSecond = point;
- m_ptTemp = point;
- rcDraw.left = MIN(m_ptFirst.x, m_ptSecond.x);
- rcDraw.top = MIN(m_ptFirst.y, m_ptSecond.y);
- rcDraw.right = MAX(m_ptFirst.x, m_ptSecond.x);
- rcDraw.bottom = MAX(m_ptFirst.y, m_ptSecond.y);
- m_ptFirst.x = rcDraw.left;
- m_ptFirst.y = rcDraw.top;
- m_ptSecond.x = rcDraw.right;
- m_ptSecond.y = rcDraw.bottom;
- pDC->SetROP2(R2_COPYPEN);
- Draw(pDC);
- pDC->SetROP2(iDrawMode);
- pDC->SelectObject(pOldBrush);
- }
- m_bStart = FALSE;
- }
- return (!rcDraw.IsRectEmpty());
- }
- void CDrawEllipse::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- ar << m_ptFirst << m_ptSecond;
- }
- else
- {
- // TODO: add loading code here
- ar >> m_ptFirst >> m_ptSecond;
- }
- }
- BOOL CDrawEllipse::PtInShape(CPoint point)
- {
- CRect rcDraw;
- CRgn rgn;
- BOOL m_bRetVal = FALSE;
- rcDraw.left = MIN(m_ptFirst.x, m_ptSecond.x);
- rcDraw.top = MIN(m_ptFirst.y, m_ptSecond.y);
- rcDraw.right = MAX(m_ptFirst.x, m_ptSecond.x);
- rcDraw.bottom = MAX(m_ptFirst.y, m_ptSecond.y);
- rgn.CreateEllipticRgnIndirect(&rcDraw);
- m_bRetVal = rgn.PtInRegion(point);
- rgn.DeleteObject();
- return m_bRetVal;
- }
- void CDrawEllipse::ShowProperty()
- {
- CRect rcDraw;
- CString strID;
- CString strTime;
- CViewProperty dlg;
- rcDraw.left = m_ptFirst.x;
- rcDraw.top = m_ptFirst.y;
- rcDraw.right = m_ptSecond.x;
- rcDraw.bottom = m_ptSecond.y;
- dlg.m_strType = "椭圆";
- MyFormatString(dlg.m_strID, m_iID);
- dlg.m_iLength = rcDraw.Width();
- dlg.m_iWidth = rcDraw.Height();
- dlg.m_strTime = m_tmCreate.Format("%Y - %m - %d");
- dlg.DoModal();
- }