避免绘画事件重叠,通过单击和拖动形成拱形线?

发布于 2024-07-07 16:41:35 字数 607 浏览 5 评论 0原文

我目前是一名学生,正在尝试设计一个 Visual C++ 应用程序,以允许我直观地插入一个定向图,以便创建一个包含该图矩阵的文本文件。 此时,我已经创建了一个 onClick 事件来创建节点,并使用表单的 Paint 事件来绘制节点。 我还插入了条件以避免节点重叠。

我目前正在致力于创建节点之间的链接。 我遇到的问题是连接两个节点的线穿过另一个节点。 我认为编写一个算法来检测重叠并计算线条需要弯曲多少以避免这种情况在这种情况下过于乏味。

因此,我考虑创建一条用户可以通过单击并将其向左或向右拖动来形成拱形的线,但是我在找到有关如何执行此操作的教程时遇到了问题。 因此,如果有人曾经不得不在项目中引入这种拱形线,或者知道我可以在哪里找到有关此的一些信息,我将非常感激。

提及:

  1. 请不要推荐任何花哨的图形库来执行此操作,因为我对为此程序安装第 3 方内容不感兴趣。 我想要插入代码的函数的名称类似于 form1_onPaint,因此我希望将其严格保留在 C++ 标准库中。
  2. 我知道我说过我有兴趣通过单击和拖动来拱起一条线,但是如果有人可以提出另一个可行的解决方案,例如检测 onPaint 事件中重叠的函数或任何其他可用于解决此问题的函数有很大的帮助。

I am currently a student and trying to design a Visual C++ application to allow me to visually insert an oriented graph in order to create a text file with the graph's matrix. At this point I have created an onClick event to create nodes and have used the form's Paint event to draw the nodes. I have also inserted the conditions to avoid nodes from overlapping.

I am currently working on creating the links between nodes. The problem that I have encountered is that the line that unites two nodes crosses another node. I consider that writing an algorithm to detect overlapping and calculate how much the line needs to arch in order to avoid that is too tedious in this situation.

Therefore I thought about creating a line that can be arched by the user by clicking and dragging it to the left or right, however I have had problems finding any tutorials on how to do this. So if anyone has ever had to introduce this kind of arching line in a project or has any idea where I could find some information about this I would deeply appreciate it.

Mentions:

  1. please do not recommend any fancy graphics libraries for doing this, as I am not interested in installing 3rd party stuff for this program. The function I want to insert the code into is named something like form1_onPaint, so I would like to keep it strictly to the C++ standard libraries.
  2. I know I said I am interested in arching a line through click and drag, however if someone could suggest another viable solution to this, such as a function that detects overlapping in onPaint events or anything else that could be of use to solve this it would be of great help.

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

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

发布评论

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

评论(2

君勿笑 2024-07-14 16:41:35

如果您想绘制曲线,请查看 Windows GDI 函数 PolyBezier()

创建一个由四个点组成的数组:第一个点和最后一个点应该是端点,即连接两个 和 的节点。 两个中间点应该相同,并且应该是曲线的“点”,即您用鼠标拖动的位置。

If you want to draw curves, then look at the Windows GDI function PolyBezier().

Create an array of four points: The first and last points should be the endpoints, i.e. the nodes you are connecting two and from. The two middle points should both be the same, and should be the 'point' of the curve, i.e. the position you are dragging with the mouse.

深者入戏 2024-07-14 16:41:35

一种可能的方法是允许用户抓住并拖动连接线之一的中点,这会将线分成两段(在末端连接)。 这使事情变得简单并避免了处理复杂曲线的需要,并且实现起来非常简单。 您可能会喜欢并允许对行进行额外的细分,因此单行最终可以分为任意数量的子行。

关于执行此操作所需的一些基本想法:

  • 线段和定义端点的各个点的表示。 您可以为一端存储一个点,为每个中间段断点存储一个点,为另一端存储一个最终点。

  • 一种跟踪光标所在位置的方法,以便当它接近线条的中点时,您可以准备抓住并拖动线条以将其分割。 “鼠标移动”事件将在其中发挥作用。 不确定您正在使用哪个工具包,或者我会更具体地说明该事件的名称 - 可能是 onMouseMove。

  • 一种跟踪拖动操作的方法。 这可能涉及“鼠标按下”、“鼠标移动”和“鼠标向上”。 当您拖动时,您将更新相关段断点的坐标。

不幸的是,我认为基本的绘图/窗口系统在尝试检测彼此重叠的油漆时没有多大用处。 您可以自己完成,但我同意您的想法,即编码可能会很棘手且乏味。

最终产品可能如下所示:


(来源:misterfoo.com

One possible approach would be to allow the user to grab and drag the midpoint of one of the connector lines, which would break the line into two segments (joined at the ends). That keeps things simple and avoids the need to deal with complex curves, and it would be pretty simple to implement. You could get fancy and allow additional subdividing of lines, so a single line could eventually be broken into any number of sub-lines.

Some basic ideas on what would be required to do this:

  • A representation of the line segments and the various points defining the ends. You might store one point for one end, one point for each of the intermediate segment break points, and a final point for the other end.

  • A way to track where the cursor is, so that when it's close to the midpoint of a line you can prepare to grab and drag the line to split it. The "mouse move" event will play a role in this. Not sure which toolkit you're using, or I would be more specific about what the event would be named - it might be onMouseMove.

  • A way to track drag operations. This will probably involve "mouse down", "mouse move", and "mouse up". As you drag, you'd be updating the coordinates of the relevant segment break point.

Unfortunately I think the basic drawing/windowing system isn't going to be of much use in trying to detect paints that overlap each other. You can do it yourself, but I agree with your thought that it may be tricky and tedious to code.

The final product might look something like this:


(source: misterfoo.com)

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