镜像和平移只要使用实体集中相关的函数即可,同时利用镜像类和平移类实现
class CMirror : public CComand
{
public:
CMirror();
virtual ~CMirror();
public:
void OnLButtonDown(UINT nFlags, CPosition pos);
void OnMouseMove(UINT nFlags, CPosition pos);
void OnRButtonDown(UINT nFlags, CPosition pos);
private:
CHandleCG* m_hand;
CEraseLine m_erase_line;//追踪类
CPosition m_begin;
CPosition m_end;
};
class CMove : public CComand//全局即时平移命令
{
public:
CMove();
virtual ~CMove();
public:
void OnLButtonDown(UINT nFlags, CPosition pos);
void OnMouseMove(UINT nFlags, CPosition pos);
void OnRButtonDown(UINT nFlags, CPosition pos);
void OnLButtonUp(UINT nFlags, CPosition pos);
void OnMButtonDown(UINT nFlags, CPosition pos);
void OnMButtonUp(UINT nFlags, CPosition pos);
public:
CPosition m_begin;
CPosition m_end;
};
CMove::CMove()
{
m_nStep = 1;
}
CMove::~CMove()
{
}
void CMove::OnLButtonDown(UINT nFlags, CPosition pos)
{
}
void CMove::OnMouseMove(UINT nFlags, CPosition pos)
{
switch(m_nStep)
{
case 2 :
{
CDC *pDC = g_pView->GetDC();
for (int i = 0; i < (g_pDoc->m_solid).GetSize(); i++)
{
(g_pDoc->m_solid[i])->Move(m_begin, pos)->DrawSolid(pDC, Normal);
}
for (i = 0; i < g_pDoc->m_select.GetSize(); i++)
{
(g_pDoc->m_select[i])->Move(m_begin, pos)->DrawSolid(pDC, Normal);
}
m_begin = pos;
g_pView->Invalidate();
g_pView->ReleaseDC(pDC);
}
break;
default:
break;
}
}
void CMove::OnRButtonDown(UINT nFlags, CPosition pos)
{
}
void CMove::OnLButtonUp(UINT nFlags, CPosition pos)
{
m_nStep = 1;
}
void CMove::OnMButtonDown(UINT nFlags, CPosition pos)
{
switch(m_nStep)
{
case 1 :
{
m_begin = m_end = pos;
m_nStep++;
break;
}
case 2 :
{
m_nStep = 1;
break;
}
default:
break;
}
}
void CMove::OnMButtonUp(UINT nFlags, CPosition pos)
{
m_nStep = 1;
}
CBaseMove::CBaseMove()//带基点的平移类
{
m_nStep = 1;
}
CBaseMove::~CBaseMove()
{
}
CMirror::CMirror()//镜像
{
m_nStep = 1;
m_hand = new CHandleCG(&g_pDoc->m_solid, &g_pDoc->m_select);
}
CMirror::~CMirror()
{
}
void CMirror::OnLButtonDown(UINT nFlags, CPosition pos)
{
switch(m_nStep)
{
case 1://输出提示信息
{
m_begin = pos;
m_nStep++;
m_erase_line.SetBegin(pos); //八个方向,并且如果在指定范围内,得到按下的点的坐标
break;
}
case 2:
{
m_erase_line.SetBegin(pos);
CDC *pDC = g_pView->GetDC();
// m_hand->Mirror(m_begin, pos, Normal);
m_nStep = 1;
g_pView->ReleaseDC(pDC);
}
default:
break;
}
}
void CMirror::OnMouseMove(UINT nFlags, CPosition pos)
{
m_erase_line.SetEnd(pos);
switch(m_nStep)
{
case 2:
CDC *pDC = g_pView->GetDC();
m_hand->Mirror(m_begin, m_end, Drag);
// g_pDoc->DrawSolid(pDC, Normal);//重画
m_hand->Mirror(m_begin, pos, Normal);
m_end = pos;
g_pView->ReleaseDC(pDC);
break;
}
}
void CMirror::OnRButtonDown(UINT nFlags, CPosition pos)
{
m_erase_line.SetCancle(pos);
}