case 5: //圆 radius = abs(p_point1.x - p_point2.x) / 2; centerX = min(p_point1.x, p_point2.x) + radius; centerY = min(p_point1.y, p_point2.y) + radius; du.Ellipse(centerX - radius, centerY - radius, centerX + radius, centerY + radius); pGraph = new P_Picture(pchoice, p_color, p_brush, p_point1, p_point2); m_ptrArray.Add(pGraph);你能否修改case5之后的代码来实现一种新的绘画出圆的方法
时间: 2024-03-19 22:43:04 浏览: 162
当然可以,以下是一个实现绘画空心圆的新代码:
```cpp
case 5:
// 空心圆
radius = abs(p_point1.x - p_point2.x) / 2;
centerX = min(p_point1.x, p_point2.x) + radius;
centerY = min(p_point1.y, p_point2.y) + radius;
du.Ellipse(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
pGraph = new P_Picture(pchoice, p_color, p_brush, p_point1, p_point2);
m_ptrArray.Add(pGraph);
// 绘制空心圆的边框
CPen pen(PS_SOLID, 1, p_color);
CPen *oldPen = du.SelectObject(&pen);
CBrush *oldBrush = du.SelectStockObject(NULL_BRUSH);
du.Ellipse(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
du.SelectObject(oldPen);
du.SelectObject(oldBrush);
break;
```
在原有代码的基础上,我们添加了绘制空心圆边框的部分。具体思路是,我们创建一个实心的画刷 NULL_BRUSH,将其选入画板中,创建一个与画笔颜色相同的画笔 pen,将其选入画板中,然后再次使用 du.Ellipse() 函数绘制圆即可。最后需要将原来的画刷和画笔恢复回去,否则可能会对后续的绘画产生影响。
阅读全文