在画线画圆等实体中都可拖动一个像皮筋类来重用,此像皮筋可以在8个方向,每隔45度指示方向
class CEraseLine//像皮筋类,可以在八个方向上画出像皮筋
{
public:
CEraseLine();
virtual ~CEraseLine();
public:
void SetBegin(CPosition begin);
void SetEnd(CPosition end);
void SetCancle(CPosition pos);
BOOL GetPoints(CPosition cen);//取得第二个实际点的坐标
void OnLButtonDown(UINT nFlags, CPosition pos);
void OnMouseMove(UINT nFlags, CPosition pos);
void OnRButtonDown(UINT nFlags, CPosition pos);
public:
CPosition m_begin;
CPosition m_end;
int m_nStep;
};
CEraseLine::CEraseLine()
{
m_nStep = 1;
}
CEraseLine::~CEraseLine()
{
}
void CEraseLine::SetBegin(CPosition begin)
{
OnLButtonDown(0, begin);
}
void CEraseLine::SetEnd(CPosition end)
{
OnMouseMove(0, end);
GetPoints(end);
}
BOOL CEraseLine::GetPoints(CPosition cen)//如果第二个点改变,则反回改变后的点
{
CLine *line[8];
CDC * pDC = g_pView->GetDC();
for (int i = 0; i < 8; i++)
{
line[i] = new CLine(m_begin, m_begin + CPosition(cos( 45 * i * PI / 180), sin( 45 * i * PI /180)) * 1000);
if ( line[i]->PickSolid(m_end, g_pView->m_scale* 5 ) &&m_nStep == 2)//只在过程中画
{
line[i]->DrawSolid(pDC,Select);
}
else
{
line[i]->DrawSolid(pDC,Back);
}
delete line[i];
}
g_pView->ReleaseDC(pDC);
return TRUE;
}
void CEraseLine::OnLButtonDown(UINT nFlags, CPosition pos)
{
switch(m_nStep)
{
case 1://输出提示信息
{
m_end = m_begin = pos;
m_nStep++;
break;
}
case 2:
{
m_end = pos;
CDC *pDC = g_pView->GetDC();
CLine *line1 = new CLine(m_begin, m_end);//画像皮线,消除上一个
line1->DrawSolid(pDC,Drag);
delete line1;
g_pView->ReleaseDC(pDC);
m_nStep = 1;
}
default:
break;
}
}
void CEraseLine::OnMouseMove(UINT nFlags, CPosition pos)
{
switch(m_nStep)
{
case 2:
CDC *pDC = g_pView->GetDC();
CLine *line1 = new CLine(m_begin, m_end);//画像皮线,消除上一个
line1->DrawSolid(pDC,Drag);
delete line1;
g_pView->m_suject->Notify();
CLine *line = new CLine(m_begin, pos);//画像皮线,最后一个
line->DrawSolid(pDC,Normal);
delete line;
m_end = pos;
g_pView->ReleaseDC(pDC);
break;
}
}
void CEraseLine::OnRButtonDown(UINT nFlags, CPosition pos)
{
CDC *pDC = g_pView->GetDC();
CLine *line1 = new CLine(m_begin, pos);//画像皮线,消除上一个
line1->DrawSolid(pDC,Back);
delete line1;
g_pView->ReleaseDC(pDC);
m_nStep = 1;
}
void CEraseLine::SetCancle(CPosition pos)
{
OnRButtonDown(0, pos);
}
int g_Refresh = 0;//记录屏幕刷新次数
int c_Refresh = 0;
CCreateLine::CCreateLine()
{
m_nStep = 1;
c_Refresh = g_Refresh;
}
CCreateLine::~CCreateLine()
{
}