图形编辑器:绘制和更改形状(Windows GDI)

发布于 2024-09-30 02:21:59 字数 897 浏览 2 评论 0原文

我需要在画布上绘制、移动、更改形状(矩形、圆形等)(由标准“静态控制”表示)。所有绘图操作均通过标准GDI函数实现。

我是这样实现的:(

例如移动形状,其他操作使用相同的原理)

...

// Before any actions set foreground mix mode:

SetROP2(hdc_, R2_NOTXORPEN); 

...

void OnMouseDown(...)
{
  SelectShapeUnderCursor();
}

void OnMouseMove(...)
{
  ... 
  DrawShape(old_points); // Eraise shape at old position (drawing with the same pen's color, see description of R2_NOTXORPEN mode)
  DrawShape(new_points); // Draw shape at new position
  ...
}

void OnMouseUp(...)
{
  DrawShape(new_points); // Final draw shape
}

在这种情况下形状正确地移动和改变。但最大的问题是形状的颜色不好。例如,当具有绿色颜色时,形状白色上具有绿色颜色背景和黑色背景上的红色。这是 R2_NOTXORPEN 混合模式的正常行为。

但我想要形状与笔颜色相同。我必须拒绝R2_NOTXORPEN混合模式,但是如何正确实现移动、改变形状等操作呢?如果需要的话我可以使用 GDI+。

I need to draw, move, change shapes (rectangles, circles an so one) on canvas (represented by standard "Static Control"). All drawing operations are realized by standard GDI functions.

I've realized it like this:

(example for moving shape, other operations use the same principle)

...

// Before any actions set foreground mix mode:

SetROP2(hdc_, R2_NOTXORPEN); 

...

void OnMouseDown(...)
{
  SelectShapeUnderCursor();
}

void OnMouseMove(...)
{
  ... 
  DrawShape(old_points); // Eraise shape at old position (drawing with the same pen's color, see description of R2_NOTXORPEN mode)
  DrawShape(new_points); // Draw shape at new position
  ...
}

void OnMouseUp(...)
{
  DrawShape(new_points); // Final draw shape
}

In this case shapes correctly moving and changing. But great problem is bad colors of shapes. For example, when pen has green color, shape has green color on white background and red on black background. It's normal behavior for R2_NOTXORPEN mix mode.

But I want to shapes have same color as pen. I must refuse of R2_NOTXORPEN mix mode, but how to correctly realize operations like moving, changing shapes? I may use GDI+, if needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

马蹄踏│碎落叶 2024-10-07 02:21:59

这就是 Windows 3.x 时代的做法,当时您拥有的只是 386SUX。现在,您只需更新内部形状列表并调用 InvalidateRect 即可让 WM_PAINT 消息处理程序重新渲染所有形状。不需要异或技巧及其令人讨厌的副作用。当开始闪烁时进行双缓冲。

This is the way it was done back in the Windows 3.x days when all you had was a 386SUX. Now you just update the internal shape list and call InvalidateRect to let the WM_PAINT message handler re-render all shapes. No need for XOR tricks and its fugly side-effects. Double-buffer when it starts to flicker.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文