gpt4 book ai didi

c++ - 为什么在这里需要两次函数 Ellipse(...) 来绘制椭圆?

转载 作者:行者123 更新时间:2023-11-28 07:56:51 25 4
gpt4 key购买 nike

MFC:我读到这段代码是绘制一个椭圆(内部不是实体),但我不明白为什么这里需要两次函数“pDC->Ellipse(...)”?(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(...) 的第二次调用,椭圆将永远不会被绘制,但会在鼠标左键弹起时消失。

对话框: 移动鼠标时: enter image description here鼠标移动(笔是绿色的)

当鼠标按钮弹出时: enter image description here鼠标按键弹出(笔是绿色的)

另外,如果我用CBrush是什么颜色"CBrush画笔;pDC->Ellipse(start.x,assist.y,end.x,end.y);"

当涉及到矩形时,策略可能会更清晰:

             ...
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;
}
...

最佳答案

是因为调用了pDC->SetROP2(R2_NOT)。根据 MSDN,R2_NOT 标志表示“像素保持不变”。您可以在此处阅读文档 - http://msdn.microsoft.com/en-us/library/99ax95h9.aspx .

关于c++ - 为什么在这里需要两次函数 Ellipse(...) 来绘制椭圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12532470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com