Circle.cpp
资源名称:CAD.zip [点击查看]
上传用户:hehe2haha
上传日期:2013-08-16
资源大小:161k
文件大小:2k
源码类别:
CAD
开发平台:
Visual C++
- // Circle.cpp: implementation of the CCircle class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Circle.h"
- #include "WinApp.h"
- extern CWinApp g_theApp;
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CCircle::CCircle()
- {
- strcpy(m_className,"CCircle");
- nRadius = 0;
- }
- CCircle::~CCircle()
- {
- }
- void CCircle::Draw(HDC hdc)
- {
- HPEN hPen = ::CreatePen( fnPenStyle,nWidth,crColor);
- HPEN hOldPen = (HPEN)::SelectObject(hdc,hPen);
- //不进行填充
- ::SelectObject(hdc,GetStockObject(NULL_BRUSH));
- if (nRadius == 0)
- {
- nRadius = CDraw::Distance(m_ptFirstPos,m_ptSecondPos);
- }
- CDraw::DrawCircle(hdc,m_ptFirstPos,nRadius);
- ::SelectObject(hdc,hOldPen);
- ::DeleteObject(hPen);
- if(isPick == TRUE)
- {
- //恢复填充
- ::SelectObject(hdc,GetStockObject(WHITE_BRUSH));
- DrawRect(hdc);
- }
- }
- void CCircle::DrawRect(HDC hdc)
- {
- POINT t_ptFirstPos,t_ptSecondPos;
- //外接矩形的左上点和右下点坐标
- t_ptFirstPos.x = m_ptFirstPos.x - nRadius;
- t_ptSecondPos.x = m_ptFirstPos.x + nRadius;
- t_ptFirstPos.y = m_ptFirstPos.y - nRadius;
- t_ptSecondPos.y = m_ptFirstPos.y + nRadius;
- //圆心的坐标
- int mPtx = m_ptFirstPos.x;
- int mPty = m_ptFirstPos.y;
- //top left
- Ellipse(hdc,t_ptFirstPos.x - Rect,t_ptFirstPos.y - Rect,
- t_ptFirstPos.x + Rect,t_ptFirstPos.y + Rect);
- //top right
- Ellipse(hdc,t_ptSecondPos.x - Rect,t_ptFirstPos.y - Rect,
- t_ptSecondPos.x + Rect,t_ptFirstPos.y + Rect);
- //top middle
- Ellipse(hdc,mPtx - Rect,t_ptFirstPos.y - Rect,
- mPtx + Rect,t_ptFirstPos.y + Rect);
- //left middle
- Ellipse(hdc,t_ptFirstPos.x - Rect,mPty - Rect,
- t_ptFirstPos.x + Rect,mPty + Rect);
- //right middle
- Ellipse(hdc,t_ptSecondPos.x - Rect,mPty - Rect,
- t_ptSecondPos.x + Rect,mPty + Rect);
- //buttom middle
- Ellipse(hdc,mPtx - Rect,t_ptSecondPos.y - Rect,
- mPtx + Rect,t_ptSecondPos.y + Rect);
- //buttom left
- Ellipse(hdc,t_ptFirstPos.x - Rect,t_ptSecondPos.y - Rect,
- t_ptFirstPos.x + Rect,t_ptSecondPos.y + Rect);
- //buttom right
- Ellipse(hdc,t_ptSecondPos.x - Rect,t_ptSecondPos.y - Rect,
- t_ptSecondPos.x + Rect,t_ptSecondPos.y + Rect);
- }
- BOOL CCircle::pick(POINT pt)
- {
- //计算当前鼠标位置与圆心的距离
- int dblLength = CDraw::Distance(m_ptFirstPos,pt);
- if (fabs(dblLength - nRadius) > 5)
- return FALSE;
- return TRUE;
- }