void CEView:: MidpointCircle (CDC pDC, int radius, CPoint cenp, COLORREF crColor)
{
int x=0;
int y=radius;
int d=1-radius;
CirclePoints(pDC,x,y,cenp,crColor);
while(y>=x)
{ if(d<0)
d+=2*x+3;
else{
d+=2(x-y)+5;
y--;
}
x++;
CirclePoints(pDC,x,y,cenp,crColor);
}
}
void CEView::CirclePoints(CDC pDC, int x, int y, CPoint cenp, COLORREF br)
{
pDC->SetPixel(x+cenp.x,y+cenp.y,br);
pDC->SetPixel(y+cenp.x,x+cenp.y,br);
pDC->SetPixel(y+cenp.x,-x+cenp.y,br);
pDC->SetPixel(x+cenp.x,-y+cenp.y,br);
pDC->SetPixel(-x+cenp.x,-y+cenp.y,br);
pDC->SetPixel(-y+cenp.x,-x+cenp.y,br);
pDC->SetPixel(-y+cenp.x,x+cenp.y,br);
pDC->SetPixel(-x+cenp.x,y+cenp.y,br);
}
void CEView::Onyuan()
{
// TODO: Add your command handler code here
m_yuan=1;
}
void CEView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_yuan==1)
{
m_Centerp=m_Aroundp=point;
}
CView::OnLButtonDown(nFlags, point);
}
void CEView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC pDC=GetDC();
if(m_yuan==1)
m_Aroundp=point;
DrawCircle(pDC,m_Centerp,m_Aroundp);
}
ReleaseDC(pDC);
CView::OnLButtonUp(nFlags, point);
}
void CEView::DrawCircle(CDC pDC, CPoint cenp, CPoint ardp)
{
int ra,a,b;
a=(ardp.x-cenp.x)(ardp.x-cenp.x);
b=(ardp.y-cenp.y)*(ardp.y-cenp.y);
ra=(int)(sqrt(a+b));
pDC->Ellipse(cenp.x-ra,cenp.y-ra,cenp.x+ra,cenp.y+ra);
MidpointCircle(pDC,ra,cenp,cl);
}
void CEView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC=GetDC();
int nDrawmode=pDC->SetROP2(R2_NOT);
if(m_yuan==1 & nFlags & MK_LBUTTON )
{
CPoint prePnt,curPnt;
prePnt=m_Aroundp;
curPnt=point;
DrawCircle(pDC,m_Centerp,prePnt);
DrawCircle(pDC,m_Centerp,curPnt);
m_Aroundp=point;
}
pDC->SetROP2(nDrawmode);
ReleaseDC(pDC);
CView::OnMouseMove(nFlags, point);
}
void CEView::OnColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
dlg.DoModal();
cl=dlg.GetColor();
}