CircleTool.cpp
资源名称:CAD.zip [点击查看]
上传用户:hehe2haha
上传日期:2013-08-16
资源大小:161k
文件大小:3k
源码类别:
CAD
开发平台:
Visual C++
- // CircleTool.cpp: implementation of the CCircleTool class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "CircleTool.h"
- #include "Circle.h"
- #include "WinApp.h"
- extern CWinApp g_theApp;
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CCircleTool::CCircleTool()
- {
- }
- CCircleTool::~CCircleTool()
- {
- }
- void CCircleTool::OnMouseMove(HWND hWnd, UINT nFlags, POINT ptPos)
- {
- CDataBase *pDataBase = &(g_theApp.m_DataBase);
- if(m_eToolState == FirstHit)
- {
- HDC hdc = ::GetDC(hWnd);
- int nOldMode = ::SetROP2(hdc,R2_XORPEN);
- HPEN hPen = ::CreatePen( pDataBase->m_Shape.fnPenStyle,
- pDataBase->m_Shape.nWidth,
- pDataBase->m_Shape.crColor^ GetBkColor(hdc) );
- HPEN hOldPen = (HPEN)::SelectObject(hdc,hPen);
- //不进行填充
- ::SelectObject(hdc,GetStockObject(NULL_BRUSH));
- //擦去前一次线段
- int nRadius = CDraw::Distance(m_ptBeginPos,m_ptPrePos );
- CDraw::DrawCircle(hdc,m_ptBeginPos,nRadius);
- //画出这一次线段
- nRadius = CDraw::Distance(m_ptBeginPos,ptPos );
- CDraw::DrawCircle(hdc,m_ptBeginPos,nRadius);
- ::SetROP2(hdc,nOldMode);
- ::SelectObject(hdc,hOldPen);
- ::DeleteObject(hPen);
- ::ReleaseDC(hWnd,hdc);
- m_ptPrePos = ptPos;
- }
- }
- void CCircleTool::OnRButtonDown(HWND hWnd,UINT nFlags, POINT ptPos)
- {
- CDataBase *pDataBase = &(g_theApp.m_DataBase);
- if(m_eToolState == FirstHit)
- {
- HDC hdc = ::GetDC(hWnd);
- int nOldMode = ::SetROP2(hdc,R2_XORPEN);
- HPEN hPen = ::CreatePen( pDataBase->m_Shape.fnPenStyle,
- pDataBase->m_Shape.nWidth,
- pDataBase->m_Shape.crColor^ GetBkColor(hdc) );
- ::SelectObject(hdc,hPen);
- //不进行填充
- ::SelectObject(hdc,GetStockObject(NULL_BRUSH));
- //擦除
- int nRadius = CDraw::Distance(m_ptBeginPos,m_ptPrePos );
- CDraw::DrawCircle(hdc,m_ptBeginPos,nRadius);
- ::SetROP2(hdc,nOldMode);
- ::ReleaseDC(hWnd,hdc);
- }
- //取消画图状态
- OverCurTool(hWnd);
- }
- void CCircleTool::OnLButtonDown(HWND hWnd,UINT nFlags, POINT ptPos)
- {
- CDataBase *pDataBase = &(g_theApp.m_DataBase);
- CArray<CShape*> *pArrayShape = &(g_theApp.m_DataBase.m_ArrayShape);
- CCircle *pShape = NULL;
- if(m_eToolState == Init_State)
- {
- m_eToolState = FirstHit;
- m_ptBeginPos = m_ptPrePos = ptPos;
- }
- else if(m_eToolState == FirstHit)
- {
- m_eToolState = SecondHit;
- pShape = new CCircle;
- //保存图形样式
- pShape->crColor = pDataBase->m_Shape.crColor;
- pShape->fnPenStyle = pDataBase->m_Shape.fnPenStyle;
- pShape->nWidth = pDataBase->m_Shape.nWidth;
- pShape->m_ptFirstPos = m_ptBeginPos;
- pShape->m_ptSecondPos = ptPos;
- pShape->nRadius = CDraw::Distance(pShape->m_ptFirstPos,
- pShape->m_ptSecondPos);
- //第一点和第二点不重合才保存
- if (pShape->m_ptFirstPos.x != ptPos.x ||
- pShape->m_ptFirstPos.y != ptPos.y)
- {
- //保存至数组
- pArrayShape->Add(pShape);
- }
- else
- {
- delete pShape;
- pShape = NULL;
- }
- //取消画图状态
- OverCurTool(hWnd);
- }
- }