wxWidgets 中类似绘画程序的绘图工具

发布于 2024-11-05 19:37:51 字数 401 浏览 6 评论 0原文

我正在 wxWidgets 中制作一个程序,它具有与 MS Paint 类似的功能,但用于更具体的目的。

我了解创建钢笔/铅笔对象的各种方法,当您拖动鼠标时该对象会提交单个像素。我在可视化中遇到麻烦的一件事是其他一些常用工具:矩形、椭圆形、直线等。对于这些工具,您可以按鼠标左键设置原点,当您在其周围拖动鼠标时,会暂时呈现一个从原点到当前鼠标位置在画布上覆盖形状,最终在释放鼠标按钮时将形状提交到图像。

创建此流程的最佳方法是什么?我能想到的唯一解决方案是在鼠标按下时存​​储原点,并在拖动鼠标时将临时变量设置为当前鼠标位置。每次鼠标位置发生变化时,从原点到存储的鼠标位置的矩形都会失效。一旦释放鼠标按钮,形状就会被提交给图像模型。

我还没有实现这个,因为我想先得到反馈。这是最佳解决方案,还是容易导致明显的闪烁,是否有更好的解决方案可用?

I'm making a program in wxWidgets that has similar functionality to, say, MS Paint, but for more specific purposes.

I understand various ways to create the pen/pencil object which commits a single pixel as you drag the mouse around. One thing I'm having trouble visualizing are some of the other common tools: rectangle, oval, line, etc. For these, you press the left mouse button to set an origin point, and as you drag your mouse around it temporarily renders an overlay of the shape on the canvas from the origin to the current mouse position, finally committing the shape to the image when the mouse button is released.

What is the best way to create this process? The only solution I can think of is to store the origin point on mouse-down, and as the mouse is dragged to set a temporary variable to the current mouse position. Each time the mouse position changes, you would invalidate the rectangle from the origin point to the stored mouse position. Once the mouse button is released, the shape would be committed to the image model.

I haven't implemented this yet, as I would like feedback first. Is this the optimal solution, or is it prone to cause a visible flicker, with a much more preferable solution available?

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

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

发布评论

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

评论(2

咿呀咿呀哟 2024-11-12 19:37:51

视频显示硬件现在是如此之快,您可能不需要费心任何这样的聪明才智。

这是一种更简单的方法。

- *Mouse moves with button down and tool X selected*
- IF flagToolInUse THEN remove previous from image model
- flagToolInUse = TRUE
- Update image model with tool X
- Draw image to invisible buffer
- Copy buffer to display
- Done

- *Button released*
- flagToolInUse = FALSE
- Done

这种方法的真正优点是您可以编写一次代码,并用于图像的每次更改,无论使用什么工具。

如果您需要有关使用 wxWidgets 实现无闪烁双缓冲显示的更多详细信息,请参阅以下简介 (主要是窗户)

Video display hardware is now so fast, you likely do not need to bother with any such cleverness.

Here is a simpler approach

- *Mouse moves with button down and tool X selected*
- IF flagToolInUse THEN remove previous from image model
- flagToolInUse = TRUE
- Update image model with tool X
- Draw image to invisible buffer
- Copy buffer to display
- Done

- *Button released*
- flagToolInUse = FALSE
- Done

The real advantage of this is you can write the code once, and use for every change to the image, no matter what tool is being used.

If you need more details on implementing flicker-free double-buffered display with wxWidgets, here is an introduction ( windows mostly )

你怎么这么可爱啊 2024-11-12 19:37:51

我建议在 FloatCanvas 中查看他们是如何做到这一点的。它适用于 wxPython,但即使您使用“普通”wxWidgets,它也应该给您一些想法。

I'd suggest checking out how they do that in FloatCanvas. It's for wxPython but it should give you some ideas even if you're using "plain" wxWidgets.

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