views:

606

answers:

2

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 smth 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.

+1  A: 
Charlie
+1  A: 

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.

MrZebra
Good to know, I've never used that one before. The winforms version of this, if the questioner is using forms, is Graphics.DrawBezier.
Charlie