为什么在这里需要两次绘制椭圆函数Ellipse(...)? [英] Why function Ellipse(...) are needed twice here to draw an ellipse?
问题描述
MFC: 我读了这段绘制椭圆(不是实心内部)的代码,但是我不明白为什么这里需要两次函数"pDC-> Ellipse(...)"? (sol == 0,和do_what == DRAW_ELLIPSE)
MFC: I read this code which is to draw an ellipse (not solid interior), but I cannot understand why function "pDC->Ellipse(...)" is needed twice here? (sol == 0, and do_what==DRAW_ELLIPSE)
void CMy078207017Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
flag = 0;
end = point;
assist = point;
if(p != NULL)
{
CDC* pDC = GetDC();
CPen pen;
CBrush brush;
getpen(pen, pDC, col, bol);
if(do_what >= DRAW_LINE && do_what <= DRAW_RRECT)
{
p->p[0] = start;
p->p[1] = end;
}
if(sol == 1)
{
getbrush(brush, pDC, col);
}
if(do_what == DRAW_LINE)
{
pDC->MoveTo(start);
pDC->LineTo(end);
}
else
{
if(do_what == DRAW_ELLIPSE || do_what == DRAW_CIRCLE)
{
assist = start;
if(do_what == DRAW_CIRCLE)
{
assist.y = end.y - end.x + start.x;
}
pDC->SetROP2(R2_NOT);
pDC->Ellipse(start.x, assist.y, end.x, end.y);
pDC->SetROP2(R2_COPYPEN);
if(sol == 0)
{
pDC->SelectStockObject(NULL_BRUSH);
}
pDC->Ellipse(start.x, assist.y, end.x, end.y);
end = point;
}
}
ReleaseDC(pDC);
}
CDialog::OnLButtonUp(nFlags, point);
}
如果我删除对pDC-> Ellipse(...)的第一个调用,则椭圆内部将是黑色实心的. 如果我删除对pDC-> Ellipse(...)的第二次调用,则椭圆将永远不会绘制,但是当鼠标左键向上时椭圆会消失.
If I remove the first call to pDC->Ellipse(...), the ellipse will be black solid inside. If I remove the second call to pDC->Ellipse(...), the ellipse will never be drawn but disappears when left mouse button is up.
对话框: 移动鼠标时: 鼠标移动(笔为绿色)
the dialog: when moving mouse: mouse moving(the pen is green)
当鼠标按钮弹出时: 鼠标按钮弹出(笔为绿色)
when mouse button pops: mouse button pops(the pen is green)
此外,如果我使用CBrush是什么颜色 "CBrush画笔; pDC-> Ellipse(start.x,assist.y,end.x,end.y);"
Besides, what color of CBrush is if I use "CBrush brush; pDC->Ellipse(start.x,assist.y,end.x,end.y);"
当涉及到矩形时,该策略可能会更清晰:
the strategy may be more clear when it comes to rectangle:
...
else if(do_what==DRAW_RECT||do_what==DRAW_RRECT){
pDC->SetROP2(R2_NOT);
if(do_what==DRAW_RECT)
{
pDC->Rectangle(start.x,start.y,end.x,end.y);
}
else if(do_what==DRAW_RRECT)
{
pDC->RoundRect(start.x,start.y,end.x,end.y,20,20);
}
pDC->SetROP2(R2_COPYPEN);
if(sol==0)
{
pDC->SelectStockObject(NULL_BRUSH);
}
if(do_what==DRAW_RECT)
{
pDC->Rectangle(start.x,start.y,point.x,point.y);
}
else if(do_what==DRAW_RRECT)
{
pDC->RoundRect(start.x,start.y,point.x,point.y,20,20);
}
end=point;
}
...
推荐答案
我终于摆脱了麻烦: 其他地方的代码:
I finally get out of the trouble: codes elsewhere:
void CDraw2009303476Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(flag == 1)
{
CDC* pDC = GetDC();
CPen pen;
CBrush brush;
getPen(pen, pDC, col, bol);
if(sol == 1)
{
getBrush(brush, pDC, col);
}
if(type >= DRAW_LINE && type <= DRAW_RRECT)
{
pDC->SetROP2(R2_NOT);
if(type == DRAW_LINE)
{
p->drawLine(point, pDC);
}
else if(type == DRAW_ELLIPSE)
{
p->drawEllipse(point, pDC);
}
else if(type == DRAW_CIRCLE)
{
p->drawEllipse(point, pDC, 1);
}
else if(type == DRAW_RECT)
{
p->drawRect(point, pDC);
}
else if(type == DRAW_RRECT)
{
p->drawRect(point, pDC, 1);
}
}
ReleaseDC(pDC);
}
CDialog::OnMouseMove(nFlags, point);
}
因此,策略是:使用"pDC-> SetROP2(R2_NOT);"一次,然后"p-> drawEllipse(point,pDC,1);"在同一位置两次保存原始像素以获得线条画效果. 最后需要调用"pDC-> SetROP2(R2_COPYPEN); p-> drawEllipse(point,pDC,1)",这才是我们真正看到省略号的地方. 谢谢您的所有帮助.
So, the strategy is: Using "pDC->SetROP2(R2_NOT);" once and "p->drawEllipse(point, pDC, 1);" twice in the same place to save the original pixels to get the line-drawing effects. And the final call to "pDC->SetROP2(R2_COPYPEN); p->drawEllipse(point, pDC, 1)" is what we really need to see the ellipsis. Thank you for all your helps.
这篇关于为什么在这里需要两次绘制椭圆函数Ellipse(...)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!